on master help sign in
Add completion for nested settings (#3183)
6b84344A-Walrus
helix-term/src/ui/mod.rs+20−6
@@ -283,14 +283,28 @@ pub mod completers {
283 names
283 names
284 }
284 }
285
285
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+
286 pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
302 pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
287 static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
303 static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
304+ let mut keys = Vec::new();
288− serde_json::json!(Config::default())
305+ let json = serde_json::json!(Config::default());
289− .as_object()
306+ get_keys(&json, &mut keys, None);
290− .unwrap()
307+ keys
291− .keys()
292− .cloned()
293− .collect()
294 });
308 });
295
309
296 let matcher = Matcher::default();
310 let matcher = Matcher::default();