@@ -107,7 +107,7 @@ let expandTypes ~file ~package ~supportsMarkdownLinks typ =
107107 | {decl; path} :: _
108108 when Res_parsetree_viewer. has_inline_record_definition_attribute
109109 decl.type_attributes ->
110- (* We print inline record types just with their definition, not the constr pointing
110+ (* We print inline record types just with their definition, not the constr pointing
111111 to them, since that doesn't make sense to show the user. *)
112112 ( [
113113 Markdown. codeBlock
@@ -149,9 +149,49 @@ 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 ~file ~package ~supportsMarkdownLinks ?constructor
153- typ =
154- let expandedTypes, expansionType =
152+ let hoverWithExpandedTypes ~(full : SharedTypes.full ) ~file ~package
153+ ~supportsMarkdownLinks ?constructor typ =
154+ let {TypeUtils.ExpandType. mainTypes; relatedTypes} =
155+ TypeUtils.ExpandType. expandTypes ~full
156+ (TypeUtils.ExpandType. TypeExpr
157+ {typeExpr = typ; (* TODO *) name = None ; env = QueryEnv. fromFile file})
158+ in
159+
160+ (* TODO: wrap in markdown code blocks and render links if `supportsMarkdownLinks` (but not for inline records) *)
161+ let expandedTypesToString
162+ (expandedTypes : TypeUtils.ExpandType.expandTypeInput list ) =
163+ expandedTypes
164+ |> List. map (fun input ->
165+ match input with
166+ | TypeUtils.ExpandType. TypeExpr {typeExpr} ->
167+ Shared. typeToString typeExpr
168+ | TypeUtils.ExpandType. TypeDecl {name; typeDecl} ->
169+ Shared. declToString name.txt typeDecl)
170+ |> List. map Markdown. codeBlock
171+ in
172+
173+ let mainTypes =
174+ let insert_contructor constructor mainTypes =
175+ match mainTypes with
176+ | [] -> [constructor]
177+ | h :: t -> h :: constructor :: t
178+ in
179+ match constructor with
180+ | Some constructor ->
181+ let constructor =
182+ (CompletionBackEnd. showConstructor constructor |> Markdown. codeBlock)
183+ ^ Markdown. divider
184+ in
185+ insert_contructor constructor (expandedTypesToString mainTypes)
186+ | None -> expandedTypesToString mainTypes
187+ in
188+
189+ (* TODO: docstring? *)
190+ (mainTypes |> String. concat " \n " )
191+ ^ " \n "
192+ ^ (expandedTypesToString relatedTypes |> String. concat Markdown. divider)
193+
194+ (* let expandedTypes, expansionType =
155195 expandTypes ~file ~package ~supportsMarkdownLinks typ
156196 in
157197 match expansionType with
@@ -164,7 +204,7 @@ let hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks ?constructor
164204 | None -> typeString
165205 in
166206 Markdown.codeBlock typeString :: expandedTypes |> String.concat "\n"
167- | `InlineType -> expandedTypes |> String. concat " \n "
207+ | `InlineType -> expandedTypes |> String.concat "\n" *)
168208
169209(* Leverages autocomplete functionality to produce a hover for a position. This
170210 makes it (most often) work with unsaved content. *)
@@ -190,7 +230,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
190230 with
191231 | Some (typ , _env ) ->
192232 let typeString =
193- hoverWithExpandedTypes ~file ~package ~supports MarkdownLinks typ
233+ hoverWithExpandedTypes ~full ~ file ~package ~supports MarkdownLinks typ
194234 in
195235 let parts = docstring @ [typeString] in
196236 Some (Protocol. stringifyHover (String. concat " \n\n " parts))
@@ -203,13 +243,14 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
203243 with
204244 | Some (typ , _env ) ->
205245 let typeString =
206- hoverWithExpandedTypes ~file ~package ~supports MarkdownLinks typ
246+ hoverWithExpandedTypes ~full ~ file ~package ~supports MarkdownLinks typ
207247 in
208248 Some (Protocol. stringifyHover typeString)
209249 | None -> None )
210250 | _ -> None )
211251
212- let newHover ~full :{file; package} ~supportsMarkdownLinks locItem =
252+ let newHover ~full ~supportsMarkdownLinks locItem =
253+ let {file; package} = full in
213254 match locItem.locType with
214255 | TypeDefinition (name , decl , _stamp ) -> (
215256 let typeDef = Markdown. codeBlock (Shared. declToString name decl) in
@@ -277,8 +318,8 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
277318 | Const_bigint _ -> " bigint" ))
278319 | Typed (_ , t , locKind ) ->
279320 let fromType ?constructor typ =
280- hoverWithExpandedTypes ~file ~package ~supports MarkdownLinks ?constructor
281- typ
321+ hoverWithExpandedTypes ~full ~ file ~package ~supports MarkdownLinks
322+ ?constructor typ
282323 in
283324 let parts =
284325 match References. definedForLoc ~file ~package locKind with
0 commit comments