@@ -100,27 +100,27 @@ let findRelevantTypesFromType ~file ~package typ =
100100 let constructors = Shared. findTypeConstructors typesToSearch in
101101 constructors |> List. filter_map (fromConstructorPath ~env: envToSearch)
102102
103+ let expandTypes ~file ~package ~supportsMarkdownLinks typ =
104+ findRelevantTypesFromType typ ~file ~package
105+ |> List. map (fun {decl; env; loc; path} ->
106+ let linkToTypeDefinitionStr =
107+ if supportsMarkdownLinks then
108+ Markdown. goToDefinitionText ~env ~pos: loc.Warnings. loc_start
109+ else " "
110+ in
111+ Markdown. divider
112+ ^ (if supportsMarkdownLinks then Markdown. spacing else " " )
113+ ^ Markdown. codeBlock
114+ (decl
115+ |> Shared. declToString ~print NameAsIs:true
116+ (SharedTypes. pathIdentToString path))
117+ ^ linkToTypeDefinitionStr ^ " \n " )
118+
103119(* Produces a hover with relevant types expanded in the main type being hovered. *)
104120let hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ =
105121 let typeString = Markdown. codeBlock (typ |> Shared. typeToString) in
106- let types = findRelevantTypesFromType typ ~file ~package in
107- let typeDefinitions =
108- types
109- |> List. map (fun {decl; env; loc; path} ->
110- let linkToTypeDefinitionStr =
111- if supportsMarkdownLinks then
112- Markdown. goToDefinitionText ~env ~pos: loc.Warnings. loc_start
113- else " "
114- in
115- Markdown. divider
116- ^ (if supportsMarkdownLinks then Markdown. spacing else " " )
117- ^ Markdown. codeBlock
118- (decl
119- |> Shared. declToString ~print NameAsIs:true
120- (SharedTypes. pathIdentToString path))
121- ^ linkToTypeDefinitionStr ^ " \n " )
122- in
123- typeString :: typeDefinitions |> String. concat " \n "
122+ typeString :: expandTypes ~file ~package ~supports MarkdownLinks typ
123+ |> String. concat " \n "
124124
125125(* Leverages autocomplete functionality to produce a hover for a position. This
126126 makes it (most often) work with unsaved content. *)
@@ -166,9 +166,14 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
166166
167167let newHover ~full :{file; package} ~supportsMarkdownLinks locItem =
168168 match locItem.locType with
169- | TypeDefinition (name , decl , _stamp ) ->
170- let typeDef = Shared. declToString name decl in
171- Some (Markdown. codeBlock typeDef)
169+ | TypeDefinition (name , decl , _stamp ) -> (
170+ let typeDef = Markdown. codeBlock (Shared. declToString name decl) in
171+ match decl.type_manifest with
172+ | None -> Some typeDef
173+ | Some typ ->
174+ Some
175+ (typeDef :: expandTypes ~file ~package ~supports MarkdownLinks typ
176+ |> String. concat " \n " ))
172177 | LModule (Definition (stamp, _tip)) | LModule (LocalReference (stamp, _tip))
173178 -> (
174179 match Stamps. findModule file.stamps stamp with
0 commit comments