@@ -4,7 +4,7 @@ use crate::{CompletionContext, Completions};
4
4
5
5
/// Completes constats and paths in patterns.
6
6
pub ( crate ) fn complete_pattern ( acc : & mut Completions , ctx : & CompletionContext ) {
7
- if !ctx. is_pat_binding_or_const {
7
+ if !( ctx. is_pat_binding_or_const || ctx . is_irrefutable_let_pat_binding ) {
8
8
return ;
9
9
}
10
10
if ctx. record_pat_syntax . is_some ( ) {
@@ -14,20 +14,27 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
14
14
// FIXME: ideally, we should look at the type we are matching against and
15
15
// suggest variants + auto-imports
16
16
ctx. scope . process_all_names ( & mut |name, res| {
17
- match & res {
18
- hir:: ScopeDef :: ModuleDef ( def) => match def {
19
- hir:: ModuleDef :: Adt ( hir:: Adt :: Enum ( ..) )
20
- | hir:: ModuleDef :: Adt ( hir:: Adt :: Struct ( ..) )
21
- | hir:: ModuleDef :: EnumVariant ( ..)
22
- | hir:: ModuleDef :: Const ( ..)
23
- | hir:: ModuleDef :: Module ( ..) => ( ) ,
24
- _ => return ,
25
- } ,
26
- hir:: ScopeDef :: MacroDef ( _) => ( ) ,
27
- _ => return ,
17
+ let add_resolution = match & res {
18
+ hir:: ScopeDef :: ModuleDef ( def) => {
19
+ if ctx. is_irrefutable_let_pat_binding {
20
+ matches ! ( def, hir:: ModuleDef :: Adt ( hir:: Adt :: Struct ( _) ) )
21
+ } else {
22
+ matches ! (
23
+ def,
24
+ hir:: ModuleDef :: Adt ( hir:: Adt :: Enum ( ..) )
25
+ | hir:: ModuleDef :: Adt ( hir:: Adt :: Struct ( ..) )
26
+ | hir:: ModuleDef :: EnumVariant ( ..)
27
+ | hir:: ModuleDef :: Const ( ..)
28
+ | hir:: ModuleDef :: Module ( ..)
29
+ )
30
+ }
31
+ }
32
+ hir:: ScopeDef :: MacroDef ( _) => true ,
33
+ _ => false ,
28
34
} ;
29
-
30
- acc. add_resolution ( ctx, name. to_string ( ) , & res)
35
+ if add_resolution {
36
+ acc. add_resolution ( ctx, name. to_string ( ) , & res) ;
37
+ }
31
38
} ) ;
32
39
}
33
40
@@ -85,4 +92,26 @@ fn foo() {
85
92
"# ] ] ,
86
93
) ;
87
94
}
95
+
96
+ #[ test]
97
+ fn completes_in_irrefutable_let ( ) {
98
+ check (
99
+ r#"
100
+ enum E { X }
101
+ use self::E::X;
102
+ const Z: E = E::X;
103
+ mod m {}
104
+
105
+ static FOO: E = E::X;
106
+ struct Bar { f: u32 }
107
+
108
+ fn foo() {
109
+ let <|>
110
+ }
111
+ "# ,
112
+ expect ! [ [ r#"
113
+ st Bar
114
+ "# ] ] ,
115
+ ) ;
116
+ }
88
117
}
0 commit comments