Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-loader/src/config.rs')
-rw-r--r--helix-loader/src/config.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/helix-loader/src/config.rs b/helix-loader/src/config.rs
index 1f414de6..a8c84361 100644
--- a/helix-loader/src/config.rs
+++ b/helix-loader/src/config.rs
@@ -1,30 +1,26 @@
-use std::str::from_utf8;
-
/// Default built-in languages.toml.
pub fn default_lang_config() -> toml::Value {
- let default_config = include_bytes!("../../languages.toml");
- toml::from_str(from_utf8(default_config).unwrap())
+ toml::from_slice(include_bytes!("../../languages.toml"))
.expect("Could not parse built-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::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| {
- crate::merge_toml_values(a, b, 3)
- });
+ 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, true)
+ });
Ok(config)
}