Skip to content

Commit 9ba0225

Browse files
committed
Print names of locitem's in heuristics.
1 parent e455cda commit 9ba0225

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

analysis/src/References.ml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ let getLocItem ~full ~pos ~debug =
2727
print_endline
2828
("locItems:\n "
2929
^ (locItems |> List.map locItemToString |> String.concat "\n "));
30+
let nameOf li =
31+
match li.locType with Typed (n, _, _) -> n | _ -> "NotFound"
32+
in
3033
match locItems with
31-
| _ :: _ :: _ :: ({locType = Typed ("makeProps", _, _)} as li) :: _
34+
| li1 :: li2 :: li3 :: ({locType = Typed ("makeProps", _, _)} as li4) :: _
3235
when full.file.uri |> Uri2.isInterface ->
3336
log 1 "heuristic for makeProps in interface files";
34-
Some li
37+
if debug then
38+
Printf.printf "n1:%s n2:%s n3:%s\n" (nameOf li1) (nameOf li2) (nameOf li3);
39+
Some li4
3540
| [
3641
{locType = Typed ("fragment", _, _)};
3742
{locType = Typed ("createElement", _, _)};
@@ -51,13 +56,17 @@ let getLocItem ~full ~pos ~debug =
5156
work\n\
5257
the type is not great but jump to definition works";
5358
Some li2
54-
| [({locType = Typed (_, _, LocalReference _)} as li1); li3]
55-
when li1.loc = li3.loc ->
59+
| [
60+
({locType = Typed (_, _, LocalReference _)} as li1);
61+
({locType = Typed (_, _, _)} as li2);
62+
]
63+
when li1.loc = li2.loc ->
5664
log 5
5765
"heuristic for JSX and compiler combined:\n\
5866
~x becomes Props#x\n\
5967
heuristic for: [Props, x], give loc of `x`";
60-
Some li3
68+
if debug then Printf.printf "n1:%s n2:%s\n" (nameOf li1) (nameOf li2);
69+
Some li2
6170
| [
6271
({locType = Typed (_, _, LocalReference _)} as li1);
6372
({locType = Typed (_, _, GlobalReference ("Js_OO", ["unsafe_downgrade"], _))}
@@ -73,7 +82,7 @@ let getLocItem ~full ~pos ~debug =
7382
heuristic for: [Props, unsafe_downgrade, x], give loc of `x`";
7483
Some li3
7584
| [
76-
{locType = Typed (_, _, LocalReference (_, Value))};
85+
({locType = Typed (_, _, LocalReference (_, Value))} as li1);
7786
({locType = Typed (_, _, Definition (_, Value))} as li2);
7887
] ->
7988
log 7
@@ -82,6 +91,7 @@ let getLocItem ~full ~pos ~debug =
8291
Props has the location range of arg:t\n\
8392
arg has the location range of arg\n\
8493
heuristic for: [Props, arg], give loc of `arg`";
94+
if debug then Printf.printf "n1:%s n2:%s\n" (nameOf li1) (nameOf li2);
8595
Some li2
8696
| [li1; li2; li3] when li1.loc = li2.loc && li2.loc = li3.loc ->
8797
(* Not currently testable on 9.1.4 *)
@@ -93,8 +103,11 @@ let getLocItem ~full ~pos ~debug =
93103
when li1.loc = li2.loc && li2.loc = li3.loc && li3.loc = li4.loc ->
94104
log 9
95105
"heuristic for JSX variadic, e.g. <C> {x} {y} </C>\n\
96-
heuristic for: [makeProps , React.null, make, createElementVariadic], \
106+
heuristic for: [React.null, makeProps, make, createElementVariadic], \
97107
give the loc of `make`";
108+
if debug then
109+
Printf.printf "n1:%s n2:%s n3:%s n4:%s\n" (nameOf li1) (nameOf li2)
110+
(nameOf li3) (nameOf li4);
98111
Some li3
99112
| {locType = Typed (_, {desc = Tconstr (path, _, _)}, _)} :: li :: _
100113
when Utils.isUncurriedInternal path ->

analysis/tests/src/expected/Hover.res.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Hover src/Hover.res 37:13
2323
getLocItem #5: heuristic for JSX and compiler combined:
2424
~x becomes Props#x
2525
heuristic for: [Props, x], give loc of `x`
26+
n1:Props n2:name
2627
{"contents": "```rescript\nstring\n```"}
2728

2829
Hover src/Hover.res 41:13
@@ -31,6 +32,7 @@ getLocItem #7: heuristic for JSX on type-annotated labeled (~arg:t):
3132
Props has the location range of arg:t
3233
arg has the location range of arg
3334
heuristic for: [Props, arg], give loc of `arg`
35+
n1:Props n2:name
3436
{"contents": "```rescript\nstring\n```"}
3537

3638
Hover src/Hover.res 44:10
@@ -56,12 +58,14 @@ Hover src/Hover.res 75:7
5658

5759
Hover src/Hover.res 85:10
5860
getLocItem #9: heuristic for JSX variadic, e.g. <C> {x} {y} </C>
59-
heuristic for: [makeProps , React.null, make, createElementVariadic], give the loc of `make`
61+
heuristic for: [React.null, makeProps, make, createElementVariadic], give the loc of `make`
62+
n1:null n2:makeProps n3:make n4:createElementVariadic
6063
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n```rescript\ntype component<'props> = componentLike<'props, element>\n```"}
6164

6265
Hover src/Hover.res 88:10
6366
getLocItem #9: heuristic for JSX variadic, e.g. <C> {x} {y} </C>
64-
heuristic for: [makeProps , React.null, make, createElementVariadic], give the loc of `make`
67+
heuristic for: [React.null, makeProps, make, createElementVariadic], give the loc of `make`
68+
n1:null n2:makeProps n3:make n4:createElementVariadic
6569
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n```rescript\ntype component<'props> = componentLike<'props, element>\n```"}
6670

6771
Hover src/Hover.res 93:25

analysis/tests/src/expected/Jsx.resi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Hover src/Jsx.resi 1:4
22
getLocItem #1: heuristic for makeProps in interface files
3+
n1:componentLike n2:unit n3:string
34
{"contents": "```rescript\n(~first: string, ~key: string=?, unit) => {\"first\": string}\n```"}
45

56
Hover src/Jsx.resi 4:4

0 commit comments

Comments
 (0)