Skip to content

Commit fb56a80

Browse files
rubmarymeta-codesync[bot]
authored andcommitted
Improve xrefs for string literals
Summary: Using pyrefly function `find_definition_for_name_use` instead of building the name based on the string and imports only. This also allows us to get the corresponding file of the definition when pyrefly actually returns a definition. The difference in the regression tests is because the quotes are not being included anymore in the range Reviewed By: donsbot Differential Revision: D92515073 fbshipit-source-id: bd0c5387566bdbf8109eab2f141a190c1d18d732
1 parent 262be56 commit fb56a80

5 files changed

Lines changed: 90 additions & 82 deletions

File tree

glean/glass/test/regression/tests/python-pyrefly/documentSymbolIndex.out

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,8 @@
11101110
}
11111111
},
11121112
"range": {
1113-
"columnBegin": 12,
1114-
"columnEnd": 20,
1113+
"columnBegin": 13,
1114+
"columnEnd": 19,
11151115
"lineBegin": 34,
11161116
"lineEnd": 34
11171117
},
@@ -1143,8 +1143,8 @@
11431143
}
11441144
},
11451145
"range": {
1146-
"columnBegin": 61,
1147-
"columnEnd": 69,
1146+
"columnBegin": 62,
1147+
"columnEnd": 68,
11481148
"lineBegin": 34,
11491149
"lineEnd": 34
11501150
},
@@ -1179,8 +1179,8 @@
11791179
}
11801180
},
11811181
"range": {
1182-
"columnBegin": 34,
1183-
"columnEnd": 46,
1182+
"columnBegin": 35,
1183+
"columnEnd": 45,
11841184
"lineBegin": 34,
11851185
"lineEnd": 34
11861186
},
@@ -1238,8 +1238,8 @@
12381238
}
12391239
},
12401240
"range": {
1241-
"columnBegin": 22,
1242-
"columnEnd": 32,
1241+
"columnBegin": 23,
1242+
"columnEnd": 31,
12431243
"lineBegin": 34,
12441244
"lineEnd": 34
12451245
},
@@ -1271,8 +1271,8 @@
12711271
}
12721272
},
12731273
"range": {
1274-
"columnBegin": 71,
1275-
"columnEnd": 80,
1274+
"columnBegin": 72,
1275+
"columnEnd": 79,
12761276
"lineBegin": 34,
12771277
"lineEnd": 34
12781278
},
@@ -1307,8 +1307,8 @@
13071307
}
13081308
},
13091309
"range": {
1310-
"columnBegin": 48,
1311-
"columnEnd": 52,
1310+
"columnBegin": 49,
1311+
"columnEnd": 51,
13121312
"lineBegin": 34,
13131313
"lineEnd": 34
13141314
},
@@ -1343,8 +1343,8 @@
13431343
}
13441344
},
13451345
"range": {
1346-
"columnBegin": 54,
1347-
"columnEnd": 59,
1346+
"columnBegin": 55,
1347+
"columnEnd": 58,
13481348
"lineBegin": 34,
13491349
"lineEnd": 34
13501350
},
@@ -1379,8 +1379,8 @@
13791379
}
13801380
},
13811381
"range": {
1382-
"columnBegin": 22,
1383-
"columnEnd": 32,
1382+
"columnBegin": 23,
1383+
"columnEnd": 31,
13841384
"lineBegin": 34,
13851385
"lineEnd": 34
13861386
},
@@ -1415,8 +1415,8 @@
14151415
}
14161416
},
14171417
"range": {
1418-
"columnBegin": 71,
1419-
"columnEnd": 80,
1418+
"columnBegin": 72,
1419+
"columnEnd": 79,
14201420
"lineBegin": 34,
14211421
"lineEnd": 34
14221422
},
@@ -1451,8 +1451,8 @@
14511451
}
14521452
},
14531453
"range": {
1454-
"columnBegin": 12,
1455-
"columnEnd": 20,
1454+
"columnBegin": 13,
1455+
"columnEnd": 19,
14561456
"lineBegin": 34,
14571457
"lineEnd": 34
14581458
},
@@ -1487,8 +1487,8 @@
14871487
}
14881488
},
14891489
"range": {
1490-
"columnBegin": 61,
1491-
"columnEnd": 69,
1490+
"columnBegin": 62,
1491+
"columnEnd": 68,
14921492
"lineBegin": 34,
14931493
"lineEnd": 34
14941494
},

