未验证 提交 ddc4a7d7 编写于 作者: D dotnet bot 提交者: GitHub

Merge pull request #14451 from dotnet/merges/main-to-release/dev17.5

Merge main to release/dev17.5
......@@ -30,6 +30,27 @@ module InlineParameterNameHints =
let private doesFieldNameExist (field: FSharpField) =
not field.IsNameGenerated
let private getTupleRanges
(symbolUse: FSharpSymbolUse)
(parseResults: FSharpParseFileResults) =
let position = Position.mkPos
(symbolUse.Range.End.Line)
(symbolUse.Range.End.Column + 1)
parseResults.FindParameterLocations position
|> Option.map (fun locations -> locations.ArgumentLocations)
|> Option.map (Seq.map (fun location -> location.ArgumentRange))
|> Option.defaultValue []
|> Seq.toList
let private getCurryRanges
(symbolUse: FSharpSymbolUse)
(parseResults: FSharpParseFileResults) =
parseResults.GetAllArgumentsForFunctionApplicationAtPosition symbolUse.Range.Start
|> Option.defaultValue []
let isMemberOrFunctionOrValueValidForHint (symbol: FSharpMemberOrFunctionOrValue) (symbolUse: FSharpSymbolUse) =
if symbolUse.IsFromUse then
let isNotBuiltInOperator =
......@@ -52,18 +73,16 @@ module InlineParameterNameHints =
(symbolUse: FSharpSymbolUse) =
let parameters = symbol.CurriedParameterGroups |> Seq.concat
let ranges = parseResults.GetAllArgumentsForFunctionApplicationAtPosition symbolUse.Range.Start
match ranges with
| Some ranges ->
parameters
|> Seq.zip ranges
|> Seq.where (snd >> doesParameterNameExist)
|> Seq.map getParameterHint
|> Seq.toList
// this is the case at least for custom operators
| None -> []
let tupleRanges = parseResults |> getTupleRanges symbolUse
let curryRanges = parseResults |> getCurryRanges symbolUse
let ranges = if tupleRanges |> (not << Seq.isEmpty) then tupleRanges else curryRanges
parameters
|> Seq.zip ranges // Seq.zip is important as List.zip requires equal lengths
|> Seq.where (snd >> doesParameterNameExist)
|> Seq.map getParameterHint
|> Seq.toList
let getHintsForUnionCase
(parseResults: FSharpParseFileResults)
......
......@@ -32,7 +32,9 @@ module HintTestFramework =
let getFsDocument code =
use project = SingleFileProject code
let fileName = fst project.Files.Head
let document, _ = RoslynTestHelpers.CreateSingleDocumentSolution(fileName, code)
// I don't know, without this lib some symbols are just not loaded
let options = { project.Options with OtherOptions = [| "--targetprofile:netcore" |] }
let document, _ = RoslynTestHelpers.CreateSingleDocumentSolution(fileName, code, options)
document
let getFsiAndFsDocuments (fsiCode: string) (fsCode: string) =
......
......@@ -381,3 +381,28 @@ type X =
let actual = getParameterNameHints document
Assert.IsEmpty(actual)
[<Test>]
let ``Hints are not shown in front of indexes`` () =
let code =
"""
let x = "test".Split("").[0].Split("");
"""
let document = getFsDocument code
let expected =
[
{
Content = "separator = "
Location = (1, 22)
}
{
Content = "separator = "
Location = (1, 36)
}
]
let actual = getParameterNameHints document
Assert.AreEqual(expected, actual)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册