File tree Expand file tree Collapse file tree 2 files changed +355
-3
lines changed
crates/ide-completion/src Expand file tree Collapse file tree 2 files changed +355
-3
lines changed Original file line number Diff line number Diff line change @@ -943,9 +943,14 @@ fn classify_name_ref<'db>(
943
943
} ;
944
944
let prev_sibling = non_trivia_sibling ( node. into ( ) , Direction :: Prev ) ?. into_node ( ) ?;
945
945
946
- ast:: ExprStmt :: cast ( prev_sibling. clone ( ) )
947
- . and_then ( |it| it. expr ( ) )
948
- . or_else ( || ast:: Expr :: cast ( prev_sibling) )
946
+ match_ast ! {
947
+ match prev_sibling {
948
+ ast:: ExprStmt ( stmt) => stmt. expr( ) . filter( |_| stmt. semicolon_token( ) . is_none( ) ) ,
949
+ ast:: LetStmt ( stmt) => stmt. initializer( ) . filter( |_| stmt. semicolon_token( ) . is_none( ) ) ,
950
+ ast:: Expr ( expr) => Some ( expr) ,
951
+ _ => None ,
952
+ }
953
+ }
949
954
} ) ( ) ;
950
955
matches ! ( prev_expr, Some ( ast:: Expr :: IfExpr ( _) ) )
951
956
} ;
Original file line number Diff line number Diff line change @@ -1210,6 +1210,353 @@ fn foo() { if foo {} el$0 { let x = 92; } }
1210
1210
sn ppd
1211
1211
"# ] ] ,
1212
1212
) ;
1213
+ check (
1214
+ r#"
1215
+ fn foo() { let x = if foo {} $0 }
1216
+ "# ,
1217
+ expect ! [ [ r#"
1218
+ fn foo() fn()
1219
+ bt u32 u32
1220
+ kw async
1221
+ kw const
1222
+ kw crate::
1223
+ kw else
1224
+ kw else if
1225
+ kw enum
1226
+ kw extern
1227
+ kw false
1228
+ kw fn
1229
+ kw for
1230
+ kw if
1231
+ kw if let
1232
+ kw impl
1233
+ kw impl for
1234
+ kw let
1235
+ kw letm
1236
+ kw loop
1237
+ kw match
1238
+ kw mod
1239
+ kw return
1240
+ kw self::
1241
+ kw static
1242
+ kw struct
1243
+ kw trait
1244
+ kw true
1245
+ kw type
1246
+ kw union
1247
+ kw unsafe
1248
+ kw use
1249
+ kw while
1250
+ kw while let
1251
+ sn macro_rules
1252
+ sn pd
1253
+ sn ppd
1254
+ "# ] ] ,
1255
+ ) ;
1256
+ check (
1257
+ r#"
1258
+ fn foo() { let x = if foo {} el$0 }
1259
+ "# ,
1260
+ expect ! [ [ r#"
1261
+ fn foo() fn()
1262
+ lc x ()
1263
+ bt u32 u32
1264
+ kw async
1265
+ kw const
1266
+ kw crate::
1267
+ kw else
1268
+ kw else if
1269
+ kw enum
1270
+ kw extern
1271
+ kw false
1272
+ kw fn
1273
+ kw for
1274
+ kw if
1275
+ kw if let
1276
+ kw impl
1277
+ kw impl for
1278
+ kw let
1279
+ kw letm
1280
+ kw loop
1281
+ kw match
1282
+ kw mod
1283
+ kw return
1284
+ kw self::
1285
+ kw static
1286
+ kw struct
1287
+ kw trait
1288
+ kw true
1289
+ kw type
1290
+ kw union
1291
+ kw unsafe
1292
+ kw use
1293
+ kw while
1294
+ kw while let
1295
+ sn macro_rules
1296
+ sn pd
1297
+ sn ppd
1298
+ "# ] ] ,
1299
+ ) ;
1300
+ check (
1301
+ r#"
1302
+ fn foo() { let x = if foo {} $0 let y = 92; }
1303
+ "# ,
1304
+ expect ! [ [ r#"
1305
+ fn foo() fn()
1306
+ bt u32 u32
1307
+ kw async
1308
+ kw const
1309
+ kw crate::
1310
+ kw else
1311
+ kw else if
1312
+ kw enum
1313
+ kw extern
1314
+ kw false
1315
+ kw fn
1316
+ kw for
1317
+ kw if
1318
+ kw if let
1319
+ kw impl
1320
+ kw impl for
1321
+ kw let
1322
+ kw letm
1323
+ kw loop
1324
+ kw match
1325
+ kw mod
1326
+ kw return
1327
+ kw self::
1328
+ kw static
1329
+ kw struct
1330
+ kw trait
1331
+ kw true
1332
+ kw type
1333
+ kw union
1334
+ kw unsafe
1335
+ kw use
1336
+ kw while
1337
+ kw while let
1338
+ sn macro_rules
1339
+ sn pd
1340
+ sn ppd
1341
+ "# ] ] ,
1342
+ ) ;
1343
+ check (
1344
+ r#"
1345
+ fn foo() { let x = if foo {} el$0 let y = 92; }
1346
+ "# ,
1347
+ expect ! [ [ r#"
1348
+ fn foo() fn()
1349
+ lc x ()
1350
+ bt u32 u32
1351
+ kw async
1352
+ kw const
1353
+ kw crate::
1354
+ kw else
1355
+ kw else if
1356
+ kw enum
1357
+ kw extern
1358
+ kw false
1359
+ kw fn
1360
+ kw for
1361
+ kw if
1362
+ kw if let
1363
+ kw impl
1364
+ kw impl for
1365
+ kw let
1366
+ kw letm
1367
+ kw loop
1368
+ kw match
1369
+ kw mod
1370
+ kw return
1371
+ kw self::
1372
+ kw static
1373
+ kw struct
1374
+ kw trait
1375
+ kw true
1376
+ kw type
1377
+ kw union
1378
+ kw unsafe
1379
+ kw use
1380
+ kw while
1381
+ kw while let
1382
+ sn macro_rules
1383
+ sn pd
1384
+ sn ppd
1385
+ "# ] ] ,
1386
+ ) ;
1387
+ check (
1388
+ r#"
1389
+ fn foo() { let x = if foo {} $0; }
1390
+ "# ,
1391
+ expect ! [ [ r#"
1392
+ fn foo() fn()
1393
+ bt u32 u32
1394
+ kw async
1395
+ kw const
1396
+ kw crate::
1397
+ kw else
1398
+ kw else if
1399
+ kw enum
1400
+ kw extern
1401
+ kw false
1402
+ kw fn
1403
+ kw for
1404
+ kw if
1405
+ kw if let
1406
+ kw impl
1407
+ kw impl for
1408
+ kw let
1409
+ kw letm
1410
+ kw loop
1411
+ kw match
1412
+ kw mod
1413
+ kw return
1414
+ kw self::
1415
+ kw static
1416
+ kw struct
1417
+ kw trait
1418
+ kw true
1419
+ kw type
1420
+ kw union
1421
+ kw unsafe
1422
+ kw use
1423
+ kw while
1424
+ kw while let
1425
+ sn macro_rules
1426
+ sn pd
1427
+ sn ppd
1428
+ "# ] ] ,
1429
+ ) ;
1430
+ check (
1431
+ r#"
1432
+ fn foo() { let x = if foo {} el$0; }
1433
+ "# ,
1434
+ expect ! [ [ r#"
1435
+ fn foo() fn()
1436
+ lc x ()
1437
+ bt u32 u32
1438
+ kw async
1439
+ kw const
1440
+ kw crate::
1441
+ kw else
1442
+ kw else if
1443
+ kw enum
1444
+ kw extern
1445
+ kw false
1446
+ kw fn
1447
+ kw for
1448
+ kw if
1449
+ kw if let
1450
+ kw impl
1451
+ kw impl for
1452
+ kw let
1453
+ kw letm
1454
+ kw loop
1455
+ kw match
1456
+ kw mod
1457
+ kw return
1458
+ kw self::
1459
+ kw static
1460
+ kw struct
1461
+ kw trait
1462
+ kw true
1463
+ kw type
1464
+ kw union
1465
+ kw unsafe
1466
+ kw use
1467
+ kw while
1468
+ kw while let
1469
+ sn macro_rules
1470
+ sn pd
1471
+ sn ppd
1472
+ "# ] ] ,
1473
+ ) ;
1474
+ check (
1475
+ r#"
1476
+ fn foo() { let x = if foo {} $0; let y = 92; }
1477
+ "# ,
1478
+ expect ! [ [ r#"
1479
+ fn foo() fn()
1480
+ bt u32 u32
1481
+ kw async
1482
+ kw const
1483
+ kw crate::
1484
+ kw else
1485
+ kw else if
1486
+ kw enum
1487
+ kw extern
1488
+ kw false
1489
+ kw fn
1490
+ kw for
1491
+ kw if
1492
+ kw if let
1493
+ kw impl
1494
+ kw impl for
1495
+ kw let
1496
+ kw letm
1497
+ kw loop
1498
+ kw match
1499
+ kw mod
1500
+ kw return
1501
+ kw self::
1502
+ kw static
1503
+ kw struct
1504
+ kw trait
1505
+ kw true
1506
+ kw type
1507
+ kw union
1508
+ kw unsafe
1509
+ kw use
1510
+ kw while
1511
+ kw while let
1512
+ sn macro_rules
1513
+ sn pd
1514
+ sn ppd
1515
+ "# ] ] ,
1516
+ ) ;
1517
+ check (
1518
+ r#"
1519
+ fn foo() { let x = if foo {} $0 else {}; }
1520
+ "# ,
1521
+ expect ! [ [ r#"
1522
+ fn foo fn()
1523
+ bt u32 u32
1524
+ kw async
1525
+ kw const
1526
+ kw crate::
1527
+ kw else
1528
+ kw else if
1529
+ kw enum
1530
+ kw extern
1531
+ kw false
1532
+ kw fn
1533
+ kw for
1534
+ kw if
1535
+ kw if let
1536
+ kw impl
1537
+ kw impl for
1538
+ kw let
1539
+ kw letm
1540
+ kw loop
1541
+ kw match
1542
+ kw mod
1543
+ kw return
1544
+ kw self::
1545
+ kw static
1546
+ kw struct
1547
+ kw trait
1548
+ kw true
1549
+ kw type
1550
+ kw union
1551
+ kw unsafe
1552
+ kw use
1553
+ kw while
1554
+ kw while let
1555
+ sn macro_rules
1556
+ sn pd
1557
+ sn ppd
1558
+ "# ] ] ,
1559
+ ) ;
1213
1560
}
1214
1561
1215
1562
#[ test]
You can’t perform that action at this time.
0 commit comments