Skip to content
Merged
12 changes: 4 additions & 8 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ type internal TypeCheckInfo
}

let toolTipElement =
FormatStructuredDescriptionOfItem displayFullName infoReader accessorDomain m denv itemWithInst None
FormatStructuredDescriptionOfItem displayFullName infoReader accessorDomain m denv itemWithInst (Some symbol) None

ToolTipText [ toolTipElement ]

Expand Down Expand Up @@ -1757,7 +1757,8 @@ type internal TypeCheckInfo
ToolTipText(
items
|> List.map (fun x ->
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst width)
let symbol = Some(FSharpSymbol.Create(cenv, x.Item))
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst symbol width)
))

(fun err ->
Expand Down Expand Up @@ -2716,12 +2717,7 @@ type FSharpCheckFileResults
| None -> ()
| Some kwDescription ->
let kwText = kw |> TaggedText.tagKeyword |> wordL |> LayoutRender.toArray
let kwTip = ToolTipElementData.Create(kwText, FSharpXmlDoc.None)

let descText = kwDescription |> TaggedText.tagText |> wordL |> LayoutRender.toArray
let descTip = ToolTipElementData.Create(descText, FSharpXmlDoc.None)

yield ToolTipElement.Group [ kwTip; descTip ]
yield ToolTipElement.Single(kwText, FSharpXmlDoc.FromXmlText(Xml.XmlDoc([| kwDescription |], range.Zero)))
]

/// Resolve the names at the given location to give a data tip
Expand Down
77 changes: 40 additions & 37 deletions src/Compiler/Service/ServiceDeclarationLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ open FSharp.Compiler.TypedTreeOps
/// A single data tip display element
[<RequireQualifiedAccess>]
type ToolTipElementData =
{ MainDescription: TaggedText[]
{
Symbol: FSharpSymbol option
MainDescription: TaggedText[]
XmlDoc: FSharpXmlDoc
TypeMapping: TaggedText[] list
Remarks: TaggedText[] option
ParamName : string option }

static member internal Create(layout, xml, ?typeMapping, ?paramName, ?remarks) =
{ MainDescription=layout; XmlDoc=xml; TypeMapping=defaultArg typeMapping []; ParamName=paramName; Remarks=remarks }
static member internal Create(layout, xml, ?typeMapping, ?paramName, ?remarks, ?symbol) =
{ MainDescription=layout; XmlDoc=xml; TypeMapping=defaultArg typeMapping []; ParamName=paramName; Remarks=remarks; Symbol = symbol }

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

static member Single(layout, xml, ?typeMapping, ?paramName, ?remarks) =
Group [ ToolTipElementData.Create(layout, xml, ?typeMapping=typeMapping, ?paramName=paramName, ?remarks=remarks) ]
static member Single(layout, xml, ?typeMapping, ?paramName, ?remarks, ?symbol) =
Group [ ToolTipElementData.Create(layout, xml, ?typeMapping=typeMapping, ?paramName=paramName, ?remarks=remarks, ?symbol = symbol) ]

/// Information for building a data tip box.
type ToolTipText =
Expand Down Expand Up @@ -93,7 +95,7 @@ module DeclarationListHelpers =
let emptyToolTip = ToolTipText []

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

ToolTipElement.Group layouts

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

/// Output the quick info information of a language item
let rec FormatItemDescriptionToToolTipElement displayFullName (infoReader: InfoReader) ad m denv (item: ItemWithInst) (width: int option) =
let rec FormatItemDescriptionToToolTipElement displayFullName (infoReader: InfoReader) ad m denv (item: ItemWithInst) symbol (width: int option) =
let g = infoReader.g
let amap = infoReader.amap
let denv = SimplerDisplayEnv denv
let xml = GetXmlCommentForItem infoReader m item.Item

match item.Item with
| Item.ImplicitOp(_, { contents = Some(TraitConstraintSln.FSMethSln(vref=vref)) }) ->
// operator with solution
FormatItemDescriptionToToolTipElement displayFullName infoReader ad m denv { item with Item = Item.Value vref } width
FormatItemDescriptionToToolTipElement displayFullName infoReader ad m denv { item with Item = Item.Value vref } symbol width

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

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

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

// Active pattern tags
| Item.ActivePatternCase apref ->
Expand All @@ -217,7 +220,7 @@ module DeclarationListHelpers =
let layout = toArray layout
let tpsL = List.map toArray tpsL
let remarks = toArray remarks
ToolTipElement.Single (layout, xml, tpsL, remarks=remarks)
ToolTipElement.Single (layout, xml, tpsL, remarks=remarks, ?symbol = symbol)

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

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

// F# record field names
| Item.RecdField rfinfo ->
Expand All @@ -257,7 +260,7 @@ module DeclarationListHelpers =
)
let layout = PrintUtilities.squashToWidth width layout
let layout = toArray layout
ToolTipElement.Single (layout, xml)
ToolTipElement.Single (layout, xml, ?symbol = symbol)

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

