Skip to content

Commit ddacfab

Browse files
committed
Downstream: Fixes for renaming(ocaml/merlin#1924)
1 parent 7ed0db8 commit ddacfab

File tree

10 files changed

+135
-12
lines changed

10 files changed

+135
-12
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ unreleased
99
- Perform less merges in the indexer (#1881)
1010
- Add initial support for project-wide renaming: occurrences can now return
1111
all usages of all related definitions. (#1877)
12+
- Fix issues with ident validation and Lid comparison for occurrences (#1924)
1213
+ ocaml-index
1314
- Bump magic number after index file format change. Index can now be read lazilly (#1886)
1415

src/analysis/locate.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ let rec uid_of_result ~traverse_aliases = function
922922
| Approximated _ | Unresolved _ | Internal_error_missing_uid -> (None, true)
923923

924924
(** This is the main function here *)
925-
let from_path ~config ~env ~local_defs ~decl path =
925+
let from_path ~config ~env ~local_defs ~decl ?ident:_ path =
926926
let title = "from_path" in
927927
let unalias (decl : Env_lookup.item) =
928928
if not config.traverse_aliases then (path, decl.uid)
@@ -969,9 +969,12 @@ let from_path ~config ~env ~local_defs ~decl path =
969969
in
970970
(* Step 2: Uid => Location *)
971971
let loc =
972+
let ident =
973+
(* TODO it might not be useful to check the ident without impl_uid *)
974+
Path.last path
975+
in
972976
match impl_uid with
973977
| Some impl_uid ->
974-
let ident = Path.last path in
975978
find_loc_of_uid ~config ~local_defs ~ident ~fallback:uid impl_uid
976979
| None -> find_loc_of_uid ~config ~local_defs uid
977980
in
@@ -1009,7 +1012,9 @@ let from_longident ~config ~env ~local_defs nss ident =
10091012
in
10101013
match Env_lookup.by_longident nss ident env with
10111014
| None -> `Not_in_env str_ident
1012-
| Some (path, decl) -> from_path ~config ~env ~local_defs ~decl path
1015+
| Some (path, decl) ->
1016+
let ident = Longident.last ident in
1017+
from_path ~config ~env ~local_defs ~decl ~ident path
10131018

10141019
let from_path ~config ~env ~local_defs ~namespace path =
10151020
File_switching.reset ();

src/index-format/lid.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ let pp fmt t =
3939

4040
let compare_pos p1 p2 = Int.compare p1.cnum p2.cnum
4141
let compare_filename t1 t2 =
42-
String.compare
43-
(Filename.basename (G.fetch t1.filename))
44-
(Filename.basename (G.fetch t2.filename))
42+
String.compare (G.fetch t1.filename) (G.fetch t2.filename)
4543

4644
let compare t1 t2 =
4745
match compare_filename t1 t2 with

tests/test-dirs/occurrences/project-wide/for-renaming/r-modules-and-types.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@
5252
"col": 7
5353
}
5454
},
55+
{
56+
"file": "$TESTCASE_ROOT/main.ml",
57+
"start": {
58+
"line": 5,
59+
"col": 25
60+
},
61+
"end": {
62+
"line": 5,
63+
"col": 26
64+
},
65+
"stale": false
66+
},
5567
{
5668
"file": "$TESTCASE_ROOT/lib.ml",
5769
"start": {

tests/test-dirs/occurrences/project-wide/for-renaming/r-with-functors.t/run.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ We expect 2 occurrences in func.ml, 1 in func.mli and 2 in main.ml
1212
"line": 1,
1313
"col": 22
1414
}
15+
"$TESTCASE_ROOT/main.ml"
16+
{
17+
"line": 4,
18+
"col": 16
19+
}
1520
"$TESTCASE_ROOT/func.ml"
1621
{
1722
"line": 1,
@@ -27,8 +32,3 @@ We expect 2 occurrences in func.ml, 1 in func.mli and 2 in main.ml
2732
"line": 1,
2833
"col": 24
2934
}
30-
"$TESTCASE_ROOT/main.ml"
31-
{
32-
"line": 4,
33-
"col": 16
34-
}

tests/test-dirs/occurrences/project-wide/mli-vs-ml.t

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ the interface and the implementation.
4646
"col": 6
4747
}
4848
},
49+
{
50+
"file": "$TESTCASE_ROOT/main.mli",
51+
"start": {
52+
"line": 2,
53+
"col": 8
54+
},
55+
"end": {
56+
"line": 2,
57+
"col": 9
58+
},
59+
"stale": false
60+
},
4961
{
5062
"file": "$TESTCASE_ROOT/main.ml",
5163
"start": {
@@ -101,6 +113,18 @@ Same when the cursor is at the origin:
101113
"col": 6
102114
}
103115
},
116+
{
117+
"file": "$TESTCASE_ROOT/main.mli",
118+
"start": {
119+
"line": 2,
120+
"col": 8
121+
},
122+
"end": {
123+
"line": 2,
124+
"col": 9
125+
},
126+
"stale": false
127+
},
104128
{
105129
"file": "$TESTCASE_ROOT/main.ml",
106130
"start": {

tests/test-dirs/occurrences/project-wide/prefix.t/run.t

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ Merlin successfully finds occurrences outside file when UNIT_NAME directive is u
9595
"col": 5
9696
}
9797
},
98+
{
99+
"file": "$TESTCASE_ROOT/b.ml",
100+
"start": {
101+
"line": 2,
102+
"col": 8
103+
},
104+
"end": {
105+
"line": 2,
106+
"col": 9
107+
},
108+
"stale": false
109+
},
98110
{
99111
"file": "$TESTCASE_ROOT/a.ml",
100112
"start": {
@@ -154,6 +166,18 @@ Merlin successfully finds occurrences outside file when WRAPPING_PREFIX directiv
154166
"col": 5
155167
}
156168
},
169+
{
170+
"file": "$TESTCASE_ROOT/b.ml",
171+
"start": {
172+
"line": 2,
173+
"col": 8
174+
},
175+
"end": {
176+
"line": 2,
177+
"col": 9
178+
},
179+
"stale": false
180+
},
157181
{
158182
"file": "$TESTCASE_ROOT/a.ml",
159183
"start": {

tests/test-dirs/occurrences/project-wide/pwo-basic.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
{
2929
"class": "return",
3030
"value": [
31+
{
32+
"file": "$TESTCASE_ROOT/main.ml",
33+
"start": {
34+
"line": 1,
35+
"col": 26
36+
},
37+
"end": {
38+
"line": 1,
39+
"col": 29
40+
},
41+
"stale": false
42+
},
3143
{
3244
"file": "$TESTCASE_ROOT/lib.ml",
3345
"start": {

tests/test-dirs/occurrences/project-wide/pwo-ml-gen.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ We should not index generated modules (lib.ml-gen)
5757

5858
$ $MERLIN single occurrences -scope project -identifier-at 3:23 \
5959
> -filename main.ml <main.ml | jq '.value[].file'
60+
"$TESTCASE_ROOT/main.ml"
6061
"$TESTCASE_ROOT/lib/aux.ml"
6162
"$TESTCASE_ROOT/lib/aux.ml"
62-
"$TESTCASE_ROOT/main.ml"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
$ cat >lib.ml <<'EOF'
2+
> (* blah *)
3+
> let foo = "bar"
4+
> EOF
5+
6+
$ cat >main.ml <<'EOF'
7+
> let () = print_string Lib.foo
8+
> EOF
9+
10+
$ $OCAMLC -bin-annot -bin-annot-occurrences -c lib.ml main.ml
11+
12+
$ ocaml-index aggregate main.cmt lib.cmt
13+
14+
Foo was defined on line 2 when the index was built, but is now defined on line 1
15+
$ cat >lib.ml <<'EOF'
16+
> let foo = "bar"
17+
> EOF
18+
19+
$ $MERLIN single occurrences -scope project -identifier-at 1:28 \
20+
> -index-file project.ocaml-index \
21+
> -filename main.ml < main.ml | jq .value
22+
[
23+
{
24+
"file": "$TESTCASE_ROOT/main.ml",
25+
"start": {
26+
"line": 1,
27+
"col": 26
28+
},
29+
"end": {
30+
"line": 1,
31+
"col": 29
32+
},
33+
"stale": false
34+
},
35+
{
36+
"file": "$TESTCASE_ROOT/lib.ml",
37+
"start": {
38+
"line": 2,
39+
"col": 4
40+
},
41+
"end": {
42+
"line": 2,
43+
"col": 7
44+
},
45+
"stale": true
46+
}
47+
]

0 commit comments

Comments
 (0)