diff options
Diffstat (limited to 'crates/completion/src/item.rs')
-rw-r--r-- | crates/completion/src/item.rs | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 4147853e7..d2e6a6aeb 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs | |||
@@ -3,11 +3,14 @@ | |||
3 | use std::fmt; | 3 | use std::fmt; |
4 | 4 | ||
5 | use hir::{Documentation, ModPath, Mutability}; | 5 | use hir::{Documentation, ModPath, Mutability}; |
6 | use ide_db::helpers::{ | 6 | use ide_db::{ |
7 | insert_use::{self, ImportScope, MergeBehavior}, | 7 | helpers::{ |
8 | mod_path_to_ast, SnippetCap, | 8 | insert_use::{self, ImportScope, MergeBehavior}, |
9 | mod_path_to_ast, SnippetCap, | ||
10 | }, | ||
11 | SymbolKind, | ||
9 | }; | 12 | }; |
10 | use stdx::assert_never; | 13 | use stdx::{assert_never, impl_from}; |
11 | use syntax::{algo, TextRange}; | 14 | use syntax::{algo, TextRange}; |
12 | use text_edit::TextEdit; | 15 | use text_edit::TextEdit; |
13 | 16 | ||
@@ -117,49 +120,50 @@ pub enum CompletionScore { | |||
117 | 120 | ||
118 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 121 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
119 | pub enum CompletionItemKind { | 122 | pub enum CompletionItemKind { |
120 | Snippet, | 123 | SymbolKind(SymbolKind), |
121 | Keyword, | 124 | Attribute, |
122 | Module, | ||
123 | Function, | ||
124 | BuiltinType, | ||
125 | Struct, | ||
126 | Enum, | ||
127 | EnumVariant, | ||
128 | Binding, | 125 | Binding, |
129 | Field, | 126 | BuiltinType, |
130 | Static, | 127 | Keyword, |
131 | Const, | ||
132 | Trait, | ||
133 | TypeAlias, | ||
134 | Method, | 128 | Method, |
135 | TypeParam, | 129 | Snippet, |
136 | Macro, | ||
137 | Attribute, | ||
138 | UnresolvedReference, | 130 | UnresolvedReference, |
139 | } | 131 | } |
140 | 132 | ||
133 | impl_from!(SymbolKind for CompletionItemKind); | ||
134 | |||
141 | impl CompletionItemKind { | 135 | impl CompletionItemKind { |
142 | #[cfg(test)] | 136 | #[cfg(test)] |
143 | pub(crate) fn tag(&self) -> &'static str { | 137 | pub(crate) fn tag(&self) -> &'static str { |
144 | match self { | 138 | match self { |
139 | CompletionItemKind::SymbolKind(kind) => match kind { | ||
140 | SymbolKind::Const => "ct", | ||
141 | SymbolKind::ConstParam => "cp", | ||
142 | SymbolKind::Enum => "en", | ||
143 | SymbolKind::Field => "fd", | ||
144 | SymbolKind::Function => "fn", | ||
145 | SymbolKind::Impl => "im", | ||
146 | SymbolKind::Label => "lb", | ||
147 | SymbolKind::LifetimeParam => "lt", | ||
148 | SymbolKind::Local => "lc", | ||
149 | SymbolKind::Macro => "ma", | ||
150 | SymbolKind::Module => "md", | ||
151 | SymbolKind::SelfParam => "sp", | ||
152 | SymbolKind::Static => "sc", | ||
153 | SymbolKind::Struct => "st", | ||
154 | SymbolKind::Trait => "tt", | ||
155 | SymbolKind::TypeAlias => "ta", | ||
156 | SymbolKind::TypeParam => "tp", | ||
157 | SymbolKind::Union => "un", | ||
158 | SymbolKind::ValueParam => "vp", | ||
159 | SymbolKind::Variant => "ev", | ||
160 | }, | ||
145 | CompletionItemKind::Attribute => "at", | 161 | CompletionItemKind::Attribute => "at", |
146 | CompletionItemKind::Binding => "bn", | 162 | CompletionItemKind::Binding => "bn", |
147 | CompletionItemKind::BuiltinType => "bt", | 163 | CompletionItemKind::BuiltinType => "bt", |
148 | CompletionItemKind::Const => "ct", | ||
149 | CompletionItemKind::Enum => "en", | ||
150 | CompletionItemKind::EnumVariant => "ev", | ||
151 | CompletionItemKind::Field => "fd", | ||
152 | CompletionItemKind::Function => "fn", | ||
153 | CompletionItemKind::Keyword => "kw", | 164 | CompletionItemKind::Keyword => "kw", |
154 | CompletionItemKind::Macro => "ma", | ||
155 | CompletionItemKind::Method => "me", | 165 | CompletionItemKind::Method => "me", |
156 | CompletionItemKind::Module => "md", | ||
157 | CompletionItemKind::Snippet => "sn", | 166 | CompletionItemKind::Snippet => "sn", |
158 | CompletionItemKind::Static => "sc", | ||
159 | CompletionItemKind::Struct => "st", | ||
160 | CompletionItemKind::Trait => "tt", | ||
161 | CompletionItemKind::TypeAlias => "ta", | ||
162 | CompletionItemKind::TypeParam => "tp", | ||
163 | CompletionItemKind::UnresolvedReference => "??", | 167 | CompletionItemKind::UnresolvedReference => "??", |
164 | } | 168 | } |
165 | } | 169 | } |
@@ -382,8 +386,8 @@ impl Builder { | |||
382 | self.insert_text_format = InsertTextFormat::Snippet; | 386 | self.insert_text_format = InsertTextFormat::Snippet; |
383 | self.insert_text(snippet) | 387 | self.insert_text(snippet) |
384 | } | 388 | } |
385 | pub(crate) fn kind(mut self, kind: CompletionItemKind) -> Builder { | 389 | pub(crate) fn kind(mut self, kind: impl Into<CompletionItemKind>) -> Builder { |
386 | self.kind = Some(kind); | 390 | self.kind = Some(kind.into()); |
387 | self | 391 | self |
388 | } | 392 | } |
389 | pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder { | 393 | pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder { |