diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index d3bc14894..4101ce88a 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | use hir::{Docs, Documentation}; | 1 | use hir::{Docs, Documentation, PerNs, Resolution}; |
2 | use ra_syntax::TextRange; | 2 | use ra_syntax::{ |
3 | TextRange, | ||
4 | }; | ||
3 | use ra_text_edit::TextEdit; | 5 | use ra_text_edit::TextEdit; |
4 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
5 | 7 | ||
@@ -48,6 +50,7 @@ pub enum CompletionItemKind { | |||
48 | Trait, | 50 | Trait, |
49 | TypeAlias, | 51 | TypeAlias, |
50 | Method, | 52 | Method, |
53 | TypeParam, | ||
51 | } | 54 | } |
52 | 55 | ||
53 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] | 56 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] |
@@ -207,23 +210,38 @@ impl Builder { | |||
207 | pub(super) fn from_resolution( | 210 | pub(super) fn from_resolution( |
208 | mut self, | 211 | mut self, |
209 | ctx: &CompletionContext, | 212 | ctx: &CompletionContext, |
210 | resolution: &hir::Resolution, | 213 | resolution: &PerNs<Resolution>, |
211 | ) -> Builder { | 214 | ) -> Builder { |
212 | let def = resolution.def.take_types().or(resolution.def.take_values()); | 215 | use hir::ModuleDef::*; |
216 | |||
217 | let def = resolution | ||
218 | .as_ref() | ||
219 | .take_types() | ||
220 | .or(resolution.as_ref().take_values()); | ||
213 | let def = match def { | 221 | let def = match def { |
214 | None => return self, | 222 | None => return self, |
215 | Some(it) => it, | 223 | Some(it) => it, |
216 | }; | 224 | }; |
217 | let (kind, docs) = match def { | 225 | let (kind, docs) = match def { |
218 | hir::ModuleDef::Module(it) => (CompletionItemKind::Module, it.docs(ctx.db)), | 226 | Resolution::Def { def: Module(it) } => (CompletionItemKind::Module, it.docs(ctx.db)), |
219 | hir::ModuleDef::Function(func) => return self.from_function(ctx, func), | 227 | Resolution::Def { |
220 | hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), | 228 | def: Function(func), |
221 | hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), | 229 | } => return self.from_function(ctx, *func), |
222 | hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), | 230 | Resolution::Def { def: Struct(it) } => (CompletionItemKind::Struct, it.docs(ctx.db)), |
223 | hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), | 231 | Resolution::Def { def: Enum(it) } => (CompletionItemKind::Enum, it.docs(ctx.db)), |
224 | hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), | 232 | Resolution::Def { |
225 | hir::ModuleDef::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), | 233 | def: EnumVariant(it), |
226 | hir::ModuleDef::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | 234 | } => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), |
235 | Resolution::Def { def: Const(it) } => (CompletionItemKind::Const, it.docs(ctx.db)), | ||
236 | Resolution::Def { def: Static(it) } => (CompletionItemKind::Static, it.docs(ctx.db)), | ||
237 | Resolution::Def { def: Trait(it) } => (CompletionItemKind::Trait, it.docs(ctx.db)), | ||
238 | Resolution::Def { def: Type(it) } => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | ||
239 | Resolution::GenericParam { .. } => (CompletionItemKind::TypeParam, None), | ||
240 | Resolution::LocalBinding { .. } => (CompletionItemKind::Binding, None), | ||
241 | Resolution::SelfType { .. } => ( | ||
242 | CompletionItemKind::TypeParam, // (does this need its own kind?) | ||
243 | None, | ||
244 | ), | ||
227 | }; | 245 | }; |
228 | self.kind = Some(kind); | 246 | self.kind = Some(kind); |
229 | self.documentation = docs; | 247 | self.documentation = docs; |