зеркало из https://github.com/dotnet/fsharp.git
Fixing hints for custom ops (#15119)
This commit is contained in:
Родитель
a766f25ccc
Коммит
ef89c6922f
|
@ -54,6 +54,9 @@ type InlineParameterNameHints(parseResults: FSharpParseFileResults) =
|
|||
>> Seq.map (fun location -> location.ArgumentRange)
|
||||
>> Seq.contains range
|
||||
|
||||
let isCustomOperation (symbol: FSharpMemberOrFunctionOrValue) =
|
||||
symbol.HasAttribute<CustomOperationAttribute>()
|
||||
|
||||
let getSourceTextAtRange (sourceText: SourceText) (range: range) =
|
||||
(RoslynHelpers.FSharpRangeToTextSpan(sourceText, range) |> sourceText.GetSubText)
|
||||
.ToString()
|
||||
|
@ -65,11 +68,9 @@ type InlineParameterNameHints(parseResults: FSharpParseFileResults) =
|
|||
symbol.DeclaringEntity
|
||||
|> Option.exists (fun entity -> entity.CompiledName <> "Operators")
|
||||
|
||||
let isNotCustomOperation = not <| symbol.HasAttribute<CustomOperationAttribute>()
|
||||
|
||||
(symbol.IsFunction && isNotBuiltInOperator) // arguably, hints for those would be rather useless
|
||||
|| symbol.IsConstructor
|
||||
|| (symbol.IsMethod && isNotCustomOperation)
|
||||
|| symbol.IsMethod
|
||||
else
|
||||
false
|
||||
|
||||
|
@ -100,8 +101,10 @@ type InlineParameterNameHints(parseResults: FSharpParseFileResults) =
|
|||
|> Seq.filter (fun range -> argumentLocations |> (not << isNamedArgument range))
|
||||
|
||||
let argumentNames = Seq.map (getSourceTextAtRange sourceText) ranges
|
||||
let skipped = if symbol |> isCustomOperation then 1 else 0
|
||||
|
||||
parameters
|
||||
|> Seq.skip skipped
|
||||
|> Seq.zip ranges // Seq.zip is important as List.zip requires equal lengths
|
||||
|> Seq.where (snd >> parameterNameExists)
|
||||
|> Seq.zip argumentNames
|
||||
|
|
|
@ -481,7 +481,7 @@ let test sequences =
|
|||
Assert.Equal(expected, actual)
|
||||
|
||||
[<Fact>]
|
||||
let ``Hints are not shown when CustomOperation attribute is detected`` () =
|
||||
let ``Hints are shown correctly for custom operations`` () =
|
||||
let code =
|
||||
"""
|
||||
let q = query { for x in { 1 .. 10 } do select x }
|
||||
|
@ -489,9 +489,30 @@ let q = query { for x in { 1 .. 10 } do select x }
|
|||
|
||||
let document = getFsDocument code
|
||||
|
||||
let expected =
|
||||
[
|
||||
{
|
||||
Content = "projection = "
|
||||
Location = (1, 48)
|
||||
}
|
||||
]
|
||||
|
||||
let actual = getParameterNameHints document
|
||||
|
||||
Assert.Empty actual
|
||||
Assert.Equal(expected, actual)
|
||||
|
||||
[<Fact>]
|
||||
let ``Hints are not shown for custom operations with only 1 parameter`` () =
|
||||
let code =
|
||||
"""
|
||||
let q = query { for _ in { 1 .. 10 } do count }
|
||||
"""
|
||||
|
||||
let document = getFsDocument code
|
||||
|
||||
let actual = getParameterNameHints document
|
||||
|
||||
Assert.Empty(actual)
|
||||
|
||||
[<Fact>]
|
||||
let ``Hints are not shown when parameter names coincide with variable names`` () =
|
||||
|
|
Загрузка…
Ссылка в новой задаче