Skip to content

Commit 237b19a

Browse files
committed
Add more heuristics for JSX inside fragments.
Fixes #182.
1 parent 867f2cd commit 237b19a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

analysis/src/References.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ let locItemForPos ~full pos =
2727
| _ :: _ :: _ :: l :: _ when full.file.uri |> Uri2.isInterface ->
2828
(* heuristic for makeProps in interface files *)
2929
Some l
30+
| [
31+
{locType = Typed ("fragment", _, _)};
32+
{locType = Typed ("createElement", _, _)};
33+
] ->
34+
(* heuristic for </Comp> within a fragment *)
35+
None
36+
| {locType = Typed ("makeProps", _, _)}
37+
:: ({locType = Typed ("make", _, _)} as l2) :: _ ->
38+
(* heuristic for </Comp> within fragments: take make as makeProps does not work
39+
the type is not greatl but jump to definition works *)
40+
Some l2
3041
| [({locType = Typed (_, _, LocalReference _)} as li1); li3]
3142
when li1.loc = li3.loc ->
3243
(* JSX and compiler combined:

analysis/tests/src/Fragment.res

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module SectionHeader = {
2+
@react.component
3+
let make = (~children) => children
4+
}
5+
6+
7+
let z1 = <> <SectionHeader> {React.string("abc")} </SectionHeader> </>
8+
// ^hov
9+
10+
let z2 = <> <SectionHeader> {React.string("abc")} </SectionHeader> </>
11+
// ^hov
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Hover tests/src/Fragment.res 6:19
2+
{"contents": "```rescript\n{\"children\": 'children} => 'children\n```"}
3+
4+
Hover tests/src/Fragment.res 9:56
5+
null
6+

0 commit comments

Comments
 (0)