diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index b0fd18a76b79..53bf85c0cbce 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2438,7 +2438,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ aliases: &["toggle"], doc: "Toggle a boolean config option at runtime.\nFor example to toggle smart case search, use `:toggle search.smart-case`.", fun: toggle_option, - completer: Some(completers::setting), + completer: Some(completers::boolean_setting), }, TypableCommand { name: "get-option", diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index d7717f8cf59c..5c0b89610510 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -312,15 +312,20 @@ pub mod completers { } /// Recursive function to get all keys from this value and add them to vec - fn get_keys(value: &serde_json::Value, vec: &mut Vec, scope: Option<&str>) { + fn get_keys( + value: &serde_json::Value, + vec: &mut Vec, + scope: Option<&str>, + only_booleans: bool, + ) { 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() { + get_keys(value, vec, Some(&key), only_booleans); + if !value.is_object() && (!only_booleans || value.is_boolean()) { vec.push(key); } } @@ -328,17 +333,40 @@ pub mod completers { } pub fn setting(_editor: &Editor, input: &str) -> Vec { - static KEYS: Lazy> = Lazy::new(|| { + setting_with_filter(_editor, input, false) + } + + pub fn boolean_setting(_editor: &Editor, input: &str) -> Vec { + setting_with_filter(_editor, input, true) + } + + pub fn setting_with_filter( + _editor: &Editor, + input: &str, + only_booleans: bool, + ) -> Vec { + static BOOL_KEYS: Lazy> = Lazy::new(|| { + let mut keys = Vec::new(); + let json = serde_json::json!(Config::default()); + get_keys(&json, &mut keys, None, true); + keys + }); + static ALL_KEYS: Lazy> = Lazy::new(|| { let mut keys = Vec::new(); let json = serde_json::json!(Config::default()); - get_keys(&json, &mut keys, None); + get_keys(&json, &mut keys, None, false); keys }); let matcher = Matcher::default(); - let mut matches: Vec<_> = KEYS - .iter() + let source = if only_booleans { + BOOL_KEYS.iter() + } else { + ALL_KEYS.iter() + }; + + let mut matches: Vec<_> = source .filter_map(|name| matcher.fuzzy_match(name, input).map(|score| (name, score))) .collect();