Skip to content

Commit b40b2c7

Browse files
authored
Merge pull request #51 from Xcodo/installed-libs
Add loading of packaged libraries by feature flag
2 parents d68066d + b4893b0 commit b40b2c7

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

.github/workflows/build-test-all.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ jobs:
4242
uses: actions-rs/cargo@v1
4343
with:
4444
command: build
45-
args: --package ${{ matrix.crate }} --release --target ${{ matrix.target }}
45+
args: --manifest-path ${{ matrix.crate }}/Cargo.toml --release --target ${{ matrix.target }} --features "packaged"
4646

4747
- name: Test ${{ matrix.crate }}
4848
uses: actions-rs/cargo@v1
4949
with:
5050
command: test
51-
args: --package ${{ matrix.crate }} --release --target ${{ matrix.target }}
51+
args: --manifest-path ${{ matrix.crate }}/Cargo.toml --release --target ${{ matrix.target }} --features "packaged"
5252

5353
- name: rustfmt
5454
if: matrix.os == 'ubuntu-latest' && matrix.rust == 'stable'

vhdl_ls/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ env_logger = "0.6.0"
2525

2626
[dev-dependencies]
2727
tempfile = "^3"
28-
pretty_assertions = "^0"
28+
pretty_assertions = "^0"
29+
30+
[features]
31+
default = []
32+
packaged = ["vhdl_parser/packaged"]

vhdl_parser/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ parking_lot = "^0"
2626
[dev-dependencies]
2727
tempfile = "^3"
2828
pretty_assertions = "^0"
29-
assert_matches = "^1"
29+
assert_matches = "^1"
30+
31+
[features]
32+
default = []
33+
packaged = []

vhdl_parser/src/config.rs

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use self::fnv::FnvHashMap;
1212
use self::toml::Value;
1313
use crate::data::*;
1414
use fnv;
15+
use std::env;
1516
use std::fs::File;
1617
use std::io;
1718
use std::io::prelude::*;
@@ -191,6 +192,32 @@ impl Config {
191192
}
192193
}
193194

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+
194221
/// Load configuration file from home folder
195222
fn load_home_config(&mut self, messages: &mut dyn MessageHandler) {
196223
if let Some(home_dir) = dirs::home_dir() {
@@ -234,6 +261,7 @@ impl Config {
234261

235262
/// Load all external configuration
236263
pub fn load_external_config(&mut self, messages: &mut dyn MessageHandler) {
264+
self.load_installed_config(messages);
237265
self.load_home_config(messages);
238266
self.load_env_config("VHDL_LS_CONFIG", messages);
239267
}

0 commit comments

Comments
 (0)