Skip to content

Commit 2b9d463

Browse files
committed
Restore doc comment when there is a shadowed identifier.
Fixes #621
1 parent 34a654e commit 2b9d463

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
- 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
1818

19+
- 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
20+
1921
## v1.8.2
2022

2123
#### :rocket: New Feature

analysis/src/ProcessCmt.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ let addDeclared ~(name : string Location.loc) ~extent ~stamp ~(env : Env.t)
1010
addStamp env.stamps stamp declared;
1111
declared
1212

13-
let rec forTypeSignatureItem ~env ~(exported : Exported.t)
13+
let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
1414
(item : Types.signature_item) =
1515
match item with
1616
| Sig_value (ident, {val_type; val_attributes; val_loc = loc}) ->
1717
let item = val_type in
18+
let stamp = Ident.binding_time ident in
19+
let oldDeclared = Stamps.findValue env.stamps stamp in
1820
let declared =
1921
addDeclared
2022
~name:(Location.mknoloc (Ident.name ident))
21-
~extent:loc ~stamp:(Ident.binding_time ident) ~env ~item val_attributes
23+
~extent:loc ~stamp ~env ~item val_attributes
2224
(Exported.add exported Exported.Value)
2325
Stamps.addValue
2426
in
27+
let declared =
28+
(* When an id is shadowed, a module constraing without the doc comment is created.
29+
Here the existing doc comment is restored. *)
30+
match oldDeclared with
31+
| Some oldDeclared when declared.docstring = [] ->
32+
let newDeclared = {declared with docstring = oldDeclared.docstring} in
33+
Stamps.addValue env.stamps stamp newDeclared;
34+
newDeclared
35+
| _ -> declared
36+
in
2537
[{Module.kind = Module.Value declared.item; name = declared.name.txt}]
2638
| Sig_type
2739
( ident,

analysis/tests/src/JsxV4.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@@jsxConfig({version: 4})
22

33
module M4 = {
4+
/** Doc Comment For M4 */
45
@react.component
56
let make = (~first, ~fun="", ~second="") => React.string(first ++ fun ++ second)
67
}
@@ -10,3 +11,6 @@ let _ = <M4 first="abc" />
1011

1112
// <M4 first="abc" f
1213
// ^com
14+
15+
let _ = <M4 first="abc" />
16+
// ^hov

analysis/tests/src/expected/Hover.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,5 @@ Hover src/Hover.res 230:20
175175
{"contents": "```rescript\nint\n```\n\n More Stuff "}
176176

177177
Hover src/Hover.res 233:17
178-
{"contents": "```rescript\nint\n```"}
178+
{"contents": "```rescript\nint\n```\n\n More Stuff "}
179179

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Definition src/JsxV4.res 7:9
2-
{"uri": "JsxV4.res", "range": {"start": {"line": 4, "character": 6}, "end": {"line": 4, "character": 10}}}
1+
Definition src/JsxV4.res 8:9
2+
{"uri": "JsxV4.res", "range": {"start": {"line": 5, "character": 6}, "end": {"line": 5, "character": 10}}}
33

4-
Complete src/JsxV4.res 10:20
5-
posCursor:[10:20] posNoWhite:[10:19] Found expr:[10:4->10:20]
6-
JSX <M4:[10:4->10:6] first[10:7->10:12]=...[10:13->10:18] f[10:19->10:20]=...[10:19->10:20]> _children:None
4+
Complete src/JsxV4.res 11:20
5+
posCursor:[11:20] posNoWhite:[11:19] Found expr:[11:4->11:20]
6+
JSX <M4:[11:4->11:6] first[11:7->11:12]=...[11:13->11:18] f[11:19->11:20]=...[11:19->11:20]> _children:None
77
Completable: Cjsx([M4], f, [first, f])
88
[{
99
"label": "fun",
@@ -13,3 +13,6 @@ Completable: Cjsx([M4], f, [first, f])
1313
"documentation": null
1414
}]
1515

16+
Hover src/JsxV4.res 14:9
17+
{"contents": "```rescript\nReact.component<M4.props<string, string, string>>\n```\n\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype M4.props<'first, 'fun, 'second> = {\n first: 'first,\n fun?: 'fun,\n second?: 'second,\n}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22JsxV4.res%22%2C3%2C2%5D)\n\n---\n\n\n Doc Comment For M4 "}
18+

0 commit comments

Comments
 (0)