diff --git a/vsintegration/src/FSharp.Editor/Hints/InlineTypeHints.fs b/vsintegration/src/FSharp.Editor/Hints/InlineTypeHints.fs index 09566e051405d8a6cf13b44483630309f683e453..402eddbaef0369d58cad7afdb75e07530125aabc 100644 --- a/vsintegration/src/FSharp.Editor/Hints/InlineTypeHints.fs +++ b/vsintegration/src/FSharp.Editor/Hints/InlineTypeHints.fs @@ -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 diff --git a/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineTypeHintTests.fs b/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineTypeHintTests.fs index a8445ede5e499371dbfe2b2b655fae7e40dad9e8..0faf11e554cc0238bc42e68668fcc5db6912655a 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineTypeHintTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/Hints/InlineTypeHintTests.fs @@ -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) + + [] + let ``Hints are not shown for unfinished expressions`` () = + let code = + """ +let x +""" + let document = getFsDocument code + + let result = getTypeHints document + + Assert.IsEmpty(result) + + [] + 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) + + [] + 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) + + [] + 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> 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)