Skip to content

Commit 8543778

Browse files
authored
Make sure doc strings are always on top in hovers (#956)
* make sure doc strings are always on top in hovers * changelog * remove flaky test
1 parent 823bf67 commit 8543778

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :nail_care: Polish
16+
17+
- Make sure doc strings are always on top in hovers. https://github.com/rescript-lang/rescript-vscode/pull/956
18+
1519
## 1.50.0
1620

1721
#### :rocket: New Feature

analysis/src/Hover.ml

+7-6
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
133133
match completions with
134134
| {kind = Label typString; docstring} :: _ ->
135135
let parts =
136-
(if typString = "" then [] else [Markdown.codeBlock typString])
137-
@ docstring
136+
docstring
137+
@ if typString = "" then [] else [Markdown.codeBlock typString]
138138
in
139+
139140
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
140141
| {kind = Field _; env; docstring} :: _ -> (
141142
let opens = CompletionBackEnd.getOpens ~debug ~rawOpens ~package ~env in
@@ -147,7 +148,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
147148
let typeString =
148149
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
149150
in
150-
let parts = typeString :: docstring in
151+
let parts = docstring @ [typeString] in
151152
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
152153
| None -> None)
153154
| {env} :: _ -> (
@@ -236,12 +237,12 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
236237
match References.definedForLoc ~file ~package locKind with
237238
| None ->
238239
let typeString, docstring = t |> fromType ~docstring:[] in
239-
typeString :: docstring
240+
docstring @ [typeString]
240241
| Some (docstring, res) -> (
241242
match res with
242243
| `Declared ->
243244
let typeString, docstring = t |> fromType ~docstring in
244-
typeString :: docstring
245+
docstring @ [typeString]
245246
| `Constructor {cname = {txt}; args; docstring} ->
246247
let typeString, docstring = t |> fromType ~docstring in
247248
let argsString =
@@ -255,6 +256,6 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
255256
(Markdown.codeBlock (txt ^ argsString) :: docstring) @ [typeString]
256257
| `Field ->
257258
let typeString, docstring = t |> fromType ~docstring in
258-
typeString :: docstring)
259+
docstring @ [typeString])
259260
in
260261
Some (String.concat "\n\n" parts)

analysis/tests/src/Hover.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,4 @@ module Arr = Belt.Array
265265
// ^hov
266266

267267
type aliased = variant
268-
// ^hov
268+
// ^hov

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": "```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. "}}
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```"}}
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": "```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"}}
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```"}}
33

44
Hover src/DocComments.res 22:6
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"}}
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```"}}
66

77
Hover src/DocComments.res 33:9
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"}}
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```"}}
99

1010
Hover src/DocComments.res 44:6
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"}}
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```"}}
1212

1313
Hover src/DocComments.res 48:5
14-
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n\nNew doc comment format"}}
14+
{"contents": {"kind": "markdown", "value": "New doc comment format\n\n```rescript\nint\n```"}}
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": "```rescript\nint => int\n```\n\nSome doc comment"}}
14+
{"contents": {"kind": "markdown", "value": "Some doc comment\n\n```rescript\nint => int\n```"}}
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": "```rescript\nunit => int\n```\n\nDoc comment for functionWithTypeAnnotation"}}
22+
{"contents": {"kind": "markdown", "value": "Doc comment for functionWithTypeAnnotation\n\n```rescript\nunit => int\n```"}}
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": "```rescript\nint\n```\n\ndoc comment 1"}}
106+
{"contents": {"kind": "markdown", "value": "doc comment 1\n\n```rescript\nint\n```"}}
107107

108108
Hover src/Hover.res 148:6
109-
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n\n doc comment 2 "}}
109+
{"contents": {"kind": "markdown", "value": " doc comment 2 \n\n```rescript\nint\n```"}}
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": "```rescript\nint\n```\n\n More Stuff "}}
209+
{"contents": {"kind": "markdown", "value": " More Stuff \n\n```rescript\nint\n```"}}
210210

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

214214
Hover src/Hover.res 245:6
215215
Nothing at that position. Now trying to use completion.
@@ -223,10 +223,10 @@ ContextPath Value[x]
223223
Path x
224224
Package opens Pervasives.JsxModules.place holder
225225
Resolved opens 1 pervasives
226-
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n\n Mighty fine field here. "}}
226+
{"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": "```rescript\nbool\n```\n\n Mighty fine field here. "}}
229+
{"contents": {"kind": "markdown", "value": " Mighty fine field here. \n\n```rescript\nbool\n```"}}
230230

231231
Hover src/Hover.res 253:20
232232
{"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"}}

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": "```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 "}}
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"}}
2121

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

0 commit comments

Comments
 (0)