diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-01 22:37:59 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-01 22:37:59 +0000 |
commit | 4447019f4b5f24728bb7b91b161755ddb373c74c (patch) | |
tree | c53ff3531cbbad182e821eb92fa9ad201d2bff0c /crates/ra_ide_api/src/completion/completion_item.rs | |
parent | 2b5c226e86892113bcab478cdf4c9adaf1e7b2f6 (diff) | |
parent | c5852f422ff45adaa21815c1a15e03b067a56a82 (diff) |
Merge #693
693: Name resolution refactoring r=matklad a=flodiebold
This is still very WIP, but it's becoming quite big and I want to make sure this isn't going in a completely bad direction :sweat_smile:. I'm not really happy with how the path resolution looks, and I'm not sure `PerNs<Resolution>` is the best return type -- there are 'this cannot happen in the (types/values) namespace' cases everywhere. I also want to unify the `resolver` and `nameres` namespaces once I'm done switching everything to `Resolver`. Also, `Resolver` only has a lifetime because it needs to have a reference to the `ItemMap` during import resolution :confused:
The differences in the completion snapshots are almost completely just ordering (except it completes `Self` as well now), so I changed it to sort the completions before snapshotting.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 40 |
1 files changed, 27 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..bada6a33b 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,34 @@ 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(Module(it)) => (CompletionItemKind::Module, it.docs(ctx.db)), |
219 | hir::ModuleDef::Function(func) => return self.from_function(ctx, func), | 227 | Resolution::Def(Function(func)) => return self.from_function(ctx, *func), |
220 | hir::ModuleDef::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)), | 228 | Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), |
221 | hir::ModuleDef::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)), | 229 | Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), |
222 | hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), | 230 | Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), |
223 | hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), | 231 | Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), |
224 | hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), | 232 | Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), |
225 | hir::ModuleDef::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), | 233 | Resolution::Def(Trait(it)) => (CompletionItemKind::Trait, it.docs(ctx.db)), |
226 | hir::ModuleDef::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | 234 | Resolution::Def(Type(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), |
235 | Resolution::GenericParam(..) => (CompletionItemKind::TypeParam, None), | ||
236 | Resolution::LocalBinding(..) => (CompletionItemKind::Binding, None), | ||
237 | Resolution::SelfType(..) => ( | ||
238 | CompletionItemKind::TypeParam, // (does this need its own kind?) | ||
239 | None, | ||
240 | ), | ||
227 | }; | 241 | }; |
228 | self.kind = Some(kind); | 242 | self.kind = Some(kind); |
229 | self.documentation = docs; | 243 | self.documentation = docs; |