1
1
use join_to_string:: join;
2
-
3
2
use hir:: { Docs , Resolution } ;
3
+ use ra_syntax:: AstNode ;
4
+ use test_utils:: tested_by;
4
5
5
- use crate :: {
6
- completion:: { CompletionItem , CompletionItemKind , Completions , CompletionKind , CompletionContext } ,
7
- } ;
6
+ use crate :: completion:: { CompletionItem , CompletionItemKind , Completions , CompletionKind , CompletionContext } ;
8
7
9
8
pub ( super ) fn complete_path ( acc : & mut Completions , ctx : & CompletionContext ) {
10
9
let path = match & ctx. path_prefix {
@@ -19,6 +18,17 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
19
18
hir:: ModuleDef :: Module ( module) => {
20
19
let module_scope = module. scope ( ctx. db ) ;
21
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
32
CompletionItem :: new (
23
33
CompletionKind :: Reference ,
24
34
ctx. source_range ( ) ,
@@ -54,22 +64,22 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
54
64
55
65
#[ cfg( test) ]
56
66
mod tests {
57
- use crate :: completion:: CompletionKind ;
58
- use crate :: completion:: completion_item:: check_completion;
67
+ use crate :: completion:: {
68
+ CompletionKind ,
69
+ completion_item:: { check_completion, do_completion} ,
70
+ } ;
71
+
72
+ use test_utils:: covers;
59
73
60
74
fn check_reference_completion ( code : & str , expected_completions : & str ) {
61
75
check_completion ( code, expected_completions, CompletionKind :: Reference ) ;
62
76
}
63
77
64
78
#[ test]
65
- #[ ignore] // should not complete foo, which currently doesn't work
66
79
fn dont_complete_current_use ( ) {
67
- check_reference_completion (
68
- "dont_complete_current_use" ,
69
- r"
70
- use self::foo<|>;
71
- " ,
72
- ) ;
80
+ covers ! ( dont_complete_current_use) ;
81
+ let completions = do_completion ( r"use self::foo<|>;" , CompletionKind :: Reference ) ;
82
+ assert ! ( completions. is_empty( ) ) ;
73
83
}
74
84
75
85
#[ test]
0 commit comments