Skip to content

Doc comment #525

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
Jul 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Inlay Hints (experimetal). `rescript.settings.inlayHints.enable: true`. Turned off by default. https://github.com/rescript-lang/rescript-vscode/pull/453
- Code Lenses for functions (experimetal). `rescript.settings.codeLens: true`. Turned off by default. https://github.com/rescript-lang/rescript-vscode/pull/513
- Markdown code blocks tagged as `rescript` now get basic syntax highlighting. https://github.com/rescript-lang/rescript-vscode/pull/97
- Hover support for doc comments on v10 compiler `/** this is a doc comment */`

#### :bug: Bug Fix

Expand Down
2 changes: 1 addition & 1 deletion analysis/src/ProcessAttributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let rec findDocAttribute attributes =
let open Parsetree in
match attributes with
| [] -> None
| ( {Asttypes.txt = "ocaml.doc"},
| ( {Asttypes.txt = "ocaml.doc" | "ns.doc"},
PStr
[
{
Expand Down
29 changes: 27 additions & 2 deletions analysis/tests/src/Hover.res
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ module Comp = {

module Comp1 = Comp

let _ = <Comp> <div /> <div /> </Comp>
let _ =
<Comp>
<div />
<div />
</Comp>
// ^hov

let _ = <Comp1> <div /> <div /> </Comp1>
let _ =
<Comp1>
<div />
<div />
</Comp1>
// ^hov

type r<'a> = {i: 'a, f: float}
Expand Down Expand Up @@ -130,3 +138,20 @@ let arity0d = (. ()) => {
let f = () => 3
f
}

/**doc comment 1*/
let docComment1 = 12
// ^hov

/** doc comment 2 */
let docComment2 = 12
// ^hov

module ModWithDocComment = {
/*** module level doc comment 1 */

/** doc comment for x */
let x = 44

/*** module level doc comment 2 */
}
50 changes: 28 additions & 22 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,51 @@ Hover src/Hover.res 72:7
Hover src/Hover.res 75:7
{"contents": "```rescript\nmodule A = {\n let x: int\n}\n```"}

Hover src/Hover.res 85:10
getLocItem #9: heuristic for JSX variadic, e.g. <C> {x} {y} </C>
heuristic for: [React.null, makeProps, make, createElementVariadic], give the loc of `make`
n1:null n2:makeProps n3:make n4:createElementVariadic
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n```rescript\ntype component<'props> = componentLike<'props, element>\n```"}

Hover src/Hover.res 88:10
getLocItem #9: heuristic for JSX variadic, e.g. <C> {x} {y} </C>
heuristic for: [React.null, makeProps, make, createElementVariadic], give the loc of `make`
n1:null n2:makeProps n3:make n4:createElementVariadic
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n```rescript\ntype component<'props> = componentLike<'props, element>\n```"}

Hover src/Hover.res 93:25
Hover src/Hover.res 89:10
Nothing at that position. Now trying to use completion.
posCursor:[89:10] posNoWhite:[89:8] Found expr:[86:3->89:9]
JSX <Comp:[86:3->86:7] > _children:86:7
null

Hover src/Hover.res 96:10
Nothing at that position. Now trying to use completion.
posCursor:[96:10] posNoWhite:[96:9] Found expr:[93:3->96:10]
JSX <Comp1:[93:3->93:8] > _children:93:8
null

Hover src/Hover.res 101:25
{"contents": "```rescript\nfloat\n```"}

Hover src/Hover.res 96:21
Hover src/Hover.res 104:21
{"contents": "```rescript\nint\n```"}

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

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

Hover src/Hover.res 112:3
Hover src/Hover.res 120:3
Nothing at that position. Now trying to use completion.
Attribute id:live:[112:0->112:5] label:live
Attribute id:live:[120:0->120:5] label:live
Completable: Cdecorator(live)
{"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!"}

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

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

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

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

Hover src/Hover.res 142:9
{"contents": "```rescript\nint\n```\n\ndoc comment 1"}

Hover src/Hover.res 146:6
{"contents": "```rescript\nint\n```\n\n doc comment 2 "}