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

Commit 0d50f29

Browse files
committed
Fix type hint when hovering over labeled arguments of components.
This is a combination of `@react.component` PPX and compiler internals. The PPX produces an object for the props, and the compiler generates a call to `Js_OO.unsafe_downgrade`. The end result is that `~x` turns into `Js_OO.unsafe_downgrade(Props)#x`, which produces becomes 3 distinct values that appear to be at exactly the same source location: `Props`, `unsafe_downgrade`, and `x`. Fixes #63
1 parent 68e8b18 commit 0d50f29

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Add support for autocomplete for `foo->`: the type of `foo` is used to determine the module to take completions from.
33
- Add support for autocomplete for decorators such as `@module` and `@val`.
44
- Fix issue for uncurried functions where the internal definition of `Js.Fn.arity` is shown on hover. (See https://github.com/rescript-lang/rescript-editor-support/issues/62).
5+
- Fix type hint when hovering over labeled arguments of components (See https://github.com/rescript-lang/rescript-editor-support/issues/63).
56

67
## Release 1.0.5 of rescript-vscode
78
This [commit](https://github.com/rescript-lang/rescript-editor-support/commit/6bdd10f6af259edc5f9cbe5b9df06836de3ab865) is vendored in [rescript-vscode 1.0.5](https://github.com/rescript-lang/rescript-vscode/releases/tag/1.0.5).

src/rescript-editor-support/References.re

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ let locsForPos = (~extra, pos) => {
2929

3030
let locForPos = (~extra, pos) => {
3131
switch (locsForPos(~extra, pos)) {
32+
| [
33+
(loc1, Typed(_, LocalReference(_))),
34+
(
35+
loc2,
36+
Typed(_, GlobalReference("Js_OO", Tip("unsafe_downgrade"), _)),
37+
),
38+
(loc3, _) as l3,
39+
]
40+
when loc1 == loc2 && loc2 == loc3 =>
41+
// JSX and compiler combined:
42+
// ~x becomes Js_OO.unsafe_downgrade(Props)#x
43+
// heuristic for: [Props, unsafe_downgrade, x], give loc of `x`
44+
Some(l3)
3245
| [(loc1, _), (loc2, _) as l, (loc3, _)]
3346
when loc1 == loc2 && loc2 == loc3 =>
3447
// JSX with at most one child

0 commit comments

Comments
 (0)