csharp-language-server icon indicating copy to clipboard operation
csharp-language-server copied to clipboard

Error when trying to go to implementation

Open redfoggg opened this issue 3 years ago • 8 comments

When I do "gi" which is mapped to vim.lsp.buf.implementation nothing happens, there is a way to debug this?? I see no errors but my cursor is not moving to the class where that method is implemented, declaration goes fine but in C# projects it's often used Interfaces so I get stuck there.

redfoggg avatar Jul 27 '22 19:07 redfoggg

I suspect this is on vim? you should be able to enable lsp log somehow, and watch textDocument/implementation request/response.. in C# it is not always possible to find a single implementation.. I need to check what roslyn does when there is only one known implementation in my test project.. anyway, I suspect go-to-implementation was designed for C/C++ --like languages where there is a header and impl file, and is not that useful in C# ?

razzmatazz avatar Jul 27 '22 19:07 razzmatazz

Sorry for my poorly described description, actually is Neovim I'm using. I'm go to declaration doesn't work giving an error "method textDocument/declaration is not supported by any of the servers registered for the current buffer".

What I'm trying to do is basically go to where the method is implemented meaning, which class has the actual code for that method and not only its definition.

I'm using the csharpls_extended plugin too.

redfoggg avatar Jul 27 '22 19:07 redfoggg

hmm, do you have a away to invoke textDocument/definition? that should work..

textDocument/declaration as you mentioned is not implemented either (and is a counterpart to textDocument/implementation) -- that IIRC are for C/C++ -like languages with split declaration and implementation files

razzmatazz avatar Jul 28 '22 18:07 razzmatazz

I can invoke textDocument/definition, but like I said it goes to my interfaces, like suppose I have a method called: DoSomething()

And it's defined at IService.cs, so when I use the go to definition method I will get at IService.cs which is something I wanna be able to do but also I wanna be able to do go to implementation which would be at Service.cs where is the actual implementation of the method.

With this language-server I couldn't get it to be done, I changed the lsp-server to omnisharp-roslyn and things are going right, go-to-impletation gets me Service.cs whereas go-to-definition gets to IService.cs, I switched because I needed to make it work but it's something to look at, with omnisharp_extended I can also peek at meta-data information.

Also, using the plugin csharpls_extended when going to definitions cross-projects I was getting into compiled generated files and not the actual files, which is a strange behavior, and maybe something to have an eye at.

I will be closing this, if you find the information's interesting you can use it, since I'm now fine with omnisharp-roslyn I will kept that way, thanks for your effort here anyway I guess it is something with my configs or something else but right now I'm short in time.

redfoggg avatar Jul 29 '22 01:07 redfoggg

I will reopen this so maybe I can fix this..

mhm, I am not particularly versed with how lsp is implemented in nvim, but the standard behaviour should be:

  • the editor invokes textDocument/implementation
  • editor received response with multiple implementations
  • provides UI to user to select which implementation he/she wants to go to
  • actually jumps to the file

this is how it works for me

I have this file:

namespace x;

public interface IAAA
 {
    void Method();
}

public class BBB : IAAA
{
    public void Method() {}
}

public class CCC : IAAA 
{
    public void Method() {}
}

public class DDD
{
    public void Run()
     {
        IAAA aaa = new BBB();
        aaa.Method();
     }
 }

lsp trace

[Trace - 09:38:57 AM] Sending request 'textDocument/implementation - (29799)'.
Params: {
  "textDocument": {
    "uri": "file:///home/bob/src/csharp/csharp-test/Test.cs"
  },
  "position": {
    "line": 22,
    "character": 15
  }
}


[Trace - 09:38:57 AM] Received response 'textDocument/implementation - (29799)' in 0ms.
Result: [
  {
    "uri": "file:///home/bob/src/csharp/csharp-test/Test.cs",
    "range": {
      "start": {
        "line": 9,
        "character": 16
      },
      "end": {
        "line": 9,
        "character": 22
      }
    }
  },
  {
    "uri": "file:///home/bob/src/csharp/csharp-test/Test.cs",
    "range": {
      "start": {
        "line": 14,
        "character": 16
      },
      "end": {
        "line": 14,
        "character": 22
      }
    }
  }
]

razzmatazz avatar Jul 29 '22 06:07 razzmatazz

what happens in omnisharp-roslyn when you "go to implementation" on Method() in DDD.Run()? where does it jump? IMHO it needs to provide UI so you can select which impl you jump to?

razzmatazz avatar Jul 29 '22 06:07 razzmatazz

I guess this test pass because it is in the same project and in the same file, in my setup was trying to go in classes and interfaces defined in another linked project.

Go-to-implementation doesn't give any error in this scenario I was testing, but it does not do anything also, going to declaration of cross-project files gets me in compiled files, I can give some screens after reproducing it with csharp_ls after, I can't do right now though.

redfoggg avatar Jul 29 '22 21:07 redfoggg

yes, it would be interesting to get a minimal test case to reproduce your problem where cross-project references behave this way

if you could make a minimal test project it would very nice to start building test code

razzmatazz avatar Jul 30 '22 14:07 razzmatazz

I had the same issue but could resolve it with the following config from the csharp_ls: csharp_ls = { root_dir = require("lspconfig.util"):root_pattern(".sln") or require("lspconfig.util"):root_pattern(".csproj"), },

Like this it always took the root folder of the project as the root folder.

tilupe avatar Feb 09 '23 15:02 tilupe

When I finally got some time to try this again, the error just doesn't happen anymore, still can't go to metadata though but this is another subject.

redfoggg avatar Jul 18 '23 01:07 redfoggg