diff --git a/src/Compiler/Facilities/RichText.fs b/src/Compiler/Facilities/RichText.fs index 13c953cd794..b0427638f9c 100644 --- a/src/Compiler/Facilities/RichText.fs +++ b/src/Compiler/Facilities/RichText.fs @@ -45,7 +45,11 @@ module RichText = let ofParts (parts: TaggedText[]) = if Array.isEmpty parts then empty else RichText(parts) - let ofTaggedText (part: TaggedText) = RichText([| part |]) + let ofTaggedText (part: TaggedText) = + if String.IsNullOrEmpty part.Text then + empty + else + RichText([| part |]) let ofTag tag (text: string) = if String.IsNullOrEmpty text then diff --git a/src/Compiler/Facilities/TextLayoutRender.fs b/src/Compiler/Facilities/TextLayoutRender.fs index a3c95148df0..540acf62f63 100644 --- a/src/Compiler/Facilities/TextLayoutRender.fs +++ b/src/Compiler/Facilities/TextLayoutRender.fs @@ -148,12 +148,17 @@ module LayoutRender = member _.Start() = NoState member _.AddText z text = - collector text + if not (String.IsNullOrEmpty text.Text) then + collector text + z member _.AddBreak rstrs n = collector TaggedText.lineBreak - collector (TaggedText.tagSpace (spaces n)) + + if n > 0 then + collector (TaggedText.tagSpace (spaces n)) + rstrs member _.AddTag z (_, _, _) = z diff --git a/tests/FSharp.Compiler.ComponentTests/Diagnostics/RichTextTests.fs b/tests/FSharp.Compiler.ComponentTests/Diagnostics/RichTextTests.fs index 70924b45dc2..e116ae18c8d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Diagnostics/RichTextTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Diagnostics/RichTextTests.fs @@ -34,6 +34,23 @@ module RichTextTests = (RichText.mkMethod "").IsEmpty |> shouldBeTrue (RichText.ofTag TextTag.Class "").IsEmpty |> shouldBeTrue + [] + let ``Empty tagged text gives empty text`` () = + (RichText.ofTaggedText (tagged TextTag.Class "")).IsEmpty |> shouldBeTrue + + [] + let ``Empty layout gives empty text`` () = + (LayoutRender.toRichText emptyL).IsEmpty |> shouldBeTrue + + [] + let ``Rendering a layout skips parts with no text`` () = + let layout = + (leftL (tagged TextTag.Text "") ^^ wordL (TaggedText.tagClass "Foo")) + @@ wordL (TaggedText.tagText "bar") + + LayoutRender.toRichText layout + |> assertRichTextParts [ TextTag.Class, "Foo"; TextTag.LineBreak, "\n"; TextTag.Text, "bar" ] + [] let ``Parts are dumped as tag and text pairs`` () = RichText.ofParts diff --git a/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs b/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs index 8144f93bf50..732118d92d5 100644 --- a/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/TooltipTests.fs @@ -1195,3 +1195,17 @@ let _ = List.m{caret}ap id [1] """ Assert.Contains("List.map", remarks) Assert.DoesNotContain("ListModule", remarks) + +[] +let ``Parameter tooltip has empty remarks`` () = + let (ToolTipText items) = + Checker.getTooltip """ +module TestNs +let bar a{caret} b = a - b +""" + match items with + | [ ToolTipElement.Group [ element ] ] -> + match element.Remarks with + | Some remarks -> Assert.True(remarks.IsEmpty, $"Expected empty remarks, got parts: %A{remarks.Parts}") + | None -> () + | _ -> failwith $"Expected a single group, got {items}"