Skip to content

Fix parameter name hints crashing with multi-line arguments #15004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)