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

Commit

Permalink
Fix type hint when hovering over labeled arguments of components.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cristianoc committed Feb 15, 2021
1 parent e103940 commit c0544d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Add support for autocomplete for `foo->`: the type of `foo` is used to determine the module to take completions from.
- Add support for autocomplete for decorators such as `@module` and `@val`.
- 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).
- Fix type hint when hovering over labeled arguments of components (See https://github.com/rescript-lang/rescript-editor-support/issues/63).

## Release 1.0.5 of rescript-vscode
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).
Expand Down
13 changes: 13 additions & 0 deletions src/rescript-editor-support/References.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ let locsForPos = (~extra, pos) => {

let locForPos = (~extra, pos) => {
switch (locsForPos(~extra, pos)) {
| [
(loc1, Typed(_, LocalReference(_))),
(
loc2,
Typed(_, GlobalReference("Js_OO", Tip("unsafe_downgrade"), _)),
),
(loc3, _) as l3,
]
when loc1 == loc2 && loc2 == loc3 =>
// JSX and compiler combined:
// ~x becomes Js_OO.unsafe_downgrade(Props)#x
// heuristic for: [Props, unsafe_downgrade, x], give loc of `x`
Some(l3)
| [(loc1, _), (loc2, _) as l, (loc3, _)]
when loc1 == loc2 && loc2 == loc3 =>
// JSX with at most one child
Expand Down

0 comments on commit c0544d1

Please sign in to comment.