Skip to content

Commit bf11878

Browse files
authored
Fixing parameter name hints for indexes (#14442)
1 parent 98c2967 commit bf11878

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ module InlineParameterNameHints =
3030
let private doesFieldNameExist (field: FSharpField) =
3131
not field.IsNameGenerated
3232

33+
let private getTupleRanges
34+
(symbolUse: FSharpSymbolUse)
35+
(parseResults: FSharpParseFileResults) =
36+
37+
let position = Position.mkPos
38+
(symbolUse.Range.End.Line)
39+
(symbolUse.Range.End.Column + 1)
40+
41+
parseResults.FindParameterLocations position
42+
|> Option.map (fun locations -> locations.ArgumentLocations)
43+
|> Option.map (Seq.map (fun location -> location.ArgumentRange))
44+
|> Option.defaultValue []
45+
|> Seq.toList
46+
47+
let private getCurryRanges
48+
(symbolUse: FSharpSymbolUse)
49+
(parseResults: FSharpParseFileResults) =
50+
51+
parseResults.GetAllArgumentsForFunctionApplicationAtPosition symbolUse.Range.Start
52+
|> Option.defaultValue []
53+
3354
let isMemberOrFunctionOrValueValidForHint (symbol: FSharpMemberOrFunctionOrValue) (symbolUse: FSharpSymbolUse) =
3455
if symbolUse.IsFromUse then
3556
let isNotBuiltInOperator =
@@ -52,18 +73,16 @@ module InlineParameterNameHints =
5273
(symbolUse: FSharpSymbolUse) =
5374

5475
let parameters = symbol.CurriedParameterGroups |> Seq.concat
55-
let ranges = parseResults.GetAllArgumentsForFunctionApplicationAtPosition symbolUse.Range.Start
56-
57-
match ranges with
58-
| Some ranges ->
59-
parameters
60-
|> Seq.zip ranges
61-
|> Seq.where (snd >> doesParameterNameExist)
62-
|> Seq.map getParameterHint
63-
|> Seq.toList
64-
65-
// this is the case at least for custom operators
66-
| None -> []
76+
77+
let tupleRanges = parseResults |> getTupleRanges symbolUse
78+
let curryRanges = parseResults |> getCurryRanges symbolUse
79+
let ranges = if tupleRanges |> (not << Seq.isEmpty) then tupleRanges else curryRanges
80+
81+
parameters
82+
|> Seq.zip ranges // Seq.zip is important as List.zip requires equal lengths
83+
|> Seq.where (snd >> doesParameterNameExist)
84+
|> Seq.map getParameterHint
85+
|> Seq.toList
6786

6887
let getHintsForUnionCase
6988
(parseResults: FSharpParseFileResults)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ module HintTestFramework =
3232
let getFsDocument code =
3333
use project = SingleFileProject code
3434
let fileName = fst project.Files.Head
35-
let document, _ = RoslynTestHelpers.CreateSingleDocumentSolution(fileName, code)
35+
// I don't know, without this lib some symbols are just not loaded
36+
let options = { project.Options with OtherOptions = [| "--targetprofile:netcore" |] }
37+
let document, _ = RoslynTestHelpers.CreateSingleDocumentSolution(fileName, code, options)
3638
document
3739

3840
let getFsiAndFsDocuments (fsiCode: string) (fsCode: string) =

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,28 @@ type X =
381381
let actual = getParameterNameHints document
382382

383383
Assert.IsEmpty(actual)
384+
385+
[<Test>]
386+
let ``Hints are not shown in front of indexes`` () =
387+
let code =
388+
"""
389+
let x = "test".Split("").[0].Split("");
390+
"""
391+
392+
let document = getFsDocument code
393+
394+
let expected =
395+
[
396+
{
397+
Content = "separator = "
398+
Location = (1, 22)
399+
}
400+
{
401+
Content = "separator = "
402+
Location = (1, 36)
403+
}
404+
]
405+
406+
let actual = getParameterNameHints document
407+
408+
Assert.AreEqual(expected, actual)

0 commit comments

Comments
 (0)