@@ -149,8 +149,9 @@ let expandTypes ~file ~package ~supportsMarkdownLinks typ =
149
149
`Default )
150
150
151
151
(* Produces a hover with relevant types expanded in the main type being hovered. *)
152
- let hoverWithExpandedTypes ~(full : SharedTypes.full ) ~file ~package
152
+ let hoverWithExpandedTypes ~(full : SharedTypes.full ) ~file ~package ? docstring
153
153
~supportsMarkdownLinks ?constructor typ =
154
+ (* TODO: figure out why this is not returning expanded types *)
154
155
let {TypeUtils.ExpandType. mainTypes; relatedTypes} =
155
156
TypeUtils.ExpandType. expandTypes ~full
156
157
(TypeUtils.ExpandType. TypeExpr
@@ -186,25 +187,16 @@ let hoverWithExpandedTypes ~(full : SharedTypes.full) ~file ~package
186
187
| None -> expandedTypesToString mainTypes
187
188
in
188
189
189
- (* TODO: docstring? *)
190
- (mainTypes |> String. concat " \n " )
191
- ^ " \n "
192
- ^ (expandedTypesToString relatedTypes |> String. concat Markdown. divider)
193
-
194
- (* let expandedTypes, expansionType =
195
- expandTypes ~file ~package ~supportsMarkdownLinks typ
190
+ let hoverMarkdown = mainTypes |> String. concat " \n " in
191
+ let hoverMarkdown =
192
+ match docstring with
193
+ | Some docstring -> hoverMarkdown ^ " \n " ^ (docstring |> String. concat " \n " )
194
+ | None -> hoverMarkdown
196
195
in
197
- match expansionType with
198
- | `Default ->
199
- let typeString = Shared.typeToString typ in
200
- let typeString =
201
- match constructor with
202
- | Some constructor ->
203
- typeString ^ "\n" ^ CompletionBackEnd.showConstructor constructor
204
- | None -> typeString
205
- in
206
- Markdown.codeBlock typeString :: expandedTypes |> String.concat "\n"
207
- | `InlineType -> expandedTypes |> String.concat "\n" *)
196
+ if List. is_empty relatedTypes then hoverMarkdown
197
+ else
198
+ hoverMarkdown ^ " \n "
199
+ ^ (expandedTypesToString relatedTypes |> String. concat Markdown. divider)
208
200
209
201
(* Leverages autocomplete functionality to produce a hover for a position. This
210
202
makes it (most often) work with unsaved content. *)
@@ -230,10 +222,10 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
230
222
with
231
223
| Some (typ , _env ) ->
232
224
let typeString =
233
- hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks typ
225
+ hoverWithExpandedTypes ~full ~file ~package ~docstring
226
+ ~supports MarkdownLinks typ
234
227
in
235
- let parts = docstring @ [typeString] in
236
- Some (Protocol. stringifyHover (String. concat " \n\n " parts))
228
+ Some (Protocol. stringifyHover typeString)
237
229
| None -> None )
238
230
| {env} :: _ -> (
239
231
let opens = CompletionBackEnd. getOpens ~debug ~raw Opens ~package ~env in
@@ -317,22 +309,16 @@ let newHover ~full ~supportsMarkdownLinks locItem =
317
309
| Const_int64 _ -> " int64"
318
310
| Const_bigint _ -> " bigint" ))
319
311
| Typed (_ , t , locKind ) ->
320
- let fromType ?constructor typ =
321
- hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks
322
- ?constructor typ
323
- in
324
- let parts =
325
- match References. definedForLoc ~file ~package locKind with
312
+ Some
313
+ (match References. definedForLoc ~file ~package locKind with
326
314
| None ->
327
- let typeString = t |> fromType in
328
- [typeString]
315
+ hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks t
329
316
| Some (docstring , res ) -> (
317
+ let fromType ?docstring ?constructor typ =
318
+ hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks
319
+ ?docstring ?constructor typ
320
+ in
330
321
match res with
331
- | `Declared | `Field ->
332
- let typeString = t |> fromType in
333
- typeString :: docstring
322
+ | `Declared | `Field -> t |> fromType ~docstring
334
323
| `Constructor constructor ->
335
- let typeString = t |> fromType ~constructor in
336
- typeString :: constructor.docstring)
337
- in
338
- Some (String. concat Markdown. divider parts)
324
+ t |> fromType ~docstring: constructor.docstring ~constructor ))
0 commit comments