diff options
author | A-Walrus | 2022-08-06 17:16:18 +0000 |
---|---|---|
committer | GitHub | 2022-08-06 17:16:18 +0000 |
commit | 6b84344e205a07261faae4f85f28175401fa7414 (patch) | |
tree | ea951642615160a8a572dd2c2509b824bfeb2cfd /helix-term | |
parent | 973c51c3e970aa975f2bd1869d50ce2ae6c6de34 (diff) |
Add completion for nested settings (#3183)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/ui/mod.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 257608f0..113bc486 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -283,14 +283,28 @@ pub mod completers { names } + /// Recursive function to get all keys from this value and add them to vec + fn get_keys(value: &serde_json::Value, vec: &mut Vec<String>, scope: Option<&str>) { + if let Some(map) = value.as_object() { + for (key, value) in map.iter() { + let key = match scope { + Some(scope) => format!("{}.{}", scope, key), + None => key.clone(), + }; + get_keys(value, vec, Some(&key)); + if !value.is_object() { + vec.push(key); + } + } + } + } + pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> { static KEYS: Lazy<Vec<String>> = Lazy::new(|| { - serde_json::json!(Config::default()) - .as_object() - .unwrap() - .keys() - .cloned() - .collect() + let mut keys = Vec::new(); + let json = serde_json::json!(Config::default()); + get_keys(&json, &mut keys, None); + keys }); let matcher = Matcher::default(); |