Skip to content

Commit f0154fb

Browse files
authored
VS: Some further QuickInfo improvements (#14995)
* first shot * wip * reduce diff * hide params * fix ugly hack * feedback * fix
1 parent a92a938 commit f0154fb

File tree

15 files changed

+473
-606
lines changed

15 files changed

+473
-606
lines changed

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ type internal TypeCheckInfo
17261726
}
17271727

17281728
let toolTipElement =
1729-
FormatStructuredDescriptionOfItem displayFullName infoReader accessorDomain m denv itemWithInst None
1729+
FormatStructuredDescriptionOfItem displayFullName infoReader accessorDomain m denv itemWithInst (Some symbol) None
17301730

17311731
ToolTipText [ toolTipElement ]
17321732

@@ -1757,7 +1757,8 @@ type internal TypeCheckInfo
17571757
ToolTipText(
17581758
items
17591759
|> List.map (fun x ->
1760-
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst width)
1760+
let symbol = Some(FSharpSymbol.Create(cenv, x.Item))
1761+
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst symbol width)
17611762
))
17621763

17631764
(fun err ->
@@ -2716,12 +2717,7 @@ type FSharpCheckFileResults
27162717
| None -> ()
27172718
| Some kwDescription ->
27182719
let kwText = kw |> TaggedText.tagKeyword |> wordL |> LayoutRender.toArray
2719-
let kwTip = ToolTipElementData.Create(kwText, FSharpXmlDoc.None)
2720-
2721-
let descText = kwDescription |> TaggedText.tagText |> wordL |> LayoutRender.toArray
2722-
let descTip = ToolTipElementData.Create(descText, FSharpXmlDoc.None)
2723-
2724-
yield ToolTipElement.Group [ kwTip; descTip ]
2720+
yield ToolTipElement.Single(kwText, FSharpXmlDoc.FromXmlText(Xml.XmlDoc([| kwDescription |], range.Zero)))
27252721
]
27262722

27272723
/// Resolve the names at the given location to give a data tip

src/Compiler/Service/ServiceDeclarationLists.fs

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ open FSharp.Compiler.TypedTreeOps
3434
/// A single data tip display element
3535
[<RequireQualifiedAccess>]
3636
type ToolTipElementData =
37-
{ MainDescription: TaggedText[]
37+
{
38+
Symbol: FSharpSymbol option
39+
MainDescription: TaggedText[]
3840
XmlDoc: FSharpXmlDoc
3941
TypeMapping: TaggedText[] list
4042
Remarks: TaggedText[] option
4143
ParamName : string option }
4244

43-
static member internal Create(layout, xml, ?typeMapping, ?paramName, ?remarks) =
44-
{ MainDescription=layout; XmlDoc=xml; TypeMapping=defaultArg typeMapping []; ParamName=paramName; Remarks=remarks }
45+
static member internal Create(layout, xml, ?typeMapping, ?paramName, ?remarks, ?symbol) =
46+
{ MainDescription=layout; XmlDoc=xml; TypeMapping=defaultArg typeMapping []; ParamName=paramName; Remarks=remarks; Symbol = symbol }
4547

4648
/// A single data tip display element
4749
[<RequireQualifiedAccess>]
@@ -54,8 +56,8 @@ type ToolTipElement =
5456
/// An error occurred formatting this element
5557
| CompositionError of errorText: string
5658

57-
static member Single(layout, xml, ?typeMapping, ?paramName, ?remarks) =
58-
Group [ ToolTipElementData.Create(layout, xml, ?typeMapping=typeMapping, ?paramName=paramName, ?remarks=remarks) ]
59+
static member Single(layout, xml, ?typeMapping, ?paramName, ?remarks, ?symbol) =
60+
Group [ ToolTipElementData.Create(layout, xml, ?typeMapping=typeMapping, ?paramName=paramName, ?remarks=remarks, ?symbol = symbol) ]
5961

6062
/// Information for building a data tip box.
6163
type ToolTipText =
@@ -93,7 +95,7 @@ module DeclarationListHelpers =
9395
let emptyToolTip = ToolTipText []
9496

9597
/// Generate the structured tooltip for a method info
96-
let FormatOverloadsToList (infoReader: InfoReader) m denv (item: ItemWithInst) minfos (width: int option) : ToolTipElement =
98+
let FormatOverloadsToList (infoReader: InfoReader) m denv (item: ItemWithInst) minfos symbol (width: int option) : ToolTipElement =
9799
ToolTipFault |> Option.iter (fun msg ->
98100
let exn = Error((0, msg), range.Zero)
99101
let ph = PhasedDiagnostic.Create(exn, BuildPhase.TypeCheck)
@@ -107,7 +109,7 @@ module DeclarationListHelpers =
107109
let layout = PrintUtilities.squashToWidth width layout
108110
let layout = toArray layout
109111
let tpsL = List.map toArray tpsL
110-
ToolTipElementData.Create(layout, xml, tpsL) ]
112+
ToolTipElementData.Create(layout, xml, tpsL, ?symbol = symbol) ]
111113

