Debian Codegraph @

helix-loader/src/config.rs

raw symbols SCIP
1 use std::str::from_utf8;
2
3 use crate::workspace_trust::{TrustQuery, WorkspaceTrust};
4
5 /// Default built-in languages.toml.
6 pub fn default_lang_config() -> toml::Value {
7 let default_config = include_bytes!("../../languages.toml");
8 toml::from_str(from_utf8(default_config).unwrap())
9 .expect("Could not parse built-in languages.toml to valid toml")
10 }
11
12 /// User configured languages.toml file, merged with the default config.
13 ///
14 /// Workspace-local `.helix/languages.toml` is merged in only when the current
15 /// workspace is trusted for [`TrustQuery::LocalConfig`].
16 pub fn user_lang_config(trust: &WorkspaceTrust) -> Result<toml::Value, toml::de::Error> {
17 let global_config = crate::lang_config_file();
18 let workspace_config = crate::workspace_lang_config_file();
19
20 let files = if trust.query_current(TrustQuery::LocalConfig).is_trusted() {
21 vec![global_config, workspace_config]
22 } else {
23 vec![global_config]
24 };
25
26 let config = files
27 .iter()
28 .filter_map(|file| {
29 std::fs::read_to_string(file)
30 .map(|config| toml::from_str(&config))
31 .ok()
32 })
33 .collect::<Result<Vec<_>, _>>()?
34 .into_iter()
35 .fold(default_lang_config(), |a, b| {
36 crate::merge_toml_values(a, b, 3)
37 });
38
39 Ok(config)
40 }