natanfudge / Auto-Using

Visual Studio Code extension that auto imports and provides auto complete for available imports in C#
https://marketplace.visualstudio.com/items?itemName=Fudge.auto-using
GNU Lesser General Public License v3.0
37 stars 7 forks source link

No suggestions for project types. #1

Open pushqrdx opened 5 years ago

pushqrdx commented 5 years ago

Amazing extension, So far it worked nicely; However, I tend to manually import namespaces for any type that is in the current project. For example

namespace MyProject.Bars
{
    public class Foo
    {

    }
}

namespace MyProject
{
    public class Bar
    {
        public void Main()
        {
            // Foo won't be in suggestions
        }
    }
}

It'd be really nice if completions show for current project plus it's referenced assemblies. (You can query those types dynamically from omnisharp. Instead of pre-compiling them as you do right now)

FUDGE PROGRESS EDIT:

natanfudge commented 5 years ago

Suggesting project types alongside library types is planned for a nearby release. Currently the plan is to run a program to query the dlls in your project whenever it is compiled, and query the nuget dlls whenever the .csproj file changes. I haven't had a lot of luck using any info from Omnisharp, although if querying the types from them is possible that would be very useful. Do you know how to do that? If not I could try making an issue on the omnisharp github.

pushqrdx commented 5 years ago

@natanfudge OmniSharp (the VS extension) is just a wrapper around a server with the same name that in turn depends on the Roslyn compiler. Both extension and server use std in/out to communicate.

A graph of how this works :

image

Your extension could easily replace the OmniSharp extension and directly communicate to it's server.

So here's how i imagine you could implement it. (Multiple Approaches)

First Approach:
  1. Watch .csproj for added/removed assemblies.
  2. Dispatch a call to OmniSharp's server Using OmniSharp Node Client with the assembly name/path to give you it's metadata. (there's a bunch of extra functionality in there that you can harness)
  3. Use the provided data for code completions.
Second Approach:
  1. Watch .csproj for added/removed assemblies.
  2. Use NRefactory, wasn't updated in a long time but will works perfectly specially for gathering metadata, to get your completions.
  3. Even better you can still use NRefactory through the now obsolete but still working OmniSharp Wrapper <= It uses HTTP instead of STD for communication.
Third Approach: (Just for variety's sake) 😂
  1. Watch .csproj for added/removed assemblies.
  2. Create a very simple console app in c# that uses reflection to return a list of methods/metadata.
  3. Communicate with it from your C# extension, in the same way OmniSharp and virtually all other language servers do, through std in/out. (Although you wouldn't even need anything fancy here as you would path in DLL path (from csproj) as an arg and get the result via stdout).

Again as said in my review for the extension. It's amazing 👌 and i really love it. I would love to further help once I have some free time.

natanfudge commented 5 years ago

Lovely answer. The third approach was my initial instinct. I'll try out the first 2 approaches soon. Currently I'm fixing some bugs and reorganizing the code base. CompletionProvider.ts is looking a bit bloated.

natanfudge commented 5 years ago

And there it is. Tell me if you want to contribute some code in the next few days.

pushqrdx commented 5 years ago

@natanfudge submitted a pr

mohaaron commented 1 year ago

Did this get fixed? I'm having this exact issue where I have a project level type not being recognized and the namespace not added. It works great for built in types, just not for project types.