Add completion for nested settings (#3183)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
pull/3348/head
A-Walrus 2 years ago committed by GitHub
parent 973c51c3e9
commit 6b84344e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -283,14 +283,28 @@ pub mod completers {
names 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> { pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
static KEYS: Lazy<Vec<String>> = Lazy::new(|| { static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
serde_json::json!(Config::default()) let mut keys = Vec::new();
.as_object() let json = serde_json::json!(Config::default());
.unwrap() get_keys(&json, &mut keys, None);
.keys() keys
.cloned()
.collect()
}); });
let matcher = Matcher::default(); let matcher = Matcher::default();

Loading…
Cancel
Save