From c0544d121bbc48626970542741510229b462289c Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 13 Feb 2021 16:41:01 +0100 Subject: [PATCH] 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 https://github.com/rescript-lang/rescript-editor-support/issues/63 --- Changes.md | 1 + src/rescript-editor-support/References.re | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Changes.md b/Changes.md index dd064637..d4f38838 100644 --- a/Changes.md +++ b/Changes.md @@ -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). diff --git a/src/rescript-editor-support/References.re b/src/rescript-editor-support/References.re index 8322ab29..7e5019e5 100644 --- a/src/rescript-editor-support/References.re +++ b/src/rescript-editor-support/References.re @@ -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