From 18c79cffdbba3c1f322bc3ce03f5c067ce058436 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Thu, 30 Mar 2023 22:15:43 +0200 Subject: [PATCH] Fix parameter name hints crashing with multi-line arguments (#15004) --- .../Hints/InlineParameterNameHints.fs | 7 +++-- .../Hints/InlineParameterNameHintTests.fs | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs b/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs index ca12c191f..77ea933f2 100644 --- a/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs +++ b/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs @@ -9,6 +9,7 @@ open FSharp.Compiler.EditorServices open FSharp.Compiler.Symbols open FSharp.Compiler.Text open Hints +open Microsoft.VisualStudio.FSharp.Editor module InlineParameterNameHints = @@ -56,10 +57,8 @@ module InlineParameterNameHints = >> Seq.contains range let private getSourceTextAtRange (sourceText: SourceText) (range: range) = - - let line = sourceText.Lines[ range.Start.Line - 1 ].ToString() - let length = range.EndColumn - range.StartColumn - line.Substring(range.Start.Column, length) + (RoslynHelpers.FSharpRangeToTextSpan(sourceText, range) |> sourceText.GetSubText) + .ToString() let isMemberOrFunctionOrValueValidForHint (symbol: FSharpMemberOrFunctionOrValue) (symbolUse: FSharpSymbolUse) = diff --git a/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs b/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs index 7a44467af..46805aea4 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs @@ -494,7 +494,7 @@ let q = query { for x in { 1 .. 10 } do select x } Assert.Empty actual [] - let ``Hints are not shown when parameter names coinside with variable names`` () = + let ``Hints are not shown when parameter names coincide with variable names`` () = let code = """ let getFullName name surname = $"{name} {surname}" @@ -517,3 +517,28 @@ let fullName = getFullName name lastName let actual = getParameterNameHints document Assert.Equal(expected, actual) + + [] + let ``Hints don't break with multi-line arguments`` () = + let code = + """ +None +|> Option.map (fun x -> + x + 5 + ) +|> ignore + """ + + let document = getFsDocument code + + let expected = + [ + { + Content = "mapping = " + Location = (2, 15) + } + ] + + let actual = getParameterNameHints document + + Assert.Equal(expected, actual) -- GitLab