Skip to content

Commit

Permalink
Add loading of packaged libraries by feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Xcodo committed Dec 29, 2019
1 parent d68066d commit fc56612
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 5 additions & 1 deletion vhdl_ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ env_logger = "0.6.0"

[dev-dependencies]
tempfile = "^3"
pretty_assertions = "^0"
pretty_assertions = "^0"

[features]
default = []
packaged = ["vhdl_parser/packaged"]
6 changes: 5 additions & 1 deletion vhdl_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ parking_lot = "^0"
[dev-dependencies]
tempfile = "^3"
pretty_assertions = "^0"
assert_matches = "^1"
assert_matches = "^1"

[features]
default = []
packaged = []
28 changes: 28 additions & 0 deletions vhdl_parser/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use self::fnv::FnvHashMap;
use self::toml::Value;
use crate::data::*;
use fnv;
use std::env;
use std::fs::File;
use std::io;
use std::io::prelude::*;
Expand Down Expand Up @@ -191,6 +192,32 @@ impl Config {
}
}

/// Load configuration file from installation folder
fn load_installed_config(&mut self, messages: &mut dyn MessageHandler) {
let config_relative_path = if cfg!(feature = "packaged") {
// relative to packaged bin folder
"../vhdl_libraries"
} else {
// relative to target/debug or target/release
"../../vhdl_libraries"
};

let exe_path = env::current_exe().expect("Executable path needed");
let exe_folder = exe_path.parent().expect("Executable folder must exist");

let mut file_name = exe_folder.join(config_relative_path);
file_name.push("vhdl_ls.toml");

if !file_name.exists() {
panic!(
"Couldn't find installed libraries at {}.",
file_name.to_string_lossy()
);
}

self.load_config(&file_name, "Installation", messages);
}

/// Load configuration file from home folder
fn load_home_config(&mut self, messages: &mut dyn MessageHandler) {
if let Some(home_dir) = dirs::home_dir() {
Expand Down Expand Up @@ -234,6 +261,7 @@ impl Config {

/// Load all external configuration
pub fn load_external_config(&mut self, messages: &mut dyn MessageHandler) {
self.load_installed_config(messages);
self.load_home_config(messages);
self.load_env_config("VHDL_LS_CONFIG", messages);
}
Expand Down

0 comments on commit fc56612

Please sign in to comment.