File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
crates/ide-completion/src Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,46 @@ fn main() {
269
269
"# ,
270
270
) ;
271
271
272
+ check_edit (
273
+ "else if" ,
274
+ r#"
275
+ fn main() {
276
+ let x = if true {
277
+ ()
278
+ } $0 else {};
279
+ }
280
+ "# ,
281
+ r#"
282
+ fn main() {
283
+ let x = if true {
284
+ ()
285
+ } else if $1 {
286
+ $0
287
+ } else {};
288
+ }
289
+ "# ,
290
+ ) ;
291
+
292
+ check_edit (
293
+ "else if" ,
294
+ r#"
295
+ fn main() {
296
+ let x = if true {
297
+ ()
298
+ } $0 else if true {};
299
+ }
300
+ "# ,
301
+ r#"
302
+ fn main() {
303
+ let x = if true {
304
+ ()
305
+ } else if $1 {
306
+ $0
307
+ } else if true {};
308
+ }
309
+ "# ,
310
+ ) ;
311
+
272
312
check_edit (
273
313
"else" ,
274
314
r#"
Original file line number Diff line number Diff line change @@ -970,6 +970,16 @@ fn classify_name_ref<'db>(
970
970
let after_incomplete_let = |node : SyntaxNode | {
971
971
prev_expr ( node) . and_then ( |it| it. syntax ( ) . parent ( ) ) . and_then ( ast:: LetStmt :: cast)
972
972
} ;
973
+ let before_else_kw = |node : & SyntaxNode | {
974
+ node. parent ( )
975
+ . and_then ( ast:: ExprStmt :: cast)
976
+ . filter ( |stmt| stmt. semicolon_token ( ) . is_none ( ) )
977
+ . and_then ( |stmt| non_trivia_sibling ( stmt. syntax ( ) . clone ( ) . into ( ) , Direction :: Next ) )
978
+ . and_then ( NodeOrToken :: into_node)
979
+ . filter ( |next| next. kind ( ) == SyntaxKind :: ERROR )
980
+ . and_then ( |next| next. first_token ( ) )
981
+ . is_some_and ( |token| token. kind ( ) == SyntaxKind :: ELSE_KW )
982
+ } ;
973
983
974
984
// We do not want to generate path completions when we are sandwiched between an item decl signature and its body.
975
985
// ex. trait Foo $0 {}
@@ -1276,7 +1286,7 @@ fn classify_name_ref<'db>(
1276
1286
. parent ( )
1277
1287
. and_then ( ast:: LetStmt :: cast)
1278
1288
. is_some_and ( |it| it. semicolon_token ( ) . is_none ( ) )
1279
- || after_incomplete_let && incomplete_expr_stmt. unwrap_or ( true ) ;
1289
+ || after_incomplete_let && incomplete_expr_stmt. unwrap_or ( true ) && ! before_else_kw ( it ) ;
1280
1290
let in_value = it. parent ( ) . and_then ( Either :: < ast:: LetStmt , ast:: ArgList > :: cast) . is_some ( ) ;
1281
1291
let impl_ = fetch_immediate_impl ( sema, original_file, expr. syntax ( ) ) ;
1282
1292
You can’t perform that action at this time.
0 commit comments