feat: always prefer postfix snippets if there's exact textual match

Note that, while we don't currently have a fuzzy-matching score, it
makes sense to special-case postfix templates -- it's very annoying when
`.not()` gets sorted before `.not`. We might want to move this infra to
fuzzy matching, once we have that!
This commit is contained in:
Aleksey Kladov 2021-07-04 16:50:02 +03:00
parent 030217d573
commit fbb9d69758
4 changed files with 105 additions and 23 deletions

View file

@ -15,7 +15,7 @@ use crate::{
context::CompletionContext,
item::{Builder, CompletionKind},
patterns::ImmediateLocation,
CompletionItem, CompletionItemKind, Completions,
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
};
pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
@ -299,6 +299,12 @@ fn postfix_snippet(
};
let mut item = CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label);
item.detail(detail).kind(CompletionItemKind::Snippet).snippet_edit(cap, edit);
if ctx.original_token.text() == label {
let mut relevance = CompletionRelevance::default();
relevance.exact_postfix_snippet_match = true;
item.set_relevance(relevance);
}
item
}