Skip to content

Fix issue where doc comment is not shown on hover in case of shadowed identifier #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions analysis/tests/src/Hover.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions analysis/tests/src/JsxV4.res
Original file line number Diff line number Diff line change
@@ -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)
}
Expand All @@ -10,3 +11,6 @@ let _ = <M4 first="abc" />

// <M4 first="abc" f
// ^com

let _ = <M4 first="abc" />
// ^hov
6 changes: 6 additions & 0 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<option<r<float>>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n\n---\n"}

Hover src/Hover.res 230:20
{"contents": "```rescript\nint\n```\n\n More Stuff "}

Hover src/Hover.res 233:17
{"contents": "```rescript\nint\n```\n\n More Stuff "}

13 changes: 8 additions & 5 deletions analysis/tests/src/expected/JsxV4.res.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Definition src/JsxV4.res 7:9
{"uri": "JsxV4.res", "range": {"start": {"line": 4, "character": 6}, "end": {"line": 4, "character": 10}}}
Definition src/JsxV4.res 8:9
{"uri": "JsxV4.res", "range": {"start": {"line": 5, "character": 6}, "end": {"line": 5, "character": 10}}}

Complete src/JsxV4.res 10:20
posCursor:[10:20] posNoWhite:[10:19] Found expr:[10:4->10:20]
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
Complete src/JsxV4.res 11:20
posCursor:[11:20] posNoWhite:[11:19] Found expr:[11:4->11:20]
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
Completable: Cjsx([M4], f, [first, f])
[{
"label": "fun",
Expand All @@ -13,3 +13,6 @@ Completable: Cjsx([M4], f, [first, f])
"documentation": null
}]

Hover src/JsxV4.res 14:9
{"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 "}