Skip to content
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

Don't show inline hint for arguments with same names as the parameters in DU #15305

Merged
merged 1 commit into from
Jun 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion vsintegration/src/FSharp.Editor/Hints/HintService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module HintService =
|> Seq.collect (InlineParameterNameHints(parseResults).GetHintsForMemberOrFunctionOrValue sourceText symbol)
| HintKind.ParameterNameHint, (:? FSharpUnionCase as symbol) ->
symbolUses
|> Seq.collect (InlineParameterNameHints(parseResults).GetHintsForUnionCase symbol)
|> Seq.collect (InlineParameterNameHints(parseResults).GetHintsForUnionCase sourceText symbol)
| _ -> []

hintKinds |> Set.toList |> List.map getHintsPerKind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,25 @@ type InlineParameterNameHints(parseResults: FSharpParseFileResults) =
else
[]

member _.GetHintsForUnionCase (symbol: FSharpUnionCase) (symbolUse: FSharpSymbolUse) =
member _.GetHintsForUnionCase (sourceText: SourceText) (symbol: FSharpUnionCase) (symbolUse: FSharpSymbolUse) =
if isUnionCaseValidForHint symbol symbolUse then

let fields = Seq.toList symbol.Fields

let ranges =
parseResults.GetAllArgumentsForFunctionApplicationAtPosition symbolUse.Range.Start

let argumentNames =
match ranges with
| Some ranges -> (List.map (getSourceTextAtRange sourceText)) ranges
| None -> []
// When not all field values are provided (as the user is typing), don't show anything yet
match ranges with
| Some ranges when ranges.Length = fields.Length ->
fields
|> List.zip ranges
|> List.where (snd >> fieldNameExists)
|> List.map getFieldHint
|> List.zip3 argumentNames ranges
|> List.where (fun (argumentName, _, parameter) -> fieldNameExists parameter && argumentName <> parameter.DisplayName)
|> List.map (fun (_, range, parameter) -> getFieldHint (range, parameter))

| _ -> []
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,39 @@ let b = Rectangle (1, 2)

Assert.Equal(expected, actual)

[<Fact>]
let ``Hints are not shown for discriminated union case fields with the same names as arguements`` () =
let code =
"""
type Shape =
| Square of side: int
| Rectangle of width: int * height: int

let width = 5
let a = Square 1
let b = Rectangle (width, 2)
"""

let document = getFsDocument code

let expected =
[
{
Content = "side = "
Location = (6, 16)
Tooltip = "field side"
}
{
Content = "height = "
Location = (7, 27)
Tooltip = "field height"
}
]

let actual = getParameterNameHints document

Assert.Equal(expected, actual)

[<Fact>]
let ``Hints for discriminated union case fields are not shown when names are generated`` () =
let code =
Expand Down