on master help sign in
Add completion for nested settings (#3183)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commit6b84344e205a07261faae4f85f28175401fa7414 authorA-Walrus <58790821+A-Walrus@users.noreply.github.com> dateSat 6 Aug 2022, 20:16 (4 years ago) parent973c51c
1 file changed+20−6
helix-term/src/ui/mod.rs+20−6
helix-term/src/ui/mod.rs+20−6
@@ -283,14 +283,28 @@ pub mod completers {
283283 names
284284 }
285285
286+ /// Recursive function to get all keys from this value and add them to vec
287+ fn get_keys(value: &serde_json::Value, vec: &mut Vec<String>, scope: Option<&str>) {
288+ if let Some(map) = value.as_object() {
289+ for (key, value) in map.iter() {
290+ let key = match scope {
291+ Some(scope) => format!("{}.{}", scope, key),
292+ None => key.clone(),
293+ };
294+ get_keys(value, vec, Some(&key));
295+ if !value.is_object() {
296+ vec.push(key);
297+ }
298+ }
299+ }
300+ }
301+
286302 pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
287303 static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
288− serde_json::json!(Config::default())
289− .as_object()
290− .unwrap()
291− .keys()
292− .cloned()
293− .collect()
304+ let mut keys = Vec::new();
305+ let json = serde_json::json!(Config::default());
306+ get_keys(&json, &mut keys, None);
307+ keys
294308 });
295309
296310 let matcher = Matcher::default();