Skip to content

Commit 31899c5

Browse files
authored
Hover: Print signature above docstrings (#969)
* print signature above docstrings * update CHANGELOG.md * update tests
1 parent 9ff1029 commit 31899c5

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
- Make sure doc strings are always on top in hovers. https://github.com/rescript-lang/rescript-vscode/pull/956
2222
- Make JSX completion work for `make` functions of type `React.component<props>`, like what you get when using `React.lazy_`. https://github.com/rescript-lang/rescript-vscode/pull/966
23+
- Hover: print signature above docstrings. https://github.com/rescript-lang/rescript-vscode/pull/969
2324

2425
#### :rocket: New Feature
2526

analysis/src/Hover.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
237237
match References.definedForLoc ~file ~package locKind with
238238
| None ->
239239
let typeString, docstring = t |> fromType ~docstring:[] in
240-
docstring @ [typeString]
240+
typeString :: docstring
241241
| Some (docstring, res) -> (
242242
match res with
243243
| `Declared ->
244244
let typeString, docstring = t |> fromType ~docstring in
245-
docstring @ [typeString]
245+
typeString :: docstring
246246
| `Constructor {cname = {txt}; args; docstring} ->
247247
let typeString, docstring = t |> fromType ~docstring in
248248
let argsString =
@@ -253,9 +253,9 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
253253
|> List.map (fun (t, _) -> Shared.typeToString t)
254254
|> String.concat ", " |> Printf.sprintf "(%s)"
255255
in
256-
(Markdown.codeBlock (txt ^ argsString) :: docstring) @ [typeString]
256+
typeString :: Markdown.codeBlock (txt ^ argsString) :: docstring
257257
| `Field ->
258258
let typeString, docstring = t |> fromType ~docstring in
259-
docstring @ [typeString])
259+
typeString :: docstring)
260260
in
261-
Some (String.concat "\n\n" parts)
261+
Some (String.concat Markdown.divider parts)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Definition src/Definition.res 10:23
55
{"uri": "Definition.res", "range": {"start": {"line": 6, "character": 7}, "end": {"line": 6, "character": 13}}}
66

77
Hover src/Definition.res 14:14
8-
{"contents": {"kind": "markdown", "value": " [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an],\n and builds the list [[f a1; ...; f an]]\n with the results returned by [f]. Not tail-recursive. \n\n```rescript\n('a => 'b, list<'a>) => list<'b>\n```"}}
8+
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```\n---\n [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an],\n and builds the list [[f a1; ...; f an]]\n with the results returned by [f]. Not tail-recursive. "}}
99

1010
Hover src/Definition.res 18:14
1111
{"contents": {"kind": "markdown", "value": "```rescript\n(list<'a>, 'a => 'b) => list<'b>\n```"}}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Hover src/DocComments.res 9:9
2-
{"contents": {"kind": "markdown", "value": " Doc comment with a triple-backquote example\\n \\n ```res example\\n let a = 10\\n /*\\n * stuff\\n */\\n ```\\n\n\n```rescript\nint\n```"}}
2+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n Doc comment with a triple-backquote example\\n \\n ```res example\\n let a = 10\\n /*\\n * stuff\\n */\\n ```\\n"}}
33

44
Hover src/DocComments.res 22:6
5-
{"contents": {"kind": "markdown", "value": "\n Doc comment with a triple-backquote example\n \n ```res example\n let a = 10\n /*\n * stuff\n */\n ```\n\n\n```rescript\nint\n```"}}
5+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n\n Doc comment with a triple-backquote example\n \n ```res example\n let a = 10\n /*\n * stuff\n */\n ```\n"}}
66

77
Hover src/DocComments.res 33:9
8-
{"contents": {"kind": "markdown", "value": " Doc comment with a triple-backquote example\\n \\n ```res example\\n let a = 10\\n let b = 20\\n ```\\n\n\n```rescript\nint\n```"}}
8+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n Doc comment with a triple-backquote example\\n \\n ```res example\\n let a = 10\\n let b = 20\\n ```\\n"}}
99

1010
Hover src/DocComments.res 44:6
11-
{"contents": {"kind": "markdown", "value": "\n Doc comment with a triple-backquote example\n \n ```res example\n let a = 10\n let b = 20\n ```\n\n\n```rescript\nint\n```"}}
11+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n\n Doc comment with a triple-backquote example\n \n ```res example\n let a = 10\n let b = 20\n ```\n"}}
1212

1313
Hover src/DocComments.res 48:5
14-
{"contents": {"kind": "markdown", "value": "New doc comment format\n\n```rescript\nint\n```"}}
14+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\nNew doc comment format"}}
1515

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Hover src/Hover.res 19:11
1111
{"contents": {"kind": "markdown", "value": "\nThis module is commented\n```rescript\nmodule Dep: {\n let customDouble: int => int\n}\n```"}}
1212

1313
Hover src/Hover.res 22:11
14-
{"contents": {"kind": "markdown", "value": "Some doc comment\n\n```rescript\nint => int\n```"}}
14+
{"contents": {"kind": "markdown", "value": "```rescript\nint => int\n```\n---\nSome doc comment"}}
1515

1616
Hover src/Hover.res 26:6
1717
getLocItem #8: heuristic for JSX with at most one child
1818
heuristic for: [makeProps, make, createElement], give the loc of `make`
1919
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```"}}
2020

2121
Hover src/Hover.res 33:4
22-
{"contents": {"kind": "markdown", "value": "Doc comment for functionWithTypeAnnotation\n\n```rescript\nunit => int\n```"}}
22+
{"contents": {"kind": "markdown", "value": "```rescript\nunit => int\n```\n---\nDoc comment for functionWithTypeAnnotation"}}
2323

2424
Hover src/Hover.res 37:13
2525
getLocItem #5: heuristic for JSX and compiler combined:
@@ -103,10 +103,10 @@ Hover src/Hover.res 137:5
103103
{"contents": {"kind": "markdown", "value": "```rescript\nunit => unit => int\n```"}}
104104

105105
Hover src/Hover.res 144:9
106-
{"contents": {"kind": "markdown", "value": "doc comment 1\n\n```rescript\nint\n```"}}
106+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\ndoc comment 1"}}
107107

108108
Hover src/Hover.res 148:6
109-
{"contents": {"kind": "markdown", "value": " doc comment 2 \n\n```rescript\nint\n```"}}
109+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n doc comment 2 "}}
110110

111111
Hover src/Hover.res 165:23
112112
{"contents": {"kind": "markdown", "value": "```rescript\nfoo<bar>\n```\n\n---\n\n```\n \n```\n```rescript\ntype foo<'a> = {content: 'a, zzz: string}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C161%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype bar = {age: int}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C162%2C2%5D)\n"}}
@@ -206,10 +206,10 @@ Resolved opens 1 pervasives
206206
{"contents": {"kind": "markdown", "value": "```rescript\nuseR\n```\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```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"}}
207207

208208
Hover src/Hover.res 230:20
209-
{"contents": {"kind": "markdown", "value": " More Stuff \n\n```rescript\nint\n```"}}
209+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n More Stuff "}}
210210

211211
Hover src/Hover.res 233:17
212-
{"contents": {"kind": "markdown", "value": " More Stuff \n\n```rescript\nint\n```"}}
212+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n More Stuff "}}
213213

214214
Hover src/Hover.res 245:6
215215
Nothing at that position. Now trying to use completion.
@@ -226,10 +226,10 @@ Resolved opens 1 pervasives
226226
{"contents": {"kind": "markdown", "value": " Mighty fine field here. \n\n```rescript\nbool\n```"}}
227227

228228
Hover src/Hover.res 248:19
229-
{"contents": {"kind": "markdown", "value": " Mighty fine field here. \n\n```rescript\nbool\n```"}}
229+
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n---\n Mighty fine field here. "}}
230230

231231
Hover src/Hover.res 253:20
232-
{"contents": {"kind": "markdown", "value": "```rescript\nCoolVariant\n```\n\n Cool variant! \n\n```rescript\nvariant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C251%2C0%5D)\n"}}
232+
{"contents": {"kind": "markdown", "value": "```rescript\nvariant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C251%2C0%5D)\n\n---\n```rescript\nCoolVariant\n```\n---\n Cool variant! "}}
233233

234234
Hover src/Hover.res 257:23
235235
Nothing at that position. Now trying to use completion.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Path M4.make
1717
}]
1818

1919
Hover src/JsxV4.res 14:9
20-
{"contents": {"kind": "markdown", "value": " Doc Comment For M4 \n\n```rescript\nReact.component<M4.props<string, string, string>>\n```\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```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"}}
20+
{"contents": {"kind": "markdown", "value": "```rescript\nReact.component<M4.props<string, string, string>>\n```\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```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 Doc Comment For M4 "}}
2121

2222
Create Interface src/JsxV4.res
2323
module M4: {

0 commit comments

Comments
 (0)