// Not used
| Item.NewDef id ->
Expand All @@ -279,7 +282,7 @@ module DeclarationListHelpers =
wordL (tagUnknownEntity id.idText)
let layout = PrintUtilities.squashToWidth width layout
let layout = toArray layout
ToolTipElement.Single (layout, xml)
ToolTipElement.Single (layout, xml, ?symbol = symbol)

// .NET fields
| Item.ILField finfo ->
Expand All @@ -299,7 +302,7 @@ module DeclarationListHelpers =
)
let layout = PrintUtilities.squashToWidth width layout
let layout = toArray layout
ToolTipElement.Single (layout, xml)
ToolTipElement.Single (layout, xml, ?symbol = symbol)

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

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

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

let layout = PrintUtilities.squashToWidth width layout
let layout = toArray layout
ToolTipElement.Single (layout, xml)
ToolTipElement.Single (layout, xml, ?symbol = symbol)

// F# constructors and methods
| Item.CtorGroup(_, minfos)
| Item.MethodGroup(_, minfos, _) ->
FormatOverloadsToList infoReader m denv item minfos width
FormatOverloadsToList infoReader m denv item minfos symbol width

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

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

// Types.
| Item.Types(_, TType_app(tcref, _, _) :: _)
Expand All @@ -395,20 +398,20 @@ module DeclarationListHelpers =
let remarks = OutputFullName displayFullName pubpathOfTyconRef fullDisplayTextOfTyconRefAsLayout tcref
let layout = toArray layout
let remarks = toArray remarks
ToolTipElement.Single (layout, xml, remarks=remarks)
ToolTipElement.Single (layout, xml, remarks=remarks, ?symbol = symbol)

// Type variables
| Item.TypeVar (_, typar) ->
let layout = NicePrint.prettyLayoutOfTypar denv typar
let layout = PrintUtilities.squashToWidth width layout
ToolTipElement.Single (toArray layout, xml)
ToolTipElement.Single (toArray layout, xml, ?symbol = symbol)

// Traits
| Item.Trait traitInfo ->
let denv = { denv with shortConstraints = false}
let layout = NicePrint.prettyLayoutOfTrait denv traitInfo
let layout = PrintUtilities.squashToWidth width layout
ToolTipElement.Single (toArray layout, xml)
ToolTipElement.Single (toArray layout, xml, ?symbol = symbol)

// F# Modules and namespaces
| Item.ModuleOrNamespaces(modref :: _ as modrefs) ->
Expand Down Expand Up @@ -449,11 +452,11 @@ module DeclarationListHelpers =
)
let layout = PrintUtilities.squashToWidth width layout
let layout = toArray layout
ToolTipElement.Single (layout, xml)
ToolTipElement.Single (layout, xml, ?symbol = symbol)
else
let layout = PrintUtilities.squashToWidth width layout
let layout = toArray layout
ToolTipElement.Single (layout, xml)
ToolTipElement.Single (layout, xml, ?symbol = symbol)

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

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

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

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

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

/// Format the structured version of a tooltip for an item
let FormatStructuredDescriptionOfItem isDecl infoReader ad m denv item width =
let FormatStructuredDescriptionOfItem isDecl infoReader ad m denv item symbol width =
DiagnosticsScope.Protect m
(fun () -> FormatItemDescriptionToToolTipElement isDecl infoReader ad m denv item width)
(fun () -> FormatItemDescriptionToToolTipElement isDecl infoReader ad m denv item symbol width)
(fun err -> ToolTipElement.CompositionError err)

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

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

let description = ToolTipText [FormatStructuredDescriptionOfItem true infoReader ad m denv { item with Item = flatItem } None]
let description = ToolTipText [FormatStructuredDescriptionOfItem true infoReader ad m denv { item with Item = flatItem } None None]

let hasParamArrayArg =
match flatItem with
Expand Down
8 changes: 5 additions & 3 deletions src/Compiler/Service/ServiceDeclarationLists.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ open FSharp.Compiler.AccessibilityLogic
[<RequireQualifiedAccess>]
type public ToolTipElementData =
{
Symbol: FSharpSymbol option

MainDescription: TaggedText[]

XmlDoc: FSharpXmlDoc
Expand All @@ -31,7 +33,7 @@ type public ToolTipElementData =
ParamName: string option
}

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

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

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

/// Information for building a tool tip box.
//
Expand Down Expand Up @@ -226,7 +228,7 @@ type public MethodGroup =
static member internal Empty: MethodGroup

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

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

Expand Down
Loading