112114
ToolTipElement.Group layouts
113115

@@ -149,15 +151,16 @@ module DeclarationListHelpers =
149151
let pubpathOfTyconRef (x: TyconRef) = x.PublicPath
150152

151153
/// Output the quick info information of a language item
152-
let rec FormatItemDescriptionToToolTipElement displayFullName (infoReader: InfoReader) ad m denv (item: ItemWithInst) (width: int option) =
154+
let rec FormatItemDescriptionToToolTipElement displayFullName (infoReader: InfoReader) ad m denv (item: ItemWithInst) symbol (width: int option) =
153155
let g = infoReader.g
154156
let amap = infoReader.amap
155157
let denv = SimplerDisplayEnv denv
156158
let xml = GetXmlCommentForItem infoReader m item.Item
159+
157160
match item.Item with
158161
| Item.ImplicitOp(_, { contents = Some(TraitConstraintSln.FSMethSln(vref=vref)) }) ->
159162
// operator with solution
160-
FormatItemDescriptionToToolTipElement displayFullName infoReader ad m denv { item with Item = Item.Value vref } width
163+
FormatItemDescriptionToToolTipElement displayFullName infoReader ad m denv { item with Item = Item.Value vref } symbol width
161164

162165
| Item.Value vref | Item.CustomBuilder (_, vref) ->
163166
let prettyTyparInst, resL = NicePrint.layoutQualifiedValOrMember denv infoReader item.TyparInstantiation vref
@@ -167,7 +170,7 @@ module DeclarationListHelpers =
167170
let resL = PrintUtilities.squashToWidth width resL
168171
let resL = toArray resL
169172
let remarks = toArray remarks
170-
ToolTipElement.Single(resL, xml, tpsL, remarks=remarks)
173+
ToolTipElement.Single(resL, xml, tpsL, remarks=remarks, ?symbol = symbol)
171174

172175
// Union tags (constructors)
173176
| Item.UnionCase(ucinfo, _) ->
@@ -184,7 +187,7 @@ module DeclarationListHelpers =
184187
NicePrint.layoutType denv unionTy
185188
let layout = PrintUtilities.squashToWidth width layout
186189
let layout = toArray layout
187-
ToolTipElement.Single (layout, xml)
190+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
188191

189192
// Active pattern tag inside the declaration (result)
190193
| Item.ActivePatternResult(apinfo, ty, idx, _) ->
@@ -196,7 +199,7 @@ module DeclarationListHelpers =
196199
NicePrint.layoutType denv ty
197200
let layout = PrintUtilities.squashToWidth width layout
198201
let layout = toArray layout
199-
ToolTipElement.Single (layout, xml)
202+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
200203

201204
// Active pattern tags
202205
| Item.ActivePatternCase apref ->
@@ -217,7 +220,7 @@ module DeclarationListHelpers =
217220
let layout = toArray layout
218221
let tpsL = List.map toArray tpsL
219222
let remarks = toArray remarks
220-
ToolTipElement.Single (layout, xml, tpsL, remarks=remarks)
223+
ToolTipElement.Single (layout, xml, tpsL, remarks=remarks, ?symbol = symbol)
221224

