diff --git a/CHANGELOG.md b/CHANGELOG.md
index 092274153..926ec5c52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@
- Fix issue where `-open Some.Path` in `"bsc-flags"` would sometimes be treated differently from `open Some.Path` locally in a file https://github.com/rescript-lang/rescript-vscode/pull/616
+- Fix issue where doc comment is not shown on hover in case of shadowed identifier (in particular for JSX V4 components which shadow `make`) https://github.com/rescript-lang/rescript-vscode/issues/621
+
## v1.8.2
#### :rocket: New Feature
diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml
index fd53e58df..b5f9e8fe2 100644
--- a/analysis/src/ProcessCmt.ml
+++ b/analysis/src/ProcessCmt.ml
@@ -10,18 +10,30 @@ let addDeclared ~(name : string Location.loc) ~extent ~stamp ~(env : Env.t)
addStamp env.stamps stamp declared;
declared
-let rec forTypeSignatureItem ~env ~(exported : Exported.t)
+let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
(item : Types.signature_item) =
match item with
| Sig_value (ident, {val_type; val_attributes; val_loc = loc}) ->
let item = val_type in
+ let stamp = Ident.binding_time ident in
+ let oldDeclared = Stamps.findValue env.stamps stamp in
let declared =
addDeclared
~name:(Location.mknoloc (Ident.name ident))
- ~extent:loc ~stamp:(Ident.binding_time ident) ~env ~item val_attributes
+ ~extent:loc ~stamp ~env ~item val_attributes
(Exported.add exported Exported.Value)
Stamps.addValue
in
+ let declared =
+ (* When an id is shadowed, a module constraint without the doc comment is created.
+ Here the existing doc comment is restored. See https://github.com/rescript-lang/rescript-vscode/issues/621 *)
+ match oldDeclared with
+ | Some oldDeclared when declared.docstring = [] ->
+ let newDeclared = {declared with docstring = oldDeclared.docstring} in
+ Stamps.addValue env.stamps stamp newDeclared;
+ newDeclared
+ | _ -> declared
+ in
[{Module.kind = Module.Value declared.item; name = declared.name.txt}]
| Sig_type
( ident,
diff --git a/analysis/tests/src/Hover.res b/analysis/tests/src/Hover.res
index 685eb1d35..51c31fec5 100644
--- a/analysis/tests/src/Hover.res
+++ b/analysis/tests/src/Hover.res
@@ -210,3 +210,26 @@ let usr: useR = {
// let f = usr
// ^hov
+
+
+module NotShadowed = {
+ /** Stuff */
+ let xx_ = 10
+
+ /** More Stuff */
+ let xx = xx_
+}
+
+module Shadowed = {
+ /** Stuff */
+ let xx = 10
+
+ /** More Stuff */
+ let xx = xx
+}
+
+let _ = NotShadowed.xx
+// ^hov
+
+let _ = Shadowed.xx
+// ^hov
diff --git a/analysis/tests/src/JsxV4.res b/analysis/tests/src/JsxV4.res
index 52e01c38b..d23b651ba 100644
--- a/analysis/tests/src/JsxV4.res
+++ b/analysis/tests/src/JsxV4.res
@@ -1,6 +1,7 @@
@@jsxConfig({version: 4})
module M4 = {
+ /** Doc Comment For M4 */
@react.component
let make = (~first, ~fun="", ~second="") => React.string(first ++ fun ++ second)
}
@@ -10,3 +11,6 @@ let _ =
//
+// ^hov
diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt
index 2b196dc7f..b46f0dfdb 100644
--- a/analysis/tests/src/expected/Hover.res.txt
+++ b/analysis/tests/src/expected/Hover.res.txt
@@ -171,3 +171,9 @@ Pexp_ident usr:[210:11->210:14]
Completable: Cpath Value[usr]
{"contents": "```rescript\nuseR\n```\n\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list