@@ -1408,11 +1408,15 @@ describe('server', () => {
1408
1408
} )
1409
1409
1410
1410
describe ( 'onPrepareRename' , ( ) => {
1411
- async function getPrepareRenameResult ( line : LSP . uinteger , character : LSP . uinteger ) {
1411
+ async function getPrepareRenameResult (
1412
+ line : LSP . uinteger ,
1413
+ character : LSP . uinteger ,
1414
+ { uri = FIXTURE_URI . RENAMING } = { } ,
1415
+ ) {
1412
1416
const { connection } = await initializeServer ( )
1413
1417
1414
1418
return connection . onPrepareRename . mock . calls [ 0 ] [ 0 ] (
1415
- { textDocument : { uri : FIXTURE_URI . RENAMING } , position : { line, character } } ,
1419
+ { textDocument : { uri } , position : { line, character } } ,
1416
1420
{ } as any ,
1417
1421
)
1418
1422
}
@@ -1480,6 +1484,22 @@ describe('server', () => {
1480
1484
},
1481
1485
}
1482
1486
` )
1487
+
1488
+ const readvar = await getPrepareRenameResult ( 2 , 18 , {
1489
+ uri : FIXTURE_URI . RENAMING_READ ,
1490
+ } )
1491
+ expect ( readvar ) . toMatchInlineSnapshot ( `
1492
+ {
1493
+ "end": {
1494
+ "character": 20,
1495
+ "line": 2,
1496
+ },
1497
+ "start": {
1498
+ "character": 13,
1499
+ "line": 2,
1500
+ },
1501
+ }
1502
+ ` )
1483
1503
} )
1484
1504
} )
1485
1505
@@ -1660,6 +1680,75 @@ describe('server', () => {
1660
1680
expect ( somevarInsideSomefunc ) . toStrictEqual ( s )
1661
1681
}
1662
1682
} )
1683
+
1684
+ it ( 'returns correct WorkspaceEdits for variables within read commands' , async ( ) => {
1685
+ const [ readvar , ...readvars ] = await getRenameRequestResults (
1686
+ [ 2 , 8 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1687
+ [ 2 , 19 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1688
+ [ 2 , 21 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1689
+ [ 3 , 10 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1690
+ [ 3 , 19 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1691
+ [ 6 , 14 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1692
+ [ 7 , 15 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1693
+ [ 8 , 32 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1694
+ [ 9 , 7 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1695
+ [ 11 , 23 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1696
+ [ 12 , 30 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1697
+ [ 13 , 10 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1698
+ [ 15 , 10 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1699
+ [ 15 , 31 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1700
+ [ 16 , 11 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1701
+ [ 16 , 30 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1702
+ [ 17 , 23 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1703
+ [ 17 , 33 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1704
+ )
1705
+ expect ( readvar ) . toMatchSnapshot ( )
1706
+ for ( const r of readvars ) {
1707
+ expect ( readvar ) . toStrictEqual ( r )
1708
+ }
1709
+
1710
+ const [ readloop , ...readloops ] = await getRenameRequestResults (
1711
+ [ 21 , 21 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1712
+ [ 23 , 12 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1713
+ )
1714
+ expect ( readloop ) . toMatchSnapshot ( )
1715
+ for ( const r of readloops ) {
1716
+ expect ( readloop ) . toStrictEqual ( r )
1717
+ }
1718
+
1719
+ const [ readscope , ...readscopes ] = await getRenameRequestResults (
1720
+ [ 28 , 8 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1721
+ [ 30 , 11 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1722
+ [ 31 , 12 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1723
+ [ 38 , 15 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1724
+ [ 43 , 9 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1725
+ )
1726
+ expect ( readscope ) . toMatchSnapshot ( )
1727
+ for ( const r of readscopes ) {
1728
+ expect ( readscope ) . toStrictEqual ( r )
1729
+ }
1730
+
1731
+ const [ readscopeInsideFunction , ...readscopesInsideFunction ] =
1732
+ await getRenameRequestResults (
1733
+ [ 33 , 11 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1734
+ [ 34 , 14 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1735
+ [ 35 , 8 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1736
+ )
1737
+ expect ( readscopeInsideFunction ) . toMatchSnapshot ( )
1738
+ for ( const r of readscopesInsideFunction ) {
1739
+ expect ( readscopeInsideFunction ) . toStrictEqual ( r )
1740
+ }
1741
+
1742
+ const [ readscopeInsideSubshell , ...readscopesInsideSubshell ] =
1743
+ await getRenameRequestResults (
1744
+ [ 40 , 14 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1745
+ [ 41 , 10 , { uri : FIXTURE_URI . RENAMING_READ } ] ,
1746
+ )
1747
+ expect ( readscopeInsideSubshell ) . toMatchSnapshot ( )
1748
+ for ( const r of readscopesInsideSubshell ) {
1749
+ expect ( readscopeInsideSubshell ) . toStrictEqual ( r )
1750
+ }
1751
+ } )
1663
1752
} )
1664
1753
1665
1754
describe ( 'Workspace-wide rename' , ( ) => {
@@ -1741,47 +1830,43 @@ describe('server', () => {
1741
1830
// These may fail in the future when tree-sitter-bash's parsing gets better
1742
1831
// or when the rename symbol implementation is improved.
1743
1832
describe ( 'Edge or not covered cases' , ( ) => {
1744
- it ( 'only includes variables typed as variable_name ' , async ( ) => {
1833
+ it ( 'does not include some variables typed as word ' , async ( ) => {
1745
1834
const iRanges = await getFirstChangeRanges ( getRenameRequestResult ( 106 , 4 ) )
1746
1835
// This should be 6 if all instances within let, postfix, and binary
1747
1836
// expressions are included.
1748
1837
expect ( iRanges . length ) . toBe ( 3 )
1749
-
1750
- const lineRanges = await getFirstChangeRanges ( getRenameRequestResult ( 118 , 10 ) )
1751
- // This should be 2 if the declaration of `line` is included.
1752
- expect ( lineRanges . length ) . toBe ( 1 )
1753
1838
} )
1754
1839
1755
1840
it ( 'includes incorrect number of symbols for complex scopes and nesting' , async ( ) => {
1756
- const varRanges = await getFirstChangeRanges ( getRenameRequestResult ( 124 , 8 ) )
1841
+ const varRanges = await getFirstChangeRanges ( getRenameRequestResult ( 118 , 8 ) )
1757
1842
// This should only be 2 if `$var` from `3` is not included.
1758
1843
expect ( varRanges . length ) . toBe ( 3 )
1759
1844
1760
- const localFuncRanges = await getFirstChangeRanges ( getRenameRequestResult ( 144 , 5 ) )
1845
+ const localFuncRanges = await getFirstChangeRanges ( getRenameRequestResult ( 138 , 5 ) )
1761
1846
// This should be 2 if the instance of `localFunc` in `callerFunc` is
1762
1847
// also included.
1763
1848
expect ( localFuncRanges . length ) . toBe ( 1 )
1764
1849
} )
1765
1850
1766
1851
it ( 'only takes into account subshells created with ( and )' , async ( ) => {
1767
1852
const pipelinevarRanges = await getFirstChangeRanges (
1768
- getRenameRequestResult ( 150 , 7 ) ,
1853
+ getRenameRequestResult ( 144 , 7 ) ,
1769
1854
)
1770
1855
// This should only be 1 if pipeline subshell scoping is recognized.
1771
1856
expect ( pipelinevarRanges . length ) . toBe ( 2 )
1772
1857
} )
1773
1858
1774
1859
it ( 'does not take into account sourcing location and scope' , async ( ) => {
1775
- const FOOUris = await getChangeUris ( getRenameRequestResult ( 154 , 8 ) )
1860
+ const FOOUris = await getChangeUris ( getRenameRequestResult ( 148 , 8 ) )
1776
1861
// This should only be 1 if sourcing after a symbol does not affect it.
1777
1862
expect ( FOOUris . length ) . toBe ( 2 )
1778
1863
1779
- const hello_worldUris = await getChangeUris ( getRenameRequestResult ( 160 , 6 ) )
1864
+ const hello_worldUris = await getChangeUris ( getRenameRequestResult ( 154 , 6 ) )
1780
1865
// This should only be 1 if sourcing inside an uncalled function does
1781
1866
// not affect symbols outside of it.
1782
1867
expect ( hello_worldUris . length ) . toBe ( 2 )
1783
1868
1784
- const PATH_INPUTUris = await getChangeUris ( getRenameRequestResult ( 163 , 9 ) )
1869
+ const PATH_INPUTUris = await getChangeUris ( getRenameRequestResult ( 157 , 9 ) )
1785
1870
// This should only be 1 if sourcing inside a subshell does not affect
1786
1871
// symbols outside of it.
1787
1872
expect ( PATH_INPUTUris . length ) . toBe ( 2 )
0 commit comments