diff --git a/numbat-cli/src/completer.rs b/numbat-cli/src/completer.rs index cf37199e..572bc55b 100644 --- a/numbat-cli/src/completer.rs +++ b/numbat-cli/src/completer.rs @@ -67,7 +67,14 @@ impl Completer for NumbatCompleter { } }); - let candidates = self.context.lock().unwrap().get_completions_for(word_part); + // don't add an opening paren if we're completing after a reverse function call + let add_paren = !line[..pos].find("//").is_some(); + + let candidates = self + .context + .lock() + .unwrap() + .get_completions_for(word_part, add_paren); Ok(( pos_word, diff --git a/numbat/src/lib.rs b/numbat/src/lib.rs index 35dc3aad..19e8fb42 100644 --- a/numbat/src/lib.rs +++ b/numbat/src/lib.rs @@ -190,7 +190,14 @@ impl Context { self.print_sorted(units, FormatType::Unit) } - pub fn get_completions_for<'a>(&self, word_part: &'a str) -> impl Iterator + 'a { + /// Gets completions for the given word_part + /// + /// If `add_paren` is true, then an opening paren will be added to the end of function names + pub fn get_completions_for<'a>( + &self, + word_part: &'a str, + add_paren: bool, + ) -> impl Iterator + 'a { const COMMON_METRIC_PREFIXES: &[&str] = &[ "pico", "nano", "micro", "milli", "centi", "kilo", "mega", "giga", "tera", ]; @@ -211,7 +218,11 @@ impl Context { } for function in self.function_names() { - words.push(format!("{}(", function)); + if add_paren { + words.push(format!("{}(", function)); + } else { + words.push(format!("{}", function)); + } } for dimension in self.dimension_names() {