aboutsummaryrefslogtreecommitdiff
path: root/helix-loader
diff options
context:
space:
mode:
authorPascal Kuthe2023-01-30 23:31:21 +0000
committerBlaž Hrastnik2023-03-29 03:57:30 +0000
commit2d10a429ebf7abe5af184b6227346377dc0523e8 (patch)
tree114b19f0031fc001d7798a31372675a94623262f /helix-loader
parentd59b80514e15d26f280a9b0dbd18afac08578638 (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')
-rw-r--r--helix-loader/src/config.rs8
-rw-r--r--helix-loader/src/lib.rs44
2 files changed, 21 insertions, 31 deletions
diff --git a/helix-loader/src/config.rs b/helix-loader/src/config.rs
index 0f329d21..8924c8fb 100644
--- a/helix-loader/src/config.rs
+++ b/helix-loader/src/config.rs
@@ -9,9 +9,8 @@ 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::local_config_dirs()
+ let config = [crate::config_dir(), crate::find_workspace().join(".helix")]
.into_iter()
- .chain([crate::config_dir()].into_iter())
.map(|path| path.join("languages.toml"))
.filter_map(|file| {
std::fs::read_to_string(file)
@@ -20,8 +19,7 @@ pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
})
.collect::<Result<Vec<_>, _>>()?
.into_iter()
- .chain([default_lang_config()].into_iter())
- .fold(toml::Value::Table(toml::value::Table::default()), |a, b| {
+ .fold(default_lang_config(), |a, b| {
// combines for example
// b:
// [[language]]
@@ -38,7 +36,7 @@ pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
// 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(b, a, 3)
+ crate::merge_toml_values(a, b, 3)
});
Ok(config)
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
+}