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.89k stars 782 forks source link

[<RequireQualifiedAccess>] members should not show in intellisense unless fully qualified #9290

Closed isaacabraham closed 3 years ago

isaacabraham commented 4 years ago

Repro of https://github.com/ionide/ionide-vscode-fsharp/issues/1364.

Given the following code:

namespace Blah
    [<RequireQualifiedAccess>]
    type Foo = Bar | Baz | Bop

When I access the Blah namespace, I would not expect Bar, Baz or Bop to show in intellisense, but they do:

image

If you then reference one, the compiler (correctly) gives you a warning:

image

IDEs (this affect VS2019 as well as Ionide and Rider) should not present suggestions that are "wrong" and / or will lead to warnings or errors. This is also important from a discoverablility point of view for library authors - if I mark something with RQA, I also don't want intellisense clogged up with suggestions of each union case.

The only workaround I can think of is to enclose the DU in a module of the same name:

namespace Blah
    [<RequireQualifiedAccessAttribute>]
    module Foo =
        type Foo = Bar | Baz | Bop

This then behaves more-or-less as expected:

image

However this is totally unidiomatic and I would not want to do this.

cartermp commented 4 years ago

Looked into this briefly and it seems that name resolution isn't filling in all the correct data. The union case info for these cases looks like this:

[<RequireQualifiedAccess>]
type DU = A | B | C 

image

That flag should be true, so unfortunately filtering by it doesn't do anything.

forki commented 4 years ago

Yeah I debugged this multiple times and found couple of very weird things happening. Basically RQA is lost in some situations when things get passed down the tree. But I didn't find a way to fix it

Phillip Carter notifications@github.com schrieb am Mo., 8. Juni 2020, 08:10:

Looked into this briefly and it seems that name resolution isn't filling in all the correct data. The union case info for these cases looks like this:

[image: image] https://user-images.githubusercontent.com/6309070/83997783-01089080-a914-11ea-8dd7-6bad8b521b17.png

That flag should be true, so unfortunately filtering by it doesn't do anything.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dotnet/fsharp/issues/9290#issuecomment-640390693, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAOANEX3ZH7SUT2QFTVEG3RVR6GJANCNFSM4NJQKRRQ .

cartermp commented 4 years ago

Yeah this looks surprisingly tricky. I pushed a branch here if anyone is interested: https://github.com/dotnet/fsharp/compare/master...cartermp:rq-completion?expand=1

Unfortunately there are many places where this data is generated in name resolution, and most don't fill in this data. I could have also missed something in my branch, since it filling in the data doesn't appear to have an effect

Also I will note that the question of "how does one get a completion list" is horribly unorganized and confusing in the codebase

safesparrow commented 3 years ago

FWIW I don't think this affects the latest Rider 2021.2: image

I haven't checked Visual Studio and Ionide though.

dsyme commented 3 years ago

It's fixed in VS too