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/complete_path.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/complete_path.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index b33ddcde5..0b9948d4b 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -1,21 +1,21 @@ | |||
1 | use join_to_string::join; | 1 | use join_to_string::join; |
2 | 2 | ||
3 | use hir::{Docs, Resolution}; | ||
4 | |||
3 | use crate::{ | 5 | use crate::{ |
4 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, | 6 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, |
5 | }; | 7 | }; |
6 | 8 | ||
7 | use hir::Docs; | ||
8 | |||
9 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | 9 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { |
10 | let (path, module) = match (&ctx.path_prefix, &ctx.module) { | 10 | let path = match &ctx.path_prefix { |
11 | (Some(path), Some(module)) => (path.clone(), module), | 11 | Some(path) => path.clone(), |
12 | _ => return, | 12 | _ => return, |
13 | }; | 13 | }; |
14 | let def_id = match module.resolve_path(ctx.db, &path).take_types() { | 14 | let def = match ctx.resolver.resolve_path(ctx.db, &path).take_types() { |
15 | Some(it) => it, | 15 | Some(Resolution::Def(def)) => def, |
16 | None => return, | 16 | _ => return, |
17 | }; | 17 | }; |
18 | match def_id { | 18 | match def { |
19 | hir::ModuleDef::Module(module) => { | 19 | hir::ModuleDef::Module(module) => { |
20 | let module_scope = module.scope(ctx.db); | 20 | let module_scope = module.scope(ctx.db); |
21 | for (name, res) in module_scope.entries() { | 21 | for (name, res) in module_scope.entries() { |
@@ -24,7 +24,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
24 | ctx.source_range(), | 24 | ctx.source_range(), |
25 | name.to_string(), | 25 | name.to_string(), |
26 | ) | 26 | ) |
27 | .from_resolution(ctx, res) | 27 | .from_resolution(ctx, &res.def.map(hir::Resolution::Def)) |
28 | .add_to(acc); | 28 | .add_to(acc); |
29 | } | 29 | } |
30 | } | 30 | } |
@@ -66,6 +66,17 @@ mod tests { | |||
66 | } | 66 | } |
67 | 67 | ||
68 | #[test] | 68 | #[test] |
69 | #[ignore] // should not complete foo, which currently doesn't work | ||
70 | fn dont_complete_current_use() { | ||
71 | check_reference_completion( | ||
72 | "dont_complete_current_use", | ||
73 | r" | ||
74 | use self::foo<|>; | ||
75 | ", | ||
76 | ); | ||
77 | } | ||
78 | |||
79 | #[test] | ||
69 | fn completes_mod_with_docs() { | 80 | fn completes_mod_with_docs() { |
70 | check_reference_completion( | 81 | check_reference_completion( |
71 | "mod_with_docs", | 82 | "mod_with_docs", |