222225
// F# exception names
223226
| Item.ExnCase ecref ->
@@ -226,7 +229,7 @@ module DeclarationListHelpers =
226229
let remarks = OutputFullName displayFullName pubpathOfTyconRef fullDisplayTextOfExnRefAsLayout ecref
227230
let layout = toArray layout
228231
let remarks = toArray remarks
229-
ToolTipElement.Single (layout, xml, remarks=remarks)
232+
ToolTipElement.Single (layout, xml, remarks=remarks, ?symbol = symbol)
230233

231234
| Item.RecdField rfinfo when rfinfo.TyconRef.IsFSharpException ->
232235
let ty, _ = PrettyTypes.PrettifyType g rfinfo.FieldType
@@ -238,7 +241,7 @@ module DeclarationListHelpers =
238241
NicePrint.layoutType denv ty
239242
let layout = PrintUtilities.squashToWidth width layout
240243
let layout = toArray layout
241-
ToolTipElement.Single (layout, xml, paramName = id)
244+
ToolTipElement.Single (layout, xml, paramName = id, ?symbol = symbol)
242245

243246
// F# record field names
244247
| Item.RecdField rfinfo ->
@@ -257,7 +260,7 @@ module DeclarationListHelpers =
257260
)
258261
let layout = PrintUtilities.squashToWidth width layout
259262
let layout = toArray layout
260-
ToolTipElement.Single (layout, xml)
263+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
261264

262265
| Item.UnionCaseField (ucinfo, fieldIndex) ->
263266
let rfield = ucinfo.UnionCase.GetFieldByIndex(fieldIndex)
@@ -270,7 +273,7 @@ module DeclarationListHelpers =
270273
NicePrint.layoutType denv fieldTy
271274
let layout = PrintUtilities.squashToWidth width layout
272275
let layout = toArray layout
273-
ToolTipElement.Single (layout, xml, paramName = id.idText)
276+
ToolTipElement.Single (layout, xml, paramName = id.idText, ?symbol = symbol)
274277

275278
// Not used
276279
| Item.NewDef id ->
@@ -279,7 +282,7 @@ module DeclarationListHelpers =
279282
wordL (tagUnknownEntity id.idText)
280283
let layout = PrintUtilities.squashToWidth width layout
281284
let layout = toArray layout
282-
ToolTipElement.Single (layout, xml)
285+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
283286

284287
// .NET fields
285288
| Item.ILField finfo ->
@@ -299,7 +302,7 @@ module DeclarationListHelpers =
299302
)
300303
let layout = PrintUtilities.squashToWidth width layout
301304
let layout = toArray layout
302-
ToolTipElement.Single (layout, xml)
305+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
303306

304307
// .NET events
305308
| Item.Event einfo ->
@@ -314,14 +317,14 @@ module DeclarationListHelpers =
314317
NicePrint.layoutType denv eventTy
315318
let layout = PrintUtilities.squashToWidth width layout
316319
let layout = toArray layout
317-
ToolTipElement.Single (layout, xml)
320+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
318321

319322
// F# and .NET properties
320323
| Item.Property(_, pinfo :: _) ->
321324
let layout = NicePrint.prettyLayoutOfPropInfoFreeStyle g amap m denv pinfo
322325
let layout = PrintUtilities.squashToWidth width layout
323326
let layout = toArray layout
324-
ToolTipElement.Single (layout, xml)
327+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
325328

326329
// Custom operations in queries
327330
| Item.CustomOperation (customOpName, usageText, Some minfo) ->
@@ -348,12 +351,12 @@ module DeclarationListHelpers =
348351

349352
let layout = PrintUtilities.squashToWidth width layout
350353
let layout = toArray layout
351-
ToolTipElement.Single (layout, xml)
354+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
352355

353356
// F# constructors and methods
354357
| Item.CtorGroup(_, minfos)
355358
| Item.MethodGroup(_, minfos, _) ->
356-
FormatOverloadsToList infoReader m denv item minfos width
359+
FormatOverloadsToList infoReader m denv item minfos symbol width
357360

358361
// The 'fake' zero-argument constructors of .NET interfaces.
359362
// This ideally should never appear in intellisense, but we do get here in repros like:
@@ -365,7 +368,7 @@ module DeclarationListHelpers =
365368
let layout = NicePrint.layoutTyconRef denv (tcrefOfAppTy g ty)
366369
let layout = PrintUtilities.squashToWidth width layout
367370
let layout = toArray layout
368-
ToolTipElement.Single(layout, xml)
371+
ToolTipElement.Single(layout, xml, ?symbol = symbol)
369372

