Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1764,13 +1764,27 @@ type internal TypeCheckInfo
match declItemsOpt with
| None -> emptyToolTip
| Some (items, denv, _, m) ->
ToolTipText(
items
|> List.map (fun x ->
let symbol = Some(FSharpSymbol.Create(cenv, x.Item))
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst symbol width)
))
let mkToolTipText (items: CompletionItem list) =
ToolTipText(
items
|> List.map (fun x ->
let symbol = Some(FSharpSymbol.Create(cenv, x.Item))
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst symbol width)
)

match items with
| [ getItem; setItem ] ->
match getItem.Item, setItem.Item with
| Item.Value vr1, Item.Value vr2 when vr1.PropertyName = vr2.PropertyName ->
let getItem =
if (vr1.CompiledName None).StartsWith "get_" then
getItem
else
setItem

mkToolTipText [ getItem ]
| _ -> mkToolTipText items
| items -> mkToolTipText items)
(fun err ->
Trace.TraceInformation(sprintf "FCS: recovering from error in GetStructuredToolTipText: '%s'" err)
ToolTipText [ ToolTipElement.CompositionError err ])
Expand Down
27 changes: 27 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/TooltipTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,30 @@ c.Abc
"""

testToolTipSquashing source 7 5 "c.Abc" [ "c"; "Abc" ] FSharpTokenTag.Identifier

[<Test>]
let ``Auto property should display a single tool tip`` () =
let source = """
namespace Foo

/// Some comment on class
type Bar() =
/// Some comment on class member
member val Foo = "bla" with get, set
"""
let fileName, options =
mkTestFileAndOptions
source
Array.empty
let _, checkResults = parseAndCheckFile fileName source options
let (ToolTipText(items)) = checkResults.GetToolTip(7, 18, " member val Foo = \"bla\" with get, set", [ "Foo" ], FSharpTokenTag.Identifier)
Assert.True (items.Length = 1)
match items.[0] with
| ToolTipElement.Group [ { MainDescription = description } ] ->
let toolTipText =
description
|> Array.map (fun taggedText -> taggedText.Text)
|> String.concat ""

Assert.AreEqual("member Bar.Foo: string", toolTipText)
| _ -> Assert.Fail $"Expected group, got {items.[0]}"