diff --git a/vsintegration/src/FSharp.Editor/Hints/HintService.fs b/vsintegration/src/FSharp.Editor/Hints/HintService.fs index 6b23fe78506..da24834efcb 100644 --- a/vsintegration/src/FSharp.Editor/Hints/HintService.fs +++ b/vsintegration/src/FSharp.Editor/Hints/HintService.fs @@ -6,32 +6,37 @@ open Microsoft.CodeAnalysis open Microsoft.VisualStudio.FSharp.Editor open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.Symbols +open FSharp.Compiler.Text open Hints module HintService = - let private getHintsForSymbol parseResults hintKinds (symbolUse: FSharpSymbolUse) = + let private getHintsForSymbol parseResults hintKinds (longIdEndLocations: Position list) (symbolUse: FSharpSymbolUse) = match symbolUse.Symbol with | :? FSharpMemberOrFunctionOrValue as symbol when hintKinds |> Set.contains HintKind.TypeHint && InlineTypeHints.isValidForHint parseResults symbol symbolUse -> - InlineTypeHints.getHints symbol symbolUse + InlineTypeHints.getHints symbol symbolUse, + longIdEndLocations | :? FSharpMemberOrFunctionOrValue as symbol when hintKinds |> Set.contains HintKind.ParameterNameHint && InlineParameterNameHints.isMemberOrFunctionOrValueValidForHint symbol symbolUse -> - InlineParameterNameHints.getHintsForMemberOrFunctionOrValue parseResults symbol symbolUse + InlineParameterNameHints.getHintsForMemberOrFunctionOrValue parseResults symbol symbolUse longIdEndLocations, + symbolUse.Range.End :: longIdEndLocations | :? FSharpUnionCase as symbol when hintKinds |> Set.contains HintKind.ParameterNameHint && InlineParameterNameHints.isUnionCaseValidForHint symbol symbolUse -> - InlineParameterNameHints.getHintsForUnionCase parseResults symbol symbolUse + InlineParameterNameHints.getHintsForUnionCase parseResults symbol symbolUse, + longIdEndLocations // we'll be adding other stuff gradually here | _ -> - [] + [], + longIdEndLocations let getHintsForDocument (document: Document) hintKinds userOpName cancellationToken = async { @@ -44,6 +49,8 @@ module HintService = return checkResults.GetAllUsesOfAllSymbolsInFile cancellationToken + |> Seq.mapFold (getHintsForSymbol parseResults hintKinds) [] + |> fst + |> Seq.concat |> Seq.toList - |> List.collect (getHintsForSymbol parseResults hintKinds) } diff --git a/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs b/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs index 1ec2b897ab5..d4278188329 100644 --- a/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs +++ b/vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs @@ -33,6 +33,7 @@ module InlineParameterNameHints = let private getArgumentLocations (symbolUse: FSharpSymbolUse) + (longIdEndLocations: Position list) (parseResults: FSharpParseFileResults) = let position = Position.mkPos @@ -40,6 +41,7 @@ module InlineParameterNameHints = (symbolUse.Range.End.Column + 1) parseResults.FindParameterLocations position + |> Option.filter (fun locations -> longIdEndLocations |> List.contains locations.LongIdEndLocation |> not) |> Option.map (fun locations -> locations.ArgumentLocations) |> Option.defaultValue [||] @@ -81,10 +83,11 @@ module InlineParameterNameHints = let getHintsForMemberOrFunctionOrValue (parseResults: FSharpParseFileResults) (symbol: FSharpMemberOrFunctionOrValue) - (symbolUse: FSharpSymbolUse) = + (symbolUse: FSharpSymbolUse) + (longIdEndLocations: Position list) = let parameters = symbol.CurriedParameterGroups |> Seq.concat - let argumentLocations = getArgumentLocations symbolUse parseResults + let argumentLocations = parseResults |> getArgumentLocations symbolUse longIdEndLocations let tupleRanges = argumentLocations |> getTupleRanges let curryRanges = parseResults |> getCurryRanges symbolUse diff --git a/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs b/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs index ae1aeb73298..998cb78bdce 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs @@ -448,3 +448,34 @@ type MyType() = let actual = getParameterNameHints document Assert.IsEmpty(actual) + + [] + let ``Hints are shown correctly for inner bindings`` () = + let code = + """ +let test sequences = + sequences + |> Seq.map (fun sequence -> sequence |> Seq.map (fun sequence' -> sequence' |> Seq.map (fun item -> item))) +""" + + let document = getFsDocument code + + let expected = + [ + { + Content = "mapping = " + Location = (3, 16) + } + { + Content = "mapping = " + Location = (3, 53) + } + { + Content = "mapping = " + Location = (3, 92) + } + ] + + let actual = getParameterNameHints document + + Assert.AreEqual(expected, actual) \ No newline at end of file