未验证 提交 71b6329f 编写于 作者: P Petr 提交者: GitHub

Making inline type hints less intrusive (#14386)

* Make inline type hints less intrusive

* Update

* Reverting the breaking change

* IWSAM

* update

* extra tests
上级 23e22ead
......@@ -30,11 +30,20 @@ module InlineTypeHints =
Parts = getHintParts symbol symbolUse
}
let private isSolved (symbol: FSharpMemberOrFunctionOrValue) =
if symbol.GenericParameters.Count > 0
then symbol.GenericParameters |> Seq.forall (fun p -> p.IsSolveAtCompileTime)
elif symbol.FullType.IsGenericParameter
then symbol.FullType.GenericParameter.DisplayNameCore <> "?"
else true
let isValidForHint
(parseFileResults: FSharpParseFileResults)
(symbol: FSharpMemberOrFunctionOrValue)
(symbolUse: FSharpSymbolUse) =
let isNotAnnotatedManually =
not (parseFileResults.IsTypeAnnotationGivenAtPosition symbolUse.Range.Start)
......@@ -46,6 +55,7 @@ module InlineTypeHints =
not symbol.IsConstructorThisValue
symbol.IsValue // we'll be adding other stuff gradually here
&& isSolved symbol
&& isNotAnnotatedManually
&& isNotAfterDot
&& isNotTypeAlias
......
......@@ -183,3 +183,67 @@ let zip4 (l1: 'a list) (l2: 'b list) (l3: 'c list) (l4: 'd list) =
let actual = getTypeHints document
CollectionAssert.AreEquivalent(expected, actual)
[<Test>]
let ``Hints are not shown for unfinished expressions`` () =
let code =
"""
let x
"""
let document = getFsDocument code
let result = getTypeHints document
Assert.IsEmpty(result)
[<Test>]
let ``Hints are not shown for unsolved types in _for_ expressions in collections`` () =
let code =
"""
let _ = [ for x ]
"""
let document = getFsDocument code
let result = getTypeHints document
Assert.IsEmpty(result)
[<Test>]
let ``Hints are not shown for unsolved types in _for_ expressions within computational expressions`` () =
let code =
"""
do task {
for x
do! Task.Delay 0
}
"""
let document = getFsDocument code
let result = getTypeHints document
Assert.IsEmpty(result)
[<Test>]
let ``Hints are shown for IWSAM`` () =
let code =
"""
type IAddition<'T when 'T :> IAddition<'T>> =
static abstract op_Addition: 'T * 'T -> 'T
type Number<'T when IAddition<'T>>(value: 'T) =
member _.Value with get() = value
interface IAddition<Number<'T>> with
static member op_Addition(a, b) = Number(a.Value + b.Value)
"""
let document = getFsDocument code
let expected =
[
{ Content = ": Number<'T>"; Location = (7, 36) }
{ Content = ": Number<'T>"; Location = (7, 39) }
]
let actual = getTypeHints document
CollectionAssert.AreEquivalent(expected, actual)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册