Skip to content

Commit

Permalink
Fix parameter name hints crashing with multi-line arguments (#15004)
Browse files Browse the repository at this point in the history
  • Loading branch information
0101 authored Mar 30, 2023
1 parent d71fde9 commit 18c79cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down Expand Up @@ -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) =

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ let q = query { for x in { 1 .. 10 } do select x }
Assert.Empty actual

[<Fact>]
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}"
Expand All @@ -517,3 +517,28 @@ let fullName = getFullName name lastName
let actual = getParameterNameHints document

Assert.Equal(expected, actual)

[<Fact>]
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)

0 comments on commit 18c79cf

Please sign in to comment.