Skip to content

Commit fbb6e1f

Browse files
committed
Add support for hovering on doc comments.
1 parent e0522a8 commit fbb6e1f

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Inlay Hints (experimetal). `rescript.settings.inlayHints.enable: true`. Turned off by default. https://github.com/rescript-lang/rescript-vscode/pull/453
1818
- Code Lenses for functions (experimetal). `rescript.settings.codeLens: true`. Turned off by default. https://github.com/rescript-lang/rescript-vscode/pull/513
1919
- Markdown code blocks tagged as `rescript` now get basic syntax highlighting. https://github.com/rescript-lang/rescript-vscode/pull/97
20+
- Hover support for v10 compiler `/** doc comments */`
2021

2122
#### :bug: Bug Fix
2223

analysis/src/ProcessAttributes.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let rec findDocAttribute attributes =
55
let open Parsetree in
66
match attributes with
77
| [] -> None
8-
| ( {Asttypes.txt = "ocaml.doc"},
8+
| ( {Asttypes.txt = "ocaml.doc" | "ns.doc"},
99
PStr
1010
[
1111
{

analysis/tests/src/Hover.res

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ module Comp = {
8383

8484
module Comp1 = Comp
8585

86-
let _ = <Comp> <div /> <div /> </Comp>
86+
let _ =
87+
<Comp>
88+
<div />
89+
<div />
90+
</Comp>
8791
// ^hov
8892

89-
let _ = <Comp1> <div /> <div /> </Comp1>
93+
let _ =
94+
<Comp1>
95+
<div />
96+
<div />
97+
</Comp1>
9098
// ^hov
9199

92100
type r<'a> = {i: 'a, f: float}
@@ -130,3 +138,11 @@ let arity0d = (. ()) => {
130138
let f = () => 3
131139
f
132140
}
141+
142+
/**doc comment 1*/
143+
let docComment1 = 12
144+
// ^hov
145+
146+
/** doc comment 2 */
147+
let docComment2 = 12
148+
// ^hov

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,45 +56,51 @@ Hover src/Hover.res 72:7
5656
Hover src/Hover.res 75:7
5757
{"contents": "```rescript\nmodule A = {\n let x: int\n}\n```"}
5858

59-
Hover src/Hover.res 85:10
60-
getLocItem #9: heuristic for JSX variadic, e.g. <C> {x} {y} </C>
61-
heuristic for: [React.null, makeProps, make, createElementVariadic], give the loc of `make`
62-
n1:null n2:makeProps n3:make n4:createElementVariadic
63-
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n```rescript\ntype component<'props> = componentLike<'props, element>\n```"}
64-
65-
Hover src/Hover.res 88:10
66-
getLocItem #9: heuristic for JSX variadic, e.g. <C> {x} {y} </C>
67-
heuristic for: [React.null, makeProps, make, createElementVariadic], give the loc of `make`
68-
n1:null n2:makeProps n3:make n4:createElementVariadic
69-
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n```rescript\ntype component<'props> = componentLike<'props, element>\n```"}
70-
71-
Hover src/Hover.res 93:25
59+
Hover src/Hover.res 89:10
60+
Nothing at that position. Now trying to use completion.
61+
posCursor:[89:10] posNoWhite:[89:8] Found expr:[86:3->89:9]
62+
JSX <Comp:[86:3->86:7] > _children:86:7
63+
null
64+
65+
Hover src/Hover.res 96:10
66+
Nothing at that position. Now trying to use completion.
67+
posCursor:[96:10] posNoWhite:[96:9] Found expr:[93:3->96:10]
68+
JSX <Comp1:[93:3->93:8] > _children:93:8
69+
null
70+
71+
Hover src/Hover.res 101:25
7272
{"contents": "```rescript\nfloat\n```"}
7373

74-
Hover src/Hover.res 96:21
74+
Hover src/Hover.res 104:21
7575
{"contents": "```rescript\nint\n```"}
7676

77-
Hover src/Hover.res 106:16
77+
Hover src/Hover.res 114:16
7878
{"contents": "```rescript\nAA.cond<[< #str(string)]> => AA.cond<[< #str(string)]>\n```"}
7979

80-
Hover src/Hover.res 109:25
80+
Hover src/Hover.res 117:25
8181
{"contents": "```rescript\nAA.cond<[< #str(string)]> => AA.cond<[< #str(string)]>\n```"}
8282

83-
Hover src/Hover.res 112:3
83+
Hover src/Hover.res 120:3
8484
Nothing at that position. Now trying to use completion.
85-
Attribute id:live:[112:0->112:5] label:live
85+
Attribute id:live:[120:0->120:5] label:live
8686
Completable: Cdecorator(live)
8787
{"contents": "The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.\n\n`@live` tells the dead code analysis that the value should be considered live, even though it might appear to be dead. This is typically used in case of FFI where there are indirect ways to access values. It can be added to everything that could otherwise be considered unused by the dead code analysis - values, functions, arguments, records, individual record fields, and so on.\n\n[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#live-decorator).\n\nHint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!"}
8888

89-
Hover src/Hover.res 115:4
89+
Hover src/Hover.res 123:4
9090
{"contents": "```rescript\n(. ()) => unit => int\n```"}
9191

92-
Hover src/Hover.res 121:4
92+
Hover src/Hover.res 129:4
9393
{"contents": "```rescript\n(. ()) => (. ()) => int\n```"}
9494

95-
Hover src/Hover.res 124:4
95+
Hover src/Hover.res 132:4
9696
{"contents": "```rescript\n(. unit, unit) => int\n```"}
9797

98-
Hover src/Hover.res 127:5
98+
Hover src/Hover.res 135:5
9999
{"contents": "```rescript\n(. ()) => unit => int\n```"}
100100

101+
Hover src/Hover.res 142:9
102+
{"contents": "```rescript\nint\n```\n\ndoc comment 1"}
103+
104+
Hover src/Hover.res 146:6
105+
{"contents": "```rescript\nint\n```\n\n doc comment 2 "}
106+

0 commit comments

Comments
 (0)