Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion vsintegration/src/FSharp.Editor/Hints/InlineTypeHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -46,6 +55,7 @@ module InlineTypeHints =
not symbol.IsConstructorThisValue

symbol.IsValue // we'll be adding other stuff gradually here
&& isSolved symbol
&& isNotAnnotatedManually
&& isNotAfterDot
&& isNotTypeAlias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)