370373
// The 'fake' representation of constructors of .NET delegate types
371374
| Item.DelegateCtor delTy ->
@@ -378,7 +381,7 @@ module DeclarationListHelpers =
378381
RightL.rightParen
379382
let layout = PrintUtilities.squashToWidth width layout
380383
let layout = toArray layout
381-
ToolTipElement.Single(layout, xml)
384+
ToolTipElement.Single(layout, xml, ?symbol = symbol)
382385

383386
// Types.
384387
| Item.Types(_, TType_app(tcref, _, _) :: _)
@@ -395,20 +398,20 @@ module DeclarationListHelpers =
395398
let remarks = OutputFullName displayFullName pubpathOfTyconRef fullDisplayTextOfTyconRefAsLayout tcref
396399
let layout = toArray layout
397400
let remarks = toArray remarks
398-
ToolTipElement.Single (layout, xml, remarks=remarks)
401+
ToolTipElement.Single (layout, xml, remarks=remarks, ?symbol = symbol)
399402

400403
// Type variables
401404
| Item.TypeVar (_, typar) ->
402405
let layout = NicePrint.prettyLayoutOfTypar denv typar
403406
let layout = PrintUtilities.squashToWidth width layout
404-
ToolTipElement.Single (toArray layout, xml)
407+
ToolTipElement.Single (toArray layout, xml, ?symbol = symbol)
405408

406409
// Traits
407410
| Item.Trait traitInfo ->
408411
let denv = { denv with shortConstraints = false}
409412
let layout = NicePrint.prettyLayoutOfTrait denv traitInfo
410413
let layout = PrintUtilities.squashToWidth width layout
411-
ToolTipElement.Single (toArray layout, xml)
414+
ToolTipElement.Single (toArray layout, xml, ?symbol = symbol)
412415

413416
// F# Modules and namespaces
414417
| Item.ModuleOrNamespaces(modref :: _ as modrefs) ->
@@ -449,11 +452,11 @@ module DeclarationListHelpers =
449452
)
450453
let layout = PrintUtilities.squashToWidth width layout
451454
let layout = toArray layout
452-
ToolTipElement.Single (layout, xml)
455+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
453456
else
454457
let layout = PrintUtilities.squashToWidth width layout
455458
let layout = toArray layout
456-
ToolTipElement.Single (layout, xml)
459+
ToolTipElement.Single (layout, xml, ?symbol = symbol)
457460

458461
| Item.AnonRecdField(anon, argTys, i, _) ->
459462
let argTy = argTys[i]
@@ -466,7 +469,7 @@ module DeclarationListHelpers =
466469
NicePrint.layoutType denv argTy
467470
let layout = PrintUtilities.squashToWidth width layout
468471
let layout = toArray layout
469-
ToolTipElement.Single (layout, FSharpXmlDoc.None)
472+
ToolTipElement.Single (layout, FSharpXmlDoc.None, ?symbol = symbol)
470473

471474
// Named parameters
472475
| Item.ArgName (Some id, argTy, _, _) ->
@@ -478,10 +481,10 @@ module DeclarationListHelpers =
478481
NicePrint.layoutType denv argTy
479482
let layout = PrintUtilities.squashToWidth width layout
480483
let layout = toArray layout
481-
ToolTipElement.Single (layout, xml, paramName = id.idText)
484+
ToolTipElement.Single (layout, xml, paramName = id.idText, ?symbol = symbol)
482485

483486
| Item.SetterArg (_, item) ->
484-
FormatItemDescriptionToToolTipElement displayFullName infoReader ad m denv (ItemWithNoInst item) width
487+
FormatItemDescriptionToToolTipElement displayFullName infoReader ad m denv (ItemWithNoInst item) symbol width
485488

486489
| Item.ArgName (None, _, _, _)
487490

@@ -523,9 +526,9 @@ module DeclarationListHelpers =
523526
| Item.CustomOperation (_, _, None) -> ToolTipElement.None
524527

