Skip to content

Commit

Permalink
Don't autocomplete opening paren after function call that follows //
Browse files Browse the repository at this point in the history
  • Loading branch information
eminence authored and sharkdp committed Nov 23, 2023
1 parent 24e6346 commit b088ad0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 8 additions & 1 deletion numbat-cli/src/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions numbat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = String> + '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<Item = String> + 'a {
const COMMON_METRIC_PREFIXES: &[&str] = &[
"pico", "nano", "micro", "milli", "centi", "kilo", "mega", "giga", "tera",
];
Expand All @@ -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() {
Expand Down

0 comments on commit b088ad0

Please sign in to comment.