diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_path.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 39aefdb13..91ca7525e 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -1,10 +1,9 @@ | |||
1 | use join_to_string::join; | 1 | use join_to_string::join; |
2 | |||
3 | use hir::{Docs, Resolution}; | 2 | use hir::{Docs, Resolution}; |
3 | use ra_syntax::AstNode; | ||
4 | use test_utils::tested_by; | ||
4 | 5 | ||
5 | use crate::{ | 6 | use crate::completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}; |
6 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, | ||
7 | }; | ||
8 | 7 | ||
9 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | 8 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { |
10 | let path = match &ctx.path_prefix { | 9 | let path = match &ctx.path_prefix { |
@@ -19,6 +18,17 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
19 | hir::ModuleDef::Module(module) => { | 18 | hir::ModuleDef::Module(module) => { |
20 | let module_scope = module.scope(ctx.db); | 19 | let module_scope = module.scope(ctx.db); |
21 | for (name, res) in module_scope.entries() { | 20 | for (name, res) in module_scope.entries() { |
21 | if Some(module) == ctx.module { | ||
22 | if let Some(import) = res.import { | ||
23 | let path = module.import_source(ctx.db, import); | ||
24 | if path.syntax().range().contains_inclusive(ctx.offset) { | ||
25 | // for `use self::foo<|>`, don't suggest `foo` as a completion | ||
26 | tested_by!(dont_complete_current_use); | ||
27 | continue; | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | |||
22 | CompletionItem::new( | 32 | CompletionItem::new( |
23 | CompletionKind::Reference, | 33 | CompletionKind::Reference, |
24 | ctx.source_range(), | 34 | ctx.source_range(), |
@@ -54,22 +64,22 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
54 | 64 | ||
55 | #[cfg(test)] | 65 | #[cfg(test)] |
56 | mod tests { | 66 | mod tests { |
57 | use crate::completion::CompletionKind; | 67 | use crate::completion::{ |
58 | use crate::completion::completion_item::check_completion; | 68 | CompletionKind, |
69 | completion_item::{check_completion, do_completion}, | ||
70 | }; | ||
71 | |||
72 | use test_utils::covers; | ||
59 | 73 | ||
60 | fn check_reference_completion(code: &str, expected_completions: &str) { | 74 | fn check_reference_completion(code: &str, expected_completions: &str) { |
61 | check_completion(code, expected_completions, CompletionKind::Reference); | 75 | check_completion(code, expected_completions, CompletionKind::Reference); |
62 | } | 76 | } |
63 | 77 | ||
64 | #[test] | 78 | #[test] |
65 | #[ignore] // should not complete foo, which currently doesn't work | ||
66 | fn dont_complete_current_use() { | 79 | fn dont_complete_current_use() { |
67 | check_reference_completion( | 80 | covers!(dont_complete_current_use); |
68 | "dont_complete_current_use", | 81 | let completions = do_completion(r"use self::foo<|>;", CompletionKind::Reference); |
69 | r" | 82 | assert!(completions.is_empty()); |
70 | use self::foo<|>; | ||
71 | ", | ||
72 | ); | ||
73 | } | 83 | } |
74 | 84 | ||
75 | #[test] | 85 | #[test] |