1
1
//! Completion of names from the current scope, e.g. locals and imported items.
2
2
3
3
use crate :: completion:: { CompletionContext , Completions } ;
4
+ use hir:: ScopeDef ;
4
5
5
6
pub ( super ) fn complete_scope ( acc : & mut Completions , ctx : & CompletionContext ) {
6
7
if !ctx. is_trivial_path && !ctx. is_pat_binding_and_path {
7
8
return ;
8
9
}
9
10
10
- ctx. scope ( ) . process_all_names ( & mut |name, res| acc. add_resolution ( ctx, name. to_string ( ) , & res) ) ;
11
+ ctx. scope ( ) . process_all_names ( & mut |name, res| match ( ctx. is_pat_binding_and_path , & res) {
12
+ ( true , ScopeDef :: Local ( ..) ) => { }
13
+ _ => acc. add_resolution ( ctx, name. to_string ( ) , & res) ,
14
+ } ) ;
11
15
}
12
16
13
17
#[ cfg( test) ]
@@ -21,53 +25,23 @@ mod tests {
21
25
}
22
26
23
27
#[ test]
24
- fn nested_bind_pat_and_path ( ) {
28
+ fn bind_pat_and_path_ignore_ref ( ) {
25
29
assert_debug_snapshot ! (
26
30
do_reference_completion(
27
31
r"
28
- enum First {
32
+ enum Enum {
29
33
A,
30
34
B,
31
35
}
32
- enum Second {
33
- A(First),
34
- B(First),
35
- }
36
- fn quux(x: Option<Option<Second>>>) {
36
+ fn quux(x: Option<Enum>) {
37
37
match x {
38
38
None => (),
39
- Some(Some(Second(Fi <|>)) ) => (),
39
+ Some(ref en <|>) => (),
40
40
}
41
41
}
42
42
"
43
43
) ,
44
- @r###"
45
- [
46
- CompletionItem {
47
- label: "First",
48
- source_range: [363; 365),
49
- delete: [363; 365),
50
- insert: "First",
51
- kind: Enum,
52
- },
53
- CompletionItem {
54
- label: "Second",
55
- source_range: [363; 365),
56
- delete: [363; 365),
57
- insert: "Second",
58
- kind: Enum,
59
- },
60
- CompletionItem {
61
- label: "quux(…)",
62
- source_range: [363; 365),
63
- delete: [363; 365),
64
- insert: "quux(${1:x})$0",
65
- kind: Function,
66
- lookup: "quux",
67
- detail: "fn quux(x: Option<Option<Second>>)",
68
- },
69
- ]
70
- "###
44
+ @r###"[]"###
71
45
) ;
72
46
}
73
47
@@ -83,7 +57,7 @@ mod tests {
83
57
fn quux(x: Option<Enum>) {
84
58
match x {
85
59
None => (),
86
- Some(en <|>) => (),
60
+ Some(En <|>) => (),
87
61
}
88
62
}
89
63
"
@@ -97,13 +71,6 @@ mod tests {
97
71
insert: "Enum",
98
72
kind: Enum,
99
73
},
100
- CompletionItem {
101
- label: "None",
102
- source_range: [231; 233),
103
- delete: [231; 233),
104
- insert: "None",
105
- kind: Binding,
106
- },
107
74
CompletionItem {
108
75
label: "quux(…)",
109
76
source_range: [231; 233),
@@ -112,13 +79,7 @@ mod tests {
112
79
kind: Function,
113
80
lookup: "quux",
114
81
detail: "fn quux(x: Option<Enum>)",
115
- },
116
- CompletionItem {
117
- label: "x",
118
- source_range: [231; 233),
119
- delete: [231; 233),
120
- insert: "x",
121
- kind: Binding,
82
+ trigger_call_info: true,
122
83
},
123
84
]
124
85
"###
0 commit comments