diff options
author | Kirawi | 2022-04-18 03:10:51 +0000 |
---|---|---|
committer | GitHub | 2022-04-18 03:10:51 +0000 |
commit | c2a40d9d5229c701fa1a6d0fb80ce4ba86e8dc0c (patch) | |
tree | b27da29863432ca7ee48c582f5aeb538d7a39ea1 /helix-loader/src/config.rs | |
parent | be656c14e32243fc32ed68f9a3240301f2902df7 (diff) |
Add support for local language configuration (#1249)
* add local configuration
* move config loading to Application::new
* simplify find_root_impl
Diffstat (limited to 'helix-loader/src/config.rs')
-rw-r--r-- | helix-loader/src/config.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/helix-loader/src/config.rs b/helix-loader/src/config.rs new file mode 100644 index 00000000..3d71baed --- /dev/null +++ b/helix-loader/src/config.rs @@ -0,0 +1,26 @@ +/// Default bultin-in languages.toml. +pub fn default_lang_config() -> toml::Value { + toml::from_slice(include_bytes!("../../languages.toml")) + .expect("Could not parse bultin-in languages.toml to valid toml") +} + +/// 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() + .into_iter() + .chain([crate::config_dir()].into_iter()) + .map(|path| path.join("languages.toml")) + .filter_map(|file| { + std::fs::read(&file) + .map(|config| toml::from_slice(&config)) + .ok() + }) + .collect::<Result<Vec<_>, _>>()? + .into_iter() + .chain([default_lang_config()].into_iter()) + .fold(toml::Value::Table(toml::value::Table::default()), |a, b| { + crate::merge_toml_values(b, a) + }); + + Ok(config) +} |