From 83e49200d82dccda54bbf376bba5a9c75da14cab Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 19 Jan 2021 20:21:56 +0100 Subject: Add LifetimeParam and ConstParam to CompletionItemKind --- .../completion/src/completions/unqualified_path.rs | 2 +- crates/completion/src/item.rs | 24 +++++++++++--------- crates/completion/src/render.rs | 6 ++++- crates/rust-analyzer/src/to_proto.rs | 26 ++++++++++++---------- 4 files changed, 34 insertions(+), 24 deletions(-) (limited to 'crates') diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 809e1645a..860c774c1 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -241,7 +241,7 @@ fn main() { check( r#"fn quux() { $0 }"#, expect![[r#" - tp C + cp C fn quux() fn quux() "#]], ); diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 4147853e7..ecf581be2 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs @@ -117,24 +117,26 @@ pub enum CompletionScore { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CompletionItemKind { - Snippet, - Keyword, - Module, - Function, + Attribute, + Binding, BuiltinType, - Struct, + Const, + ConstParam, Enum, EnumVariant, - Binding, Field, + Function, + Keyword, + LifetimeParam, + Macro, + Method, + Module, + Snippet, Static, - Const, + Struct, Trait, TypeAlias, - Method, TypeParam, - Macro, - Attribute, UnresolvedReference, } @@ -146,11 +148,13 @@ impl CompletionItemKind { CompletionItemKind::Binding => "bn", CompletionItemKind::BuiltinType => "bt", CompletionItemKind::Const => "ct", + CompletionItemKind::ConstParam => "cp", CompletionItemKind::Enum => "en", CompletionItemKind::EnumVariant => "ev", CompletionItemKind::Field => "fd", CompletionItemKind::Function => "fn", CompletionItemKind::Keyword => "kw", + CompletionItemKind::LifetimeParam => "lt", CompletionItemKind::Macro => "ma", CompletionItemKind::Method => "me", CompletionItemKind::Module => "md", diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 4f622d28a..68556c8ce 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -208,7 +208,11 @@ impl<'a> Render<'a> { ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::Trait, ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias, ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType, - ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam, + ScopeDef::GenericParam(param) => match param { + hir::GenericParam::TypeParam(_) => CompletionItemKind::TypeParam, + hir::GenericParam::LifetimeParam(_) => CompletionItemKind::LifetimeParam, + hir::GenericParam::ConstParam(_) => CompletionItemKind::ConstParam, + }, ScopeDef::Local(..) => CompletionItemKind::Binding, // (does this need its own kind?) ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam, diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 0e3550002..9fd32a8c7 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -87,24 +87,26 @@ pub(crate) fn completion_item_kind( completion_item_kind: CompletionItemKind, ) -> lsp_types::CompletionItemKind { match completion_item_kind { - CompletionItemKind::Keyword => lsp_types::CompletionItemKind::Keyword, - CompletionItemKind::Snippet => lsp_types::CompletionItemKind::Snippet, - CompletionItemKind::Module => lsp_types::CompletionItemKind::Module, - CompletionItemKind::Function => lsp_types::CompletionItemKind::Function, - CompletionItemKind::Struct => lsp_types::CompletionItemKind::Struct, + CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember, + CompletionItemKind::Binding => lsp_types::CompletionItemKind::Variable, + CompletionItemKind::BuiltinType => lsp_types::CompletionItemKind::Struct, + CompletionItemKind::Const => lsp_types::CompletionItemKind::Constant, + CompletionItemKind::ConstParam => lsp_types::CompletionItemKind::TypeParameter, CompletionItemKind::Enum => lsp_types::CompletionItemKind::Enum, CompletionItemKind::EnumVariant => lsp_types::CompletionItemKind::EnumMember, - CompletionItemKind::BuiltinType => lsp_types::CompletionItemKind::Struct, - CompletionItemKind::Binding => lsp_types::CompletionItemKind::Variable, CompletionItemKind::Field => lsp_types::CompletionItemKind::Field, + CompletionItemKind::Function => lsp_types::CompletionItemKind::Function, + CompletionItemKind::Keyword => lsp_types::CompletionItemKind::Keyword, + CompletionItemKind::LifetimeParam => lsp_types::CompletionItemKind::TypeParameter, + CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method, + CompletionItemKind::Method => lsp_types::CompletionItemKind::Method, + CompletionItemKind::Module => lsp_types::CompletionItemKind::Module, + CompletionItemKind::Snippet => lsp_types::CompletionItemKind::Snippet, + CompletionItemKind::Static => lsp_types::CompletionItemKind::Value, + CompletionItemKind::Struct => lsp_types::CompletionItemKind::Struct, CompletionItemKind::Trait => lsp_types::CompletionItemKind::Interface, CompletionItemKind::TypeAlias => lsp_types::CompletionItemKind::Struct, - CompletionItemKind::Const => lsp_types::CompletionItemKind::Constant, - CompletionItemKind::Static => lsp_types::CompletionItemKind::Value, - CompletionItemKind::Method => lsp_types::CompletionItemKind::Method, CompletionItemKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter, - CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method, - CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember, CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::Reference, } } -- cgit v1.2.3