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>>}\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 "} + diff --git a/analysis/tests/src/expected/JsxV4.res.txt b/analysis/tests/src/expected/JsxV4.res.txt index b791e9ecf..377058c66 100644 --- a/analysis/tests/src/expected/JsxV4.res.txt +++ b/analysis/tests/src/expected/JsxV4.res.txt @@ -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 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 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", @@ -13,3 +13,6 @@ Completable: Cjsx([M4], f, [first, f]) "documentation": null }] +Hover src/JsxV4.res 14:9 +{"contents": "```rescript\nReact.component>\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 "} +