glean/glass/test/regression/tests/python-pyrefly/documentSymbolListX.out

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,8 @@
775775
}
776776
],
777777
"range": {
778-
"columnBegin": 12,
779-
"columnEnd": 20,
778+
"columnBegin": 13,
779+
"columnEnd": 19,
780780
"lineBegin": 34,
781781
"lineEnd": 34
782782
},
@@ -820,8 +820,8 @@
820820
}
821821
],
822822
"range": {
823-
"columnBegin": 61,
824-
"columnEnd": 69,
823+
"columnBegin": 62,
824+
"columnEnd": 68,
825825
"lineBegin": 34,
826826
"lineEnd": 34
827827
},
@@ -949,8 +949,8 @@
949949
}
950950
],
951951
"range": {
952-
"columnBegin": 34,
953-
"columnEnd": 46,
952+
"columnBegin": 35,
953+
"columnEnd": 45,
954954
"lineBegin": 34,
955955
"lineEnd": 34
956956
},
@@ -994,8 +994,8 @@
994994
}
995995
],
996996
"range": {
997-
"columnBegin": 22,
998-
"columnEnd": 32,
997+
"columnBegin": 23,
998+
"columnEnd": 31,
999999
"lineBegin": 34,
10001000
"lineEnd": 34
10011001
},
@@ -1084,8 +1084,8 @@
10841084
}
10851085
],
10861086
"range": {
1087-
"columnBegin": 71,
1088-
"columnEnd": 80,
1087+
"columnBegin": 72,
1088+
"columnEnd": 79,
10891089
"lineBegin": 34,
10901090
"lineEnd": 34
10911091
},
@@ -1186,8 +1186,8 @@
11861186
}
11871187
],
11881188
"range": {
1189-
"columnBegin": 48,
1190-
"columnEnd": 52,
1189+
"columnBegin": 49,
1190+
"columnEnd": 51,
11911191
"lineBegin": 34,
11921192
"lineEnd": 34
11931193
},
@@ -1411,8 +1411,8 @@
14111411
}
14121412
],
14131413
"range": {
1414-
"columnBegin": 54,
1415-
"columnEnd": 59,
1414+
"columnBegin": 55,
1415+
"columnEnd": 58,
14161416
"lineBegin": 34,
14171417
"lineEnd": 34
14181418
},
@@ -1615,8 +1615,8 @@
16151615
}
16161616
],
16171617
"range": {
1618-
"columnBegin": 22,
1619-
"columnEnd": 32,
1618+
"columnBegin": 23,
1619+
"columnEnd": 31,
16201620
"lineBegin": 34,
16211621
"lineEnd": 34
16221622
},
@@ -1768,8 +1768,8 @@
17681768
}
17691769
],
17701770
"range": {
1771-
"columnBegin": 71,
1772-
"columnEnd": 80,
1771+
"columnBegin": 72,
1772+
"columnEnd": 79,
17731773
"lineBegin": 34,
17741774
"lineEnd": 34
17751775
},
@@ -2125,8 +2125,8 @@
21252125
}
21262126
],
21272127
"range": {
2128-
"columnBegin": 12,
2129-
"columnEnd": 20,
2128+
"columnBegin": 13,
2129+
"columnEnd": 19,
21302130
"lineBegin": 34,
21312131
"lineEnd": 34
21322132
},
@@ -2176,8 +2176,8 @@
21762176
}
21772177
],
21782178
"range": {
2179-
"columnBegin": 61,
2180-
"columnEnd": 69,
2179+
"columnBegin": 62,
2180+
"columnEnd": 68,
21812181
"lineBegin": 34,
21822182
"lineEnd": 34
21832183
},

glean/glass/test/regression/tests/python-pyrefly/findReferenceRanges_big_lib_func.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
{
1515
"filepath": "glean/lang/python-pyrefly/tests/regression/without_dynamic_import/core/xrefs/all.py",
1616
"range": {
17-
"columnBegin": 22,
18-
"columnEnd": 32,
17+
"columnBegin": 23,
18+
"columnEnd": 31,
1919
"lineBegin": 34,
2020
"lineEnd": 34
2121
},

glean/lang/python-pyrefly/tests/regression/pyrefly_specific/xrefs_via_name_by_file.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@
650650
"key": "glean/lang/python-pyrefly/tests/regression/pyrefly_specific/generic.py"
651651
},
652652
"xrefs": [
653+
{
654+
"source": { "length": 1, "start": 265 },
655+
"target": { "key": "generic.T" }
656+
},
653657
{
654658
"source": { "length": 1, "start": 285 },
655659
"target": { "key": "generic.G" }
@@ -695,6 +699,10 @@
695699
"key": "glean/lang/python-pyrefly/tests/regression/pyrefly_specific/optional_generic.py"
696700
},
697701
"xrefs": [
702+
{
703+
"source": { "length": 1, "start": 265 },
704+
"target": { "key": "optional_generic.T" }
705+
},
698706
{
699707
"source": { "length": 1, "start": 293 },
700708
"target": { "key": "optional_generic.G" }

0 commit comments

Comments
 (0)