dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 783 forks source link

`AddOpenCodeFixProvider` does not take generics into account #17150

Closed abelbraaksma closed 4 months ago

abelbraaksma commented 4 months ago

If your type name is clearly a generic name, the suggested opens from the AddOpenCodeFixProvider do not include the generic ones.

Repro steps

Type the following code in a file that does not have the collections open:

module Foo =
    let x = dict [ 1, 4] :?> IDictionary<_,_>  // FS0039 type not defined

Expected behavior

The suggestions for the type should either:

a. include only any generic types, as the current type if clearly generic b. include both generic types and non-generic ones

Actual behavior

Only the non-generic ones are shown in the list of suggestions.

image

Known workarounds

Fix it by hand instead.

Related information

I feel like the reported range for the FS0039 should include the generic part as well (as seen in the screenshot, it isn't, and therefore the code fix provider cannot trivially get enough information). I remember, though, that in a not so far away past, generic types were included in the dropdown, so this may have been a conscious removal. Yet I wonder if we could get it back?

Seen in latest RTM of VS, and seen in VS 17.10.0 Preview 7.0 on Windows 11.

kerams commented 4 months ago

https://github.com/dotnet/fsharp/issues/16155