OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.72k stars 168 forks source link

[Feature Request] Add support for Code Action "add a project reference to ..." #618

Closed Melandel closed 4 years ago

Melandel commented 4 years ago

Hello,

Omnisharp proposes to add a project reference for me, which is nice, but for now, when I select that action, a No action taken is displayed.

Is it possible to implement this code action?

nickspoons commented 4 years ago

Hi @Melandel, I don't think I've seen that code action offered before. How do I repro?

Melandel commented 4 years ago

Let me try to get a simple scenario for you :)

Melandel commented 4 years ago

I can reproduce with 4 projects (sorry if I couldn't do better)

Here's a repo with the code: git@github.com:Melandel/AddAProjectReference.git

You can reproduce by running omnisharp on the sln file and put the cursor on C/OtherInterfaceImplementation.cs, raw 3 on the interface OtherInterface, then trigger GetCodeActions.

I get these options: image

Basically, C.csproj has a reference to B.csproj - C.csproj tries to implement an interface defined in B.csproj.

However, that interface requires O.csproj for a return type (DataStructure).

So C.csproj knows the interface but misses the link with O.csproj's DataStructure - that our sln knows of.

I think the tricky part to reproduce is to have the cursor on the Interface, the code action doesn't seem to appear when the cursor is on another location.

nickspoons commented 4 years ago

OK I see what you mean. Running that code action, we get this response from the server:

{
  "Request_seq": 1009,
  "Command": "/v2/runcodeaction",
  "Running": true,
  "Success": true,
  "Message": null,
  "Body": {
    "Changes": []
  },
  "Seq": 1625,
  "Type": "response"
}

It might be that we should be requesting it differently, I'll try to see what happens in VSCode

nickspoons commented 4 years ago

I tried in VSCode and got the exact same result. I think you're going to need to ask this in omnisharp-rolsyn/issues

nickspoons commented 4 years ago

@Melandel I created an issue: https://github.com/OmniSharp/omnisharp-roslyn/issues/1873

Thanks for the repro, that makes it easy to demonstrate.