diff options
author | Pascal Kuthe | 2023-01-30 23:31:21 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-03-29 03:57:30 +0000 |
commit | 2d10a429ebf7abe5af184b6227346377dc0523e8 (patch) | |
tree | 114b19f0031fc001d7798a31372675a94623262f /helix-loader/src/lib.rs | |
parent | d59b80514e15d26f280a9b0dbd18afac08578638 (diff) |
add workspace config and manual LSP root management
fixup documentation
Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
fixup typo
Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
Diffstat (limited to 'helix-loader/src/lib.rs')
-rw-r--r-- | helix-loader/src/lib.rs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/helix-loader/src/lib.rs b/helix-loader/src/lib.rs index 04b44b5a..51bde716 100644 --- a/helix-loader/src/lib.rs +++ b/helix-loader/src/lib.rs @@ -42,7 +42,7 @@ fn prioritize_runtime_dirs() -> Vec<PathBuf> { let mut rt_dirs = Vec::new(); if let Ok(dir) = std::env::var("CARGO_MANIFEST_DIR") { // this is the directory of the crate being run by cargo, we need the workspace path so we take the parent - let path = std::path::PathBuf::from(dir).parent().unwrap().join(RT_DIR); + let path = PathBuf::from(dir).parent().unwrap().join(RT_DIR); log::debug!("runtime dir: {}", path.to_string_lossy()); rt_dirs.push(path); } @@ -113,15 +113,6 @@ pub fn config_dir() -> PathBuf { path } -pub fn local_config_dirs() -> Vec<PathBuf> { - let directories = find_local_config_dirs() - .into_iter() - .map(|path| path.join(".helix")) - .collect(); - log::debug!("Located configuration folders: {:?}", directories); - directories -} - pub fn cache_dir() -> PathBuf { // TODO: allow env var override let strategy = choose_base_strategy().expect("Unable to find the config directory!"); @@ -137,6 +128,10 @@ pub fn config_file() -> PathBuf { .unwrap_or_else(|| config_dir().join("config.toml")) } +pub fn workspace_config_file() -> PathBuf { + find_workspace().join(".helix").join("config.toml") +} + pub fn lang_config_file() -> PathBuf { config_dir().join("languages.toml") } @@ -145,22 +140,6 @@ pub fn log_file() -> PathBuf { cache_dir().join("helix.log") } -pub fn find_local_config_dirs() -> Vec<PathBuf> { - let current_dir = std::env::current_dir().expect("unable to determine current directory"); - let mut directories = Vec::new(); - - for ancestor in current_dir.ancestors() { - if ancestor.join(".git").exists() { - directories.push(ancestor.to_path_buf()); - // Don't go higher than repo if we're in one - break; - } else if ancestor.join(".helix").is_dir() { - directories.push(ancestor.to_path_buf()); - } - } - directories -} - /// Merge two TOML documents, merging values from `right` onto `left` /// /// When an array exists in both `left` and `right`, `right`'s array is @@ -302,3 +281,16 @@ mod merge_toml_tests { ) } } + +/// Finds the current workspace folder. +/// Used as a ceiling dir for root resolve, for the filepicker and other related +pub fn find_workspace() -> PathBuf { + let current_dir = std::env::current_dir().expect("unable to determine current directory"); + for ancestor in current_dir.ancestors() { + if ancestor.join(".git").exists() || ancestor.join(".helix").exists() { + return ancestor.to_owned(); + } + } + + current_dir +} |