@@ -149,8 +149,9 @@ let expandTypes ~file ~package ~supportsMarkdownLinks typ =
149149 `Default )
150150
151151(* 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
153153 ~supportsMarkdownLinks ?constructor typ =
154+ (* TODO: figure out why this is not returning expanded types *)
154155 let {TypeUtils.ExpandType. mainTypes; relatedTypes} =
155156 TypeUtils.ExpandType. expandTypes ~full
156157 (TypeUtils.ExpandType. TypeExpr
@@ -186,25 +187,16 @@ let hoverWithExpandedTypes ~(full : SharedTypes.full) ~file ~package
186187 | None -> expandedTypesToString mainTypes
187188 in
188189
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
196195 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)
208200
209201(* Leverages autocomplete functionality to produce a hover for a position. This
210202 makes it (most often) work with unsaved content. *)
@@ -230,10 +222,10 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
230222 with
231223 | Some (typ , _env ) ->
232224 let typeString =
233- hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks typ
225+ hoverWithExpandedTypes ~full ~file ~package ~docstring
226+ ~supports MarkdownLinks typ
234227 in
235- let parts = docstring @ [typeString] in
236- Some (Protocol. stringifyHover (String. concat " \n\n " parts))
228+ Some (Protocol. stringifyHover typeString)
237229 | None -> None )
238230 | {env} :: _ -> (
239231 let opens = CompletionBackEnd. getOpens ~debug ~raw Opens ~package ~env in
@@ -317,22 +309,16 @@ let newHover ~full ~supportsMarkdownLinks locItem =
317309 | Const_int64 _ -> " int64"
318310 | Const_bigint _ -> " bigint" ))
319311 | 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
326314 | None ->
327- let typeString = t |> fromType in
328- [typeString]
315+ hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks t
329316 | Some (docstring , res ) -> (
317+ let fromType ?docstring ?constructor typ =
318+ hoverWithExpandedTypes ~full ~file ~package ~supports MarkdownLinks
319+ ?docstring ?constructor typ
320+ in
330321 match res with
331- | `Declared | `Field ->
332- let typeString = t |> fromType in
333- typeString :: docstring
322+ | `Declared | `Field -> t |> fromType ~docstring
334323 | `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