resharper-fsharp icon indicating copy to clipboard operation
resharper-fsharp copied to clipboard

Open namespace issues

Open NinoFloris opened this issue 5 years ago • 13 comments

Few issues I've come across repeatedly:

  1. Rider sometimes adds the open above the first line (above namespace/module), not sure why
  2. Rider cannot deal very well with multiple namespaces in the same file, it gets confused where to put the open causing the open to have no effect on the code you're writing.
  3. Rider does not take AutoOpen into account when it opens from a function suggestion, causing the auto opened module to be added unnecessarily into the completion too.

NinoFloris avatar Feb 03 '20 16:02 NinoFloris

There's a related issue at the Rider tracker for it: RIDER-27924. I'm trying to fix/workaround most of the known problems with symbols import in 2020.1, and 1 and 2 are already fixed in a branch.

auduchinok avatar Feb 03 '20 17:02 auduchinok

Ah that's welcome.

About 3, I guess similarly it should take into account RequireQualifiedAccess if it doesn't already.

NinoFloris avatar Feb 03 '20 17:02 NinoFloris

Fixes for 1 and 2 are now in: 696ddaf.

@NinoFloris Could you share some particular repros for the AutoOpen and RequireQualifiedAccess case you're seeing so I could check it as well?

auduchinok avatar Feb 05 '20 11:02 auduchinok

namespace Foo
[<AutoOpen>]
module Operators = 
    let foo x = ()

namespace Bar
module Bar = 
    let bar x = foo // try to import this, result will be Operators.foo, while foo is enough.  

For RequireQualifiedAccess I don't have an example but there may be cases where today an import isn't qualified enough for DUs/modules that are annotated with RequireQualifiedAccess. It's just somewhat of a dual to AutoOpen so it may have similar issues.

I did find another issue related to imports: 4. Importing a non generic symbol living in another namespace as its generic one, say when implementing IEnumerable (IEnumerator<T> IEnumerator) is impossible, this is the same vice versa (opening non generic namespace first). You will see a red symbol but won't get any import suggestions. 5. While exploring 4. I found that import also ignores any generic argument syntax you may have written, and gives you a non generic suggestion as well. I could see that being useful but I'm not sure if there's any ranking that takes the fact you wrote a generic type into account when ordering these suggestions? Screenshot 2020-02-05 at 16 09 54

NinoFloris avatar Feb 05 '20 15:02 NinoFloris

// try to import this, result will be Operators.foo, while foo is enough.

Thanks, I see. The text to insert is currently coming from FCS items provider. I'll be looking into it as a part of RIDER-27924 fix.

auduchinok avatar Feb 05 '20 20:02 auduchinok

That Auto module was meant to be Operators of course... Fixed

NinoFloris avatar Feb 05 '20 20:02 NinoFloris

Trying to import a nested class (so, defined in C#) causes a compiler error because it just tries to import the parent class, which is not allowed until open static is out of preview.

NinoFloris avatar Feb 11 '20 15:02 NinoFloris

@NinoFloris Could you also attach some minimal repro snippets? It's also important to note which import method is used: code completion or a quick fix, since the first one is currently provided by FCS and the second one is done on our side.

auduchinok avatar Feb 11 '20 15:02 auduchinok

Working on it :)

NinoFloris avatar Feb 11 '20 15:02 NinoFloris

So quick fix ignores the parent class and imports just the namespace which is wrong in its own way without symbol fixup at the import site, while code completion tries to import the parent class like I said.

it's super simple

namespace ReproCs
{
    public class Foo
    {
        public class Bar
        {
        }
    } 
}
module ReproFs

let bar() = Bar // try either quick fix or code completion for the fireworks.

NinoFloris avatar Feb 11 '20 15:02 NinoFloris

@NinoFloris Yes, this case wasn't implemented yet. Thanks for repro!

auduchinok avatar Feb 11 '20 16:02 auduchinok

  1. While exploring 4. I found that import also ignores any generic argument syntax you may have written, and gives you a non generic suggestion as well.

It's also fixed now. If there are any type arguments given, the suggested types are filtered based on the type parameters count.

auduchinok avatar Mar 30 '20 16:03 auduchinok

Nested types qualifiers are also inserted via quick fix now. Before: Screenshot 2020-12-14 at 13 04 59 After: Screenshot 2020-12-14 at 13 05 23

All completion-related issues currently need separate fixes in FCS and completion side though, but I'm aiming to reusing the logic implemented for the quick fix instead.

auduchinok avatar Dec 14 '20 10:12 auduchinok

It seems like all of these issues have been fixed in code completion too. @NinoFloris If you see other cases, please file a separate issue, and I'll work on it.

auduchinok avatar May 01 '23 14:05 auduchinok