mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Modernize unqualified reference completion tests
This commit is contained in:
parent
9b2847885d
commit
5b8a5bfb15
5 changed files with 407 additions and 1206 deletions
File diff suppressed because it is too large
Load diff
|
@ -196,20 +196,11 @@ impl<'a> CompletionContext<'a> {
|
||||||
// The range of the identifier that is being completed.
|
// The range of the identifier that is being completed.
|
||||||
pub(crate) fn source_range(&self) -> TextRange {
|
pub(crate) fn source_range(&self) -> TextRange {
|
||||||
// check kind of macro-expanded token, but use range of original token
|
// check kind of macro-expanded token, but use range of original token
|
||||||
match self.token.kind() {
|
if self.token.kind() == IDENT || self.token.kind().is_keyword() {
|
||||||
// workaroud when completion is triggered by trigger characters.
|
mark::hit!(completes_if_prefix_is_keyword);
|
||||||
IDENT => self.original_token.text_range(),
|
self.original_token.text_range()
|
||||||
_ => {
|
} else {
|
||||||
// If we haven't characters between keyword and our cursor we take the keyword start range to edit
|
TextRange::empty(self.offset)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,7 @@ pub enum CompletionItemKind {
|
||||||
TypeParam,
|
TypeParam,
|
||||||
Macro,
|
Macro,
|
||||||
Attribute,
|
Attribute,
|
||||||
|
UnresolvedReference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompletionItemKind {
|
impl CompletionItemKind {
|
||||||
|
@ -147,6 +148,7 @@ impl CompletionItemKind {
|
||||||
CompletionItemKind::Trait => "tt",
|
CompletionItemKind::Trait => "tt",
|
||||||
CompletionItemKind::TypeAlias => "ta",
|
CompletionItemKind::TypeAlias => "ta",
|
||||||
CompletionItemKind::TypeParam => "tp",
|
CompletionItemKind::TypeParam => "tp",
|
||||||
|
CompletionItemKind::UnresolvedReference => "??",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,11 +79,10 @@ impl Completions {
|
||||||
return self.add_macro(ctx, Some(local_name), *mac);
|
return self.add_macro(ctx, Some(local_name), *mac);
|
||||||
}
|
}
|
||||||
ScopeDef::Unknown => {
|
ScopeDef::Unknown => {
|
||||||
return self.add(CompletionItem::new(
|
return self.add(
|
||||||
CompletionKind::Reference,
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name)
|
||||||
ctx.source_range(),
|
.kind(CompletionItemKind::UnresolvedReference),
|
||||||
local_name,
|
);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,7 @@ pub(crate) fn completion_item_kind(
|
||||||
CompletionItemKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
|
CompletionItemKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||||
CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method,
|
CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method,
|
||||||
CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember,
|
CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember,
|
||||||
|
CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::Reference,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue