File tree Expand file tree Collapse file tree 2 files changed +120
-1
lines changed Expand file tree Collapse file tree 2 files changed +120
-1
lines changed Original file line number Diff line number Diff line change @@ -427,7 +427,6 @@ def nodes
427
427
] . compact
428
428
end
429
429
430
- # @todo Support shadowing.
431
430
# @return [Enumerable<Rucoa::Nodes::LvarNode>]
432
431
def reference_nodes
433
432
return [ ] unless assignment_node
@@ -446,13 +445,30 @@ def reference_nodes
446
445
node ,
447
446
*node . descendants
448
447
]
448
+ end . take_while do |node | # FIXME: flat_map and take_while are not correct solution for shadowing.
449
+ case node
450
+ when Nodes ::ArgNode , Nodes ::LvasgnNode
451
+ node . equal? ( assignment_node ) || node . name != assignment_node . name
452
+ else
453
+ true
454
+ end
449
455
end . select do |node |
450
456
case node
451
457
when Nodes ::LvarNode
452
458
node . name == @node . name
453
459
end
454
460
end
455
461
end
462
+
463
+ class UnshadowedNodeVisitor
464
+ def initialize (
465
+ node :,
466
+ &block
467
+ )
468
+ @block = block
469
+ @node = node
470
+ end
471
+ end
456
472
end
457
473
458
474
class ModuleMapper < Base
Original file line number Diff line number Diff line change @@ -1335,5 +1335,108 @@ def a
1335
1335
)
1336
1336
end
1337
1337
end
1338
+
1339
+ context 'when local variable is shadowed by local variable assignment' do
1340
+ let ( :content ) do
1341
+ <<~RUBY
1342
+ a = 1
1343
+ b = 2
1344
+ a
1345
+ a = 2
1346
+ a
1347
+ RUBY
1348
+ end
1349
+
1350
+ let ( :position ) do
1351
+ Rucoa ::Position . new (
1352
+ column : 0 ,
1353
+ line : 1
1354
+ )
1355
+ end
1356
+
1357
+ it 'returns highlights' do
1358
+ subject
1359
+ expect ( server . responses ) . to match (
1360
+ [
1361
+ hash_including (
1362
+ 'id' => 1 ,
1363
+ 'result' => Array . new ( 2 ) do
1364
+ a_kind_of ( Hash )
1365
+ end
1366
+ )
1367
+ ]
1368
+ )
1369
+ end
1370
+ end
1371
+
1372
+ context 'when local variable is shadowed by block argument' do
1373
+ let ( :content ) do
1374
+ <<~RUBY
1375
+ a = 1
1376
+ a
1377
+ foo do |a|
1378
+ a
1379
+ end
1380
+ RUBY
1381
+ end
1382
+
1383
+ let ( :position ) do
1384
+ Rucoa ::Position . new (
1385
+ column : 0 ,
1386
+ line : 1
1387
+ )
1388
+ end
1389
+
1390
+ it 'returns highlights' do
1391
+ subject
1392
+ expect ( server . responses ) . to match (
1393
+ [
1394
+ hash_including (
1395
+ 'id' => 1 ,
1396
+ 'result' => Array . new ( 2 ) do
1397
+ a_kind_of ( Hash )
1398
+ end
1399
+ )
1400
+ ]
1401
+ )
1402
+ end
1403
+ end
1404
+
1405
+ context 'when local variable is shadowed but restored' do
1406
+ before do
1407
+ pending 'not implemented yet'
1408
+ end
1409
+
1410
+ let ( :content ) do
1411
+ <<~RUBY
1412
+ a = 1
1413
+ foo do |a|
1414
+ a
1415
+ end
1416
+ a
1417
+ RUBY
1418
+ end
1419
+
1420
+ let ( :position ) do
1421
+ Rucoa ::Position . new (
1422
+ column : 0 ,
1423
+ line : 1
1424
+ )
1425
+ end
1426
+
1427
+ it 'returns highlights' do
1428
+ subject
1429
+ expect ( server . responses ) . to match (
1430
+ [
1431
+ hash_including (
1432
+ 'id' => 1 ,
1433
+ 'result' => Array . new ( 2 ) do
1434
+ a_kind_of ( Hash )
1435
+ end
1436
+ )
1437
+ ]
1438
+ )
1439
+ end
1440
+ end
1338
1441
end
1339
1442
end
You can’t perform that action at this time.
0 commit comments