Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 806fd4c

Browse files
committed
Add heuristic for JSX with more than one child.
Fixes #18 Variadic JSX such as `<C> {x} {y} </C>` triggers the definition of 4 values at the same location. Only one of them is the desired one for hover and jump to definition.
1 parent 9c0a0b7 commit 806fd4c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

examples/example-project/src/ZZ.res

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
2-
31
let a = 12
42

53
let b = [1, 2, 3, a]
64

7-
85
let c = <div />
96

107
let s = React.string
118

12-
// module M = {
13-
// @react.component
14-
// let make = (~x) => React.string(x)
15-
// }
9+
module M = {
10+
@react.component
11+
let make = (~x) => React.string(x)
12+
}
13+
14+
let d = <M x="abc" />
1615

16+
module J = {
17+
@react.component
18+
export make = (~children: React.element) => React.null
19+
}
1720

18-
// let d = <M x="abc" />
21+
let z = <J> {React.string("")} {React.string("")} </J>

src/rescript-editor-support/References.re

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ let locForPos = (~extra, pos) => {
3131
switch (locsForPos(~extra, pos)) {
3232
| [(loc1, _), (loc2, _) as l, (loc3, _)]
3333
when loc1 == loc2 && loc2 == loc3 =>
34-
// heuristic for: [makeProps, make, createElements], give the loc of `make`
34+
// JSX with at most one child
35+
// heuristic for: [makeProps, make, createElement], give the loc of `make`
36+
Some(l)
37+
| [(loc1, _), (loc2, _), (loc3, _) as l, (loc4, _)]
38+
when loc1 == loc2 && loc2 == loc3 && loc3 == loc4 =>
39+
// JSX variadic, e.g. <C> {x} {y} </C>
40+
// heuristic for: [makeProps, React.null, make, createElementVariadic], give the loc of `make`
3541
Some(l)
3642
| [l, ..._] => Some(l)
3743
| _ => None

0 commit comments

Comments
 (0)