@@ -12,6 +12,7 @@ use self::fnv::FnvHashMap;
12
12
use self :: toml:: Value ;
13
13
use crate :: data:: * ;
14
14
use fnv;
15
+ use std:: env;
15
16
use std:: fs:: File ;
16
17
use std:: io;
17
18
use std:: io:: prelude:: * ;
@@ -191,6 +192,32 @@ impl Config {
191
192
}
192
193
}
193
194
195
+ /// Load configuration file from installation folder
196
+ fn load_installed_config ( & mut self , messages : & mut dyn MessageHandler ) {
197
+ let config_relative_path = if cfg ! ( feature = "packaged" ) {
198
+ // relative to packaged bin folder
199
+ "../vhdl_libraries"
200
+ } else {
201
+ // relative to target/debug or target/release
202
+ "../../vhdl_libraries"
203
+ } ;
204
+
205
+ let exe_path = env:: current_exe ( ) . expect ( "Executable path needed" ) ;
206
+ let exe_folder = exe_path. parent ( ) . expect ( "Executable folder must exist" ) ;
207
+
208
+ let mut file_name = exe_folder. join ( config_relative_path) ;
209
+ file_name. push ( "vhdl_ls.toml" ) ;
210
+
211
+ if !file_name. exists ( ) {
212
+ panic ! (
213
+ "Couldn't find installed libraries at {}." ,
214
+ file_name. to_string_lossy( )
215
+ ) ;
216
+ }
217
+
218
+ self . load_config ( & file_name, "Installation" , messages) ;
219
+ }
220
+
194
221
/// Load configuration file from home folder
195
222
fn load_home_config ( & mut self , messages : & mut dyn MessageHandler ) {
196
223
if let Some ( home_dir) = dirs:: home_dir ( ) {
@@ -234,6 +261,7 @@ impl Config {
234
261
235
262
/// Load all external configuration
236
263
pub fn load_external_config ( & mut self , messages : & mut dyn MessageHandler ) {
264
+ self . load_installed_config ( messages) ;
237
265
self . load_home_config ( messages) ;
238
266
self . load_env_config ( "VHDL_LS_CONFIG" , messages) ;
239
267
}
0 commit comments