Skip to content

Commit

Permalink
Add completion for nested settings (#3183)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
  • Loading branch information
A-Walrus and the-mikedavis authored Aug 6, 2022
1 parent 973c51c commit 6b84344
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6b84344

Please sign in to comment.