Skip to content

Commit c3aacd0

Browse files
authored
Fix: Inline parameter hints for inner bindings (#14506)
Fixes #14501
1 parent 0adeca4 commit c3aacd0

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,37 @@ open Microsoft.CodeAnalysis
66
open Microsoft.VisualStudio.FSharp.Editor
77
open FSharp.Compiler.CodeAnalysis
88
open FSharp.Compiler.Symbols
9+
open FSharp.Compiler.Text
910
open Hints
1011

1112
module HintService =
12-
let private getHintsForSymbol parseResults hintKinds (symbolUse: FSharpSymbolUse) =
13+
let private getHintsForSymbol parseResults hintKinds (longIdEndLocations: Position list) (symbolUse: FSharpSymbolUse) =
1314
match symbolUse.Symbol with
1415
| :? FSharpMemberOrFunctionOrValue as symbol
1516
when hintKinds |> Set.contains HintKind.TypeHint
1617
&& InlineTypeHints.isValidForHint parseResults symbol symbolUse ->
1718

18-
InlineTypeHints.getHints symbol symbolUse
19+
InlineTypeHints.getHints symbol symbolUse,
20+
longIdEndLocations
1921

2022
| :? FSharpMemberOrFunctionOrValue as symbol
2123
when hintKinds |> Set.contains HintKind.ParameterNameHint
2224
&& InlineParameterNameHints.isMemberOrFunctionOrValueValidForHint symbol symbolUse ->
2325

24-
InlineParameterNameHints.getHintsForMemberOrFunctionOrValue parseResults symbol symbolUse
26+
InlineParameterNameHints.getHintsForMemberOrFunctionOrValue parseResults symbol symbolUse longIdEndLocations,
27+
symbolUse.Range.End :: longIdEndLocations
2528

2629
| :? FSharpUnionCase as symbol
2730
when hintKinds |> Set.contains HintKind.ParameterNameHint
2831
&& InlineParameterNameHints.isUnionCaseValidForHint symbol symbolUse ->
2932

30-
InlineParameterNameHints.getHintsForUnionCase parseResults symbol symbolUse
33+
InlineParameterNameHints.getHintsForUnionCase parseResults symbol symbolUse,
34+
longIdEndLocations
3135

3236
// we'll be adding other stuff gradually here
3337
| _ ->
34-
[]
38+
[],
39+
longIdEndLocations
3540

3641
let getHintsForDocument (document: Document) hintKinds userOpName cancellationToken =
3742
async {
@@ -44,6 +49,8 @@ module HintService =
4449

4550
return
4651
checkResults.GetAllUsesOfAllSymbolsInFile cancellationToken
52+
|> Seq.mapFold (getHintsForSymbol parseResults hintKinds) []
53+
|> fst
54+
|> Seq.concat
4755
|> Seq.toList
48-
|> List.collect (getHintsForSymbol parseResults hintKinds)
4956
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ module InlineParameterNameHints =
3333

3434
let private getArgumentLocations
3535
(symbolUse: FSharpSymbolUse)
36+
(longIdEndLocations: Position list)
3637
(parseResults: FSharpParseFileResults) =
3738

3839
let position = Position.mkPos
3940
(symbolUse.Range.End.Line)
4041
(symbolUse.Range.End.Column + 1)
4142

4243
parseResults.FindParameterLocations position
44+
|> Option.filter (fun locations -> longIdEndLocations |> List.contains locations.LongIdEndLocation |> not)
4345
|> Option.map (fun locations -> locations.ArgumentLocations)
4446
|> Option.defaultValue [||]
4547

@@ -81,10 +83,11 @@ module InlineParameterNameHints =
8183
let getHintsForMemberOrFunctionOrValue
8284
(parseResults: FSharpParseFileResults)
8385
(symbol: FSharpMemberOrFunctionOrValue)
84-
(symbolUse: FSharpSymbolUse) =
86+
(symbolUse: FSharpSymbolUse)
87+
(longIdEndLocations: Position list) =
8588

8689
let parameters = symbol.CurriedParameterGroups |> Seq.concat
87-
let argumentLocations = getArgumentLocations symbolUse parseResults
90+
let argumentLocations = parseResults |> getArgumentLocations symbolUse longIdEndLocations
8891

8992
let tupleRanges = argumentLocations |> getTupleRanges
9093
let curryRanges = parseResults |> getCurryRanges symbolUse

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,34 @@ type MyType() =
448448
let actual = getParameterNameHints document
449449

450450
Assert.IsEmpty(actual)
451+
452+
[<Test>]
453+
let ``Hints are shown correctly for inner bindings`` () =
454+
let code =
455+
"""
456+
let test sequences =
457+
sequences
458+
|> Seq.map (fun sequence -> sequence |> Seq.map (fun sequence' -> sequence' |> Seq.map (fun item -> item)))
459+
"""
460+
461+
let document = getFsDocument code
462+
463+
let expected =
464+
[
465+
{
466+
Content = "mapping = "
467+
Location = (3, 16)
468+
}
469+
{
470+
Content = "mapping = "
471+
Location = (3, 53)
472+
}
473+
{
474+
Content = "mapping = "
475+
Location = (3, 92)
476+
}
477+
]
478+
479+
let actual = getParameterNameHints document
480+
481+
Assert.AreEqual(expected, actual)

0 commit comments

Comments
 (0)