Modernize unqualified reference completion tests

This commit is contained in:
Aleksey Kladov 2020-07-07 12:52:09 +02:00
parent 9b2847885d
commit 5b8a5bfb15
5 changed files with 407 additions and 1206 deletions

File diff suppressed because it is too large Load diff

View file

@ -196,20 +196,11 @@ impl<'a> CompletionContext<'a> {
// The range of the identifier that is being completed.
pub(crate) fn source_range(&self) -> TextRange {
// check kind of macro-expanded token, but use range of original token
match self.token.kind() {
// workaroud when completion is triggered by trigger characters.
IDENT => self.original_token.text_range(),
_ => {
// If we haven't characters between keyword and our cursor we take the keyword start range to edit
if self.token.kind().is_keyword()
&& self.offset == self.original_token.text_range().end()
{
mark::hit!(completes_bindings_from_for_with_in_prefix);
TextRange::empty(self.original_token.text_range().start())
} else {
TextRange::empty(self.offset)
}
}
if self.token.kind() == IDENT || self.token.kind().is_keyword() {
mark::hit!(completes_if_prefix_is_keyword);
self.original_token.text_range()
} else {
TextRange::empty(self.offset)
}
}

View file

@ -123,6 +123,7 @@ pub enum CompletionItemKind {
TypeParam,
Macro,
Attribute,
UnresolvedReference,
}
impl CompletionItemKind {
@ -147,6 +148,7 @@ impl CompletionItemKind {
CompletionItemKind::Trait => "tt",
CompletionItemKind::TypeAlias => "ta",
CompletionItemKind::TypeParam => "tp",
CompletionItemKind::UnresolvedReference => "??",
}
}
}

View file

@ -79,11 +79,10 @@ impl Completions {
return self.add_macro(ctx, Some(local_name), *mac);
}
ScopeDef::Unknown => {
return self.add(CompletionItem::new(
CompletionKind::Reference,
ctx.source_range(),
local_name,
));
return self.add(
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name)
.kind(CompletionItemKind::UnresolvedReference),
);
}
};

View file

@ -100,6 +100,7 @@ pub(crate) fn completion_item_kind(
CompletionItemKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method,
CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember,
CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::Reference,
}
}