aboutsummaryrefslogtreecommitdiff
path: root/helix-loader
diff options
context:
space:
mode:
Diffstat (limited to 'helix-loader')
-rw-r--r--helix-loader/src/config.rs61
-rw-r--r--helix-loader/src/lib.rs15
2 files changed, 42 insertions, 34 deletions
diff --git a/helix-loader/src/config.rs b/helix-loader/src/config.rs
index 8924c8fb..d092d20f 100644
--- a/helix-loader/src/config.rs
+++ b/helix-loader/src/config.rs
@@ -9,35 +9,38 @@ pub fn default_lang_config() -> toml::Value {
/// User configured languages.toml file, merged with the default config.
pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
- let config = [crate::config_dir(), crate::find_workspace().join(".helix")]
- .into_iter()
- .map(|path| path.join("languages.toml"))
- .filter_map(|file| {
- std::fs::read_to_string(file)
- .map(|config| toml::from_str(&config))
- .ok()
- })
- .collect::<Result<Vec<_>, _>>()?
- .into_iter()
- .fold(default_lang_config(), |a, b| {
- // combines for example
- // b:
- // [[language]]
- // name = "toml"
- // language-server = { command = "taplo", args = ["lsp", "stdio"] }
- //
- // a:
- // [[language]]
- // language-server = { command = "/usr/bin/taplo" }
- //
- // into:
- // [[language]]
- // name = "toml"
- // language-server = { command = "/usr/bin/taplo" }
- //
- // thus it overrides the third depth-level of b with values of a if they exist, but otherwise merges their values
- crate::merge_toml_values(a, b, 3)
- });
+ let config = [
+ crate::config_dir(),
+ crate::find_workspace().0.join(".helix"),
+ ]
+ .into_iter()
+ .map(|path| path.join("languages.toml"))
+ .filter_map(|file| {
+ std::fs::read_to_string(file)
+ .map(|config| toml::from_str(&config))
+ .ok()
+ })
+ .collect::<Result<Vec<_>, _>>()?
+ .into_iter()
+ .fold(default_lang_config(), |a, b| {
+ // combines for example
+ // b:
+ // [[language]]
+ // name = "toml"
+ // language-server = { command = "taplo", args = ["lsp", "stdio"] }
+ //
+ // a:
+ // [[language]]
+ // language-server = { command = "/usr/bin/taplo" }
+ //
+ // into:
+ // [[language]]
+ // name = "toml"
+ // language-server = { command = "/usr/bin/taplo" }
+ //
+ // thus it overrides the third depth-level of b with values of a if they exist, but otherwise merges their values
+ crate::merge_toml_values(a, b, 3)
+ });
Ok(config)
}
diff --git a/helix-loader/src/lib.rs b/helix-loader/src/lib.rs
index 51bde716..6c716975 100644
--- a/helix-loader/src/lib.rs
+++ b/helix-loader/src/lib.rs
@@ -129,7 +129,7 @@ pub fn config_file() -> PathBuf {
}
pub fn workspace_config_file() -> PathBuf {
- find_workspace().join(".helix").join("config.toml")
+ find_workspace().0.join(".helix").join("config.toml")
}
pub fn lang_config_file() -> PathBuf {
@@ -283,14 +283,19 @@ 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 {
+/// Used as a ceiling dir for LSP root resolution, the filepicker and potentially as a future filewatching root
+///
+/// This function starts searching the FS upward from the CWD
+/// and returns the first directory that contains either `.git` or `.helix`.
+/// If no workspace was found returns (CWD, true).
+/// Otherwise (workspace, false) is returned
+pub fn find_workspace() -> (PathBuf, bool) {
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();
+ return (ancestor.to_owned(), false);
}
}
- current_dir
+ (current_dir, true)
}