@@ -1,3 +1,4 @@
1+pub mod config;
12pub mod grammar;
23
34use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
@@ -36,6 +37,15 @@ pub fn config_dir() -> std::path::PathBuf {
3637 path
3738}
3839
40+pub fn local_config_dirs() -> Vec<std::path::PathBuf> {
41+ let directories = find_root_impl(None, &[".helix".to_string()])
42+ .into_iter()
43+ .map(|path| path.join(".helix"))
44+ .collect();
45+ log::debug!("Located configuration folders: {:?}", directories);
46+ directories
47+}
48+
3949pub fn cache_dir() -> std::path::PathBuf {
4050 // TODO: allow env var override
4151 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
@@ -56,25 +66,36 @@ pub fn log_file() -> std::path::PathBuf {
5666 cache_dir().join("helix.log")
5767}
5868
59−/// Default bultin-in languages.toml.
60−pub fn default_lang_config() -> toml::Value {
61− toml::from_slice(include_bytes!("../../languages.toml"))
62− .expect("Could not parse bultin-in languages.toml to valid toml")
63−}
64−
65−/// User configured languages.toml file, merged with the default config.
66−pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
67− let def_lang_conf = default_lang_config();
68− let data = std::fs::read(crate::config_dir().join("languages.toml"));
69− let user_lang_conf = match data {
70− Ok(raw) => {
71− let value = toml::from_slice(&raw)?;
72− merge_toml_values(def_lang_conf, value)
69+pub fn find_root_impl(root: Option<&str>, root_markers: &[String]) -> Vec<std::path::PathBuf> {
70+ let current_dir = std::env::current_dir().expect("unable to determine current directory");
71+ let mut directories = Vec::new();
72+
73+ let root = match root {
74+ Some(root) => {
75+ let root = std::path::Path::new(root);
76+ if root.is_absolute() {
77+ root.to_path_buf()
78+ } else {
79+ current_dir.join(root)
80+ }
7381 }
74− Err(_) => def_lang_conf,
82+ None => current_dir,
7583 };
7684
77− Ok(user_lang_conf)
85+ for ancestor in root.ancestors() {
86+ // don't go higher than repo
87+ if ancestor.join(".git").is_dir() {
88+ // Use workspace if detected from marker
89+ directories.push(ancestor.to_path_buf());
90+ break;
91+ } else if root_markers
92+ .iter()
93+ .any(|marker| ancestor.join(marker).exists())
94+ {
95+ directories.push(ancestor.to_path_buf());
96+ }
97+ }
98+ directories
7899}
79100
80101// right overrides left