Skip to content

Commit 4aa0757

Browse files
committed
Show variant constructor type information below type on hover
1 parent 88a772f commit 4aa0757

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

analysis/src/Hover.ml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,21 @@ let expandTypes ~file ~package ~supportsMarkdownLinks typ =
137137
`Default )
138138

139139
(* Produces a hover with relevant types expanded in the main type being hovered. *)
140-
let hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ =
141-
let typeString = Markdown.codeBlock (typ |> Shared.typeToString) in
140+
let hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks ?constructor
141+
typ =
142142
let expandedTypes, expansionType =
143143
expandTypes ~file ~package ~supportsMarkdownLinks typ
144144
in
145145
match expansionType with
146-
| `Default -> typeString :: expandedTypes |> String.concat "\n"
146+
| `Default ->
147+
let typeString = Shared.typeToString typ in
148+
let typeString =
149+
match constructor with
150+
| Some constructor ->
151+
typeString ^ "\n" ^ CompletionBackEnd.showConstructor constructor
152+
| None -> typeString
153+
in
154+
Markdown.codeBlock typeString :: expandedTypes |> String.concat "\n"
147155
| `InlineType -> expandedTypes |> String.concat "\n"
148156

149157
(* Leverages autocomplete functionality to produce a hover for a position. This
@@ -256,8 +264,9 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
256264
| Const_int64 _ -> "int64"
257265
| Const_bigint _ -> "bigint"))
258266
| Typed (_, t, locKind) ->
259-
let fromType ~docstring typ =
260-
( hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ,
267+
let fromType ~docstring ?constructor typ =
268+
( hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks
269+
?constructor typ,
261270
docstring )
262271
in
263272
let parts =
@@ -272,11 +281,9 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
272281
typeString :: docstring
273282
| `Constructor constructor ->
274283
let typeString, docstring =
275-
t |> fromType ~docstring:constructor.docstring
284+
t |> fromType ~docstring:constructor.docstring ~constructor
276285
in
277-
typeString
278-
:: Markdown.codeBlock (CompletionBackEnd.showConstructor constructor)
279-
:: docstring
286+
typeString :: docstring
280287
| `Field ->
281288
let typeString, docstring = t |> fromType ~docstring in
282289
typeString :: docstring)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Hover src/Hover.res 248:19
301301
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n---\n Mighty fine field here. "}}
302302

303303
Hover src/Hover.res 253:20
304-
{"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! "}}
304+
{"contents": {"kind": "markdown", "value": "```rescript\nvariant\nCoolVariant\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 Cool variant! "}}
305305

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

0 commit comments

Comments
 (0)