@@ -1,3 +1,4 @@
1pub mod grammar;
2pub mod grammar;
3use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
4use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
@@ -36,6 +37,15 @@ pub fn config_dir() -> std::path::PathBuf {
40+pub fn local_config_dirs() -> Vec<std::path::PathBuf> {
41+ let directories = find_root_impl(None, &[".helix".to_string()])
43+ .map(|path| path.join(".helix"))
45+ log::debug!("Located configuration folders: {:?}", directories);
39pub fn cache_dir() -> std::path::PathBuf {
49pub fn cache_dir() -> std::path::PathBuf {
40 // TODO: allow env var override
50 // TODO: allow env var override
41 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
51 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
@@ -56,25 +66,36 @@ pub fn log_file() -> std::path::PathBuf {
56 cache_dir().join("helix.log")
66 cache_dir().join("helix.log")
59−/// Default bultin-in languages.toml.
69+pub fn find_root_impl(root: Option<&str>, root_markers: &[String]) -> Vec<std::path::PathBuf> {
60−pub fn default_lang_config() -> toml::Value {
70+ let current_dir = std::env::current_dir().expect("unable to determine current directory");
61− toml::from_slice(include_bytes!("../../languages.toml"))
71+ let mut directories = Vec::new();
62− .expect("Could not parse bultin-in languages.toml to valid toml")
72+
63−}
73+ let root = match root {
65−/// User configured languages.toml file, merged with the default config.
75+ let root = std::path::Path::new(root);
66−pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
76+ if root.is_absolute() {
67− let def_lang_conf = default_lang_config();
77+ root.to_path_buf()
68− let data = std::fs::read(crate::config_dir().join("languages.toml"));
78+ } else {
69− let user_lang_conf = match data {
79+ current_dir.join(root)
71− let value = toml::from_slice(&raw)?;
72− merge_toml_values(def_lang_conf, value)
74− Err(_) => def_lang_conf,
82+ None => current_dir,
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());
91+ } else if root_markers
93+ .any(|marker| ancestor.join(marker).exists())
95+ directories.push(ancestor.to_path_buf());
80// right overrides left
101// right overrides left