525528
/// Format the structured version of a tooltip for an item
526-
let FormatStructuredDescriptionOfItem isDecl infoReader ad m denv item width =
529+
let FormatStructuredDescriptionOfItem isDecl infoReader ad m denv item symbol width =
527530
DiagnosticsScope.Protect m
528-
(fun () -> FormatItemDescriptionToToolTipElement isDecl infoReader ad m denv item width)
531+
(fun () -> FormatItemDescriptionToToolTipElement isDecl infoReader ad m denv item symbol width)
529532
(fun err -> ToolTipElement.CompositionError err)
530533

531534
/// Represents one parameter for one method (or other item) in a group.
@@ -1034,7 +1037,7 @@ type DeclarationListItem(textInDeclList: string, textInCode: string, fullName: s
10341037
member _.Description =
10351038
match info with
10361039
| Choice1Of2 (items: CompletionItem list, infoReader, ad, m, denv) ->
1037-
ToolTipText(items |> List.map (fun x -> FormatStructuredDescriptionOfItem true infoReader ad m denv x.ItemWithInst None))
1040+
ToolTipText(items |> List.map (fun x -> FormatStructuredDescriptionOfItem true infoReader ad m denv x.ItemWithInst None None))
10381041
| Choice2Of2 result ->
10391042
result
10401043

@@ -1297,7 +1300,7 @@ type MethodGroup( name: string, unsortedMethods: MethodGroupItem[] ) =
12971300
(fun () -> PrettyParamsAndReturnTypeOfItem infoReader m denv { item with Item = flatItem })
12981301
(fun err -> [], wordL (tagText err))
12991302

1300-
let description = ToolTipText [FormatStructuredDescriptionOfItem true infoReader ad m denv { item with Item = flatItem } None]
1303+
let description = ToolTipText [FormatStructuredDescriptionOfItem true infoReader ad m denv { item with Item = flatItem } None None]
13011304

13021305
let hasParamArrayArg =
13031306
match flatItem with

src/Compiler/Service/ServiceDeclarationLists.fsi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ open FSharp.Compiler.AccessibilityLogic
1717
[<RequireQualifiedAccess>]
1818
type public ToolTipElementData =
1919
{
20+
Symbol: FSharpSymbol option
21+
2022
MainDescription: TaggedText[]
2123

2224
XmlDoc: FSharpXmlDoc
@@ -31,7 +33,7 @@ type public ToolTipElementData =
3133
ParamName: string option
3234
}
3335

34-
static member internal Create: layout: TaggedText[] * xml: FSharpXmlDoc * ?typeMapping: TaggedText[] list * ?paramName: string * ?remarks: TaggedText[] -> ToolTipElementData
36+
static member internal Create: layout: TaggedText[] * xml: FSharpXmlDoc * ?typeMapping: TaggedText[] list * ?paramName: string * ?remarks: TaggedText[] * ?symbol: FSharpSymbol -> ToolTipElementData
3537

3638
/// A single tool tip display element
3739
//
@@ -46,7 +48,7 @@ type public ToolTipElement =
4648
/// An error occurred formatting this element
4749
| CompositionError of errorText: string
4850

49-
static member Single: layout: TaggedText[] * xml: FSharpXmlDoc * ?typeMapping: TaggedText[] list * ?paramName: string * ?remarks: TaggedText[] -> ToolTipElement
51+
static member Single: layout: TaggedText[] * xml: FSharpXmlDoc * ?typeMapping: TaggedText[] list * ?paramName: string * ?remarks: TaggedText[] * ?symbol: FSharpSymbol -> ToolTipElement
5052

5153
/// Information for building a tool tip box.
5254
//
@@ -226,7 +228,7 @@ type public MethodGroup =
226228
static member internal Empty: MethodGroup
227229

228230
module internal DeclarationListHelpers =
229-
val FormatStructuredDescriptionOfItem: isDecl:bool -> InfoReader -> AccessorDomain -> range -> DisplayEnv -> ItemWithInst -> int option -> ToolTipElement
231+
val FormatStructuredDescriptionOfItem: isDecl:bool -> InfoReader -> AccessorDomain -> range -> DisplayEnv -> ItemWithInst -> FSharpSymbol option -> int option -> ToolTipElement
230232

231233
val RemoveDuplicateCompletionItems: TcGlobals -> CompletionItem list -> CompletionItem list
232234

0 commit comments

Comments
 (0)