@@ -14,7 +14,9 @@ pub(crate) fn complete_expr_path(
14
14
path_ctx : & PathCompletionCtx ,
15
15
) {
16
16
let _p = profile:: span ( "complete_expr_path" ) ;
17
-
17
+ if !ctx. qualifier_ctx . none ( ) {
18
+ return ;
19
+ }
18
20
let (
19
21
qualified,
20
22
in_block_expr,
@@ -23,6 +25,9 @@ pub(crate) fn complete_expr_path(
23
25
after_if_expr,
24
26
wants_mut_token,
25
27
in_condition,
28
+ ty,
29
+ incomplete_let,
30
+ impl_,
26
31
) = match path_ctx {
27
32
& PathCompletionCtx {
28
33
kind :
@@ -31,19 +36,26 @@ pub(crate) fn complete_expr_path(
31
36
in_loop_body,
32
37
after_if_expr,
33
38
in_condition,
39
+ incomplete_let,
34
40
ref ref_expr_parent,
35
41
ref is_func_update,
42
+ ref innermost_ret_ty,
43
+ ref impl_,
44
+ ..
36
45
} ,
37
46
ref qualified,
38
47
..
39
- } if ctx . qualifier_ctx . none ( ) => (
48
+ } => (
40
49
qualified,
41
50
in_block_expr,
42
51
in_loop_body,
43
52
is_func_update. is_some ( ) ,
44
53
after_if_expr,
45
54
ref_expr_parent. as_ref ( ) . map ( |it| it. mut_token ( ) . is_none ( ) ) . unwrap_or ( false ) ,
46
55
in_condition,
56
+ innermost_ret_ty,
57
+ incomplete_let,
58
+ impl_,
47
59
) ,
48
60
_ => return ,
49
61
} ;
@@ -172,8 +184,7 @@ pub(crate) fn complete_expr_path(
172
184
if let Some ( adt) =
173
185
ctx. expected_type . as_ref ( ) . and_then ( |ty| ty. strip_references ( ) . as_adt ( ) )
174
186
{
175
- let self_ty =
176
- ( || ctx. sema . to_def ( ctx. impl_def . as_ref ( ) ?) ?. self_ty ( ctx. db ) . as_adt ( ) ) ( ) ;
187
+ let self_ty = ( || ctx. sema . to_def ( impl_. as_ref ( ) ?) ?. self_ty ( ctx. db ) . as_adt ( ) ) ( ) ;
177
188
let complete_self = self_ty == Some ( adt) ;
178
189
179
190
match adt {
@@ -201,9 +212,15 @@ pub(crate) fn complete_expr_path(
201
212
}
202
213
}
203
214
hir:: Adt :: Enum ( e) => {
204
- super :: enum_variants_with_paths ( acc, ctx, e, |acc, ctx, variant, path| {
205
- acc. add_qualified_enum_variant ( ctx, variant, path)
206
- } ) ;
215
+ super :: enum_variants_with_paths (
216
+ acc,
217
+ ctx,
218
+ e,
219
+ impl_,
220
+ |acc, ctx, variant, path| {
221
+ acc. add_qualified_enum_variant ( ctx, variant, path)
222
+ } ,
223
+ ) ;
207
224
}
208
225
}
209
226
}
@@ -214,7 +231,8 @@ pub(crate) fn complete_expr_path(
214
231
} ) ;
215
232
216
233
if !is_func_update {
217
- let mut add_keyword = |kw, snippet| acc. add_keyword_snippet ( ctx, kw, snippet) ;
234
+ let mut add_keyword =
235
+ |kw, snippet| acc. add_keyword_snippet_expr ( ctx, kw, snippet, incomplete_let) ;
218
236
219
237
if !in_block_expr {
220
238
add_keyword ( "unsafe" , "unsafe {\n $0\n }" ) ;
@@ -252,10 +270,10 @@ pub(crate) fn complete_expr_path(
252
270
}
253
271
}
254
272
255
- if let Some ( fn_def ) = & ctx . function_def {
273
+ if let Some ( ty ) = ty {
256
274
add_keyword (
257
275
"return" ,
258
- match ( in_block_expr, fn_def . ret_type ( ) . is_some ( ) ) {
276
+ match ( in_block_expr, ty . is_unit ( ) ) {
259
277
( true , true ) => "return ;" ,
260
278
( true , false ) => "return;" ,
261
279
( false , true ) => "return $0" ,
0 commit comments