Skip to content

Commit 18c79cf

Browse files
authored
Fix parameter name hints crashing with multi-line arguments (#15004)
1 parent d71fde9 commit 18c79cf

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open FSharp.Compiler.EditorServices
99
open FSharp.Compiler.Symbols
1010
open FSharp.Compiler.Text
1111
open Hints
12+
open Microsoft.VisualStudio.FSharp.Editor
1213

1314
module InlineParameterNameHints =
1415

@@ -56,10 +57,8 @@ module InlineParameterNameHints =
5657
>> Seq.contains range
5758

5859
let private getSourceTextAtRange (sourceText: SourceText) (range: range) =
59-
60-
let line = sourceText.Lines[ range.Start.Line - 1 ].ToString()
61-
let length = range.EndColumn - range.StartColumn
62-
line.Substring(range.Start.Column, length)
60+
(RoslynHelpers.FSharpRangeToTextSpan(sourceText, range) |> sourceText.GetSubText)
61+
.ToString()
6362

6463
let isMemberOrFunctionOrValueValidForHint (symbol: FSharpMemberOrFunctionOrValue) (symbolUse: FSharpSymbolUse) =
6564

vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ let q = query { for x in { 1 .. 10 } do select x }
494494
Assert.Empty actual
495495

496496
[<Fact>]
497-
let ``Hints are not shown when parameter names coinside with variable names`` () =
497+
let ``Hints are not shown when parameter names coincide with variable names`` () =
498498
let code =
499499
"""
500500
let getFullName name surname = $"{name} {surname}"
@@ -517,3 +517,28 @@ let fullName = getFullName name lastName
517517
let actual = getParameterNameHints document
518518

519519
Assert.Equal(expected, actual)
520+
521+
[<Fact>]
522+
let ``Hints don't break with multi-line arguments`` () =
523+
let code =
524+
"""
525+
None
526+
|> Option.map (fun x ->
527+
x + 5
528+
)
529+
|> ignore
530+
"""
531+
532+
let document = getFsDocument code
533+
534+
let expected =
535+
[
536+
{
537+
Content = "mapping = "
538+
Location = (2, 15)
539+
}
540+
]
541+
542+
let actual = getParameterNameHints document
543+
544+
Assert.Equal(expected, actual)

0 commit comments

Comments
 (0)