From aca891fdc7a1410a92d8addf9442dea86821b5e3 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 12 Jul 2023 10:55:21 +0200 Subject: [PATCH] Detect get/set combination for GetStructuredToolTipText. --- src/Compiler/Service/FSharpCheckerResults.fs | 26 +++++++++++++----- .../TooltipTests.fs | 27 +++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 311b5a82f66..303806c69ff 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -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 ]) diff --git a/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs b/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs index 82f4245c29a..f727ba16d61 100644 --- a/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs @@ -385,3 +385,30 @@ c.Abc """ testToolTipSquashing source 7 5 "c.Abc" [ "c"; "Abc" ] FSharpTokenTag.Identifier + +[] +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]}"