Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant seem to understand .sln with multiple .csproj #62

Closed
ckangnz opened this issue Jan 19, 2023 · 9 comments · Fixed by #112
Closed

Cant seem to understand .sln with multiple .csproj #62

ckangnz opened this issue Jan 19, 2023 · 9 comments · Fixed by #112

Comments

@ckangnz
Copy link

ckangnz commented Jan 19, 2023

I have a .sln that consists multiple .csproj

But whenever i load a single .cs file, it attempts to find the .csproj but won't understand other connected .csproj within the solution. How do make it work?

@melendezd
Copy link

melendezd commented Jan 26, 2023

I'm having this issue too. When I'm in Project A and I try to go to definition for a symbol defined in Project B in the same solution, it tries to find the symbol in the corresponding assembly for Project B within Project A (csharp:metadata/projects/ProjectA/assemblies/ProjectB/symbols/..."). Makes sense but I would prefer to have some way to set it up so that it'd go to the definition in the source for Project B in the solution.

@razzmatazz
Copy link
Owner

Hey,

Could you provide a file tree of your solution (.sln + .csprojs is enough)?
And a log from csharp-ls (if available on your editor/ide) -- especially the startup part?

Ideally csharp-ls would pick up a .sln file and would load everything in one go (and faster at that) -- so no metadata refs should be emitted for local files.

@ckangnz
Copy link
Author

ckangnz commented Feb 8, 2023

the file tree looks something like this

  • root_folder_with_.git
    • /project
      • Main.sln
      • /subproject
        • SubProj.csproj
      • /subproject
        • SubProj.csproj
      • /subproject
        • SubProj.csproj
      • /subproject
        • SubProj.csproj
          .......

@razzmatazz
Copy link
Owner

could you provide log from the server? usually it complains if it cannot find sln or something is not ok. if there is a single sln and all csprojs are there in this sln then thing should just work...

@ckangnz
Copy link
Author

ckangnz commented Feb 8, 2023

I think csharp-language-server is trying to use dotnet 6 when the project is dotnet 7?

The log does say that it picked up the .sln file correctly, but it can't find any references.

image

When I run :CocOpenLog, this is all I get

2023-02-09T08:09:46.843 INFO (pid:2626) [plugin] - coc.nvim initialized with node: v14.17.5 after �[33m5003�[39m
2023-02-09T08:09:46.847 INFO (pid:2626) [services] - LanguageClient csharp state change: stopped => starting
2023-02-09T08:09:46.847 INFO (pid:2626) [services] - LanguageClient csharp-ls state change: stopped => starting
2023-02-09T08:09:46.860 INFO (pid:2626) [language-client-index] - Language server "languageserver.csharp" started with 2633
2023-02-09T08:09:46.870 INFO (pid:2626) [language-client-index] - Language server "csharp-ls" started with 2634
2023-02-09T08:09:47.077 INFO (pid:2626) [core-watchman] - watchman watching project: /Users/chris.kang/code/Business.ContactService/project
2023-02-09T08:09:59.083 INFO (pid:2626) [services] - LanguageClient csharp-ls state change: starting => running
2023-02-09T08:09:59.088 INFO (pid:2626) [services] - service csharp-ls started
2023-02-09T08:09:59.089 INFO (pid:2626) [services] - LanguageClient csharp state change: starting => running
2023-02-09T08:09:59.090 INFO (pid:2626) [services] - service languageserver.csharp started
2023-02-09T08:11:45.223 INFO (pid:2626) [attach] - receive notification: openLog []

@82Kang
Copy link

82Kang commented Feb 12, 2023

Facing the same issue. I am getting the following error:
Error executing vim.schedule lua callback: /opt/nvim-linux64/share/nvim/runtime/lua/vim/lsp/util.lua:1735: index out of range stack traceback: [C]: in function '_str_byteindex_enc' /opt/nvim-linux64/share/nvim/runtime/lua/vim/lsp/util.lua:1735: in function 'locations_to_items' ...nvim-linux64/share/nvim/runtime/lua/vim/lsp/handlers.lua:352: in function 'handler' /opt/nvim-linux64/share/nvim/runtime/lua/vim/lsp.lua:1383: in function '' vim/_editor.lua: in function <vim/_editor.lua:0>

Issue with the NeoVim LSP? I did try it with Coc and it works perfectly fine there.
Update: When I do "vim.lsp.buf.hover()" it does show the fully qualified name of the class. I think that means it can "see" the class but looks like there is some issue while jumping to it.

@freber0
Copy link

freber0 commented May 2, 2023

I'm having the same issue. The file tree looks like this:

  • MyProject root dir
    • .git
    • .sln
    • /src
      • proj1.csproj
      • proj2.csproj
      • proj3.csproj
    • /tests
      • testproj1.csproj
      • testproj2.csproj
      • testproj3.csproj

Here's some logs when trying to go to a func definition in proj1.csproj from testproj1.csproj:

[DEBUG][2023-05-02 08:24:06] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/showMessage",  params = {    message = 'csharp-ls: attempting to find and load solution based on cwd ("/Users/hello/dev/MyProject/tests/MyProject.Tests")..',    type = 4  }}
[DEBUG][2023-05-02 08:24:06] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/showMessage",  params = {    message = "csharp-ls: 0 solution(s) found: []",    type = 4  }}
[DEBUG][2023-05-02 08:24:06] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/showMessage",  params = {    message = "csharp-ls: no or multiple .sln files found on /Users/hello/dev/MyProject/tests/MyProject.Tests",    type = 4  }}
[DEBUG][2023-05-02 08:24:06] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/showMessage",  params = {    message = "csharp-ls: looking for .csproj/fsproj files on /Users/hello/dev/MyProject/tests/MyProject.Tests..",    type = 4  }}
[DEBUG][2023-05-02 08:24:06] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/showMessage",  params = {    message = 'csharp-ls: loading project "/Users/hello/dev/MyProject/tests/MyProject.Tests/MyProject.Tests.csproj"..',    type = 4  }}
[DEBUG][2023-05-02 08:24:07] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/showMessage",  params = {    message = "csharp-ls: OK, 1 project files loaded",    type = 4  }}

I'm using dotnet 7.

@emilioziniades
Copy link

emilioziniades commented May 13, 2023

Hi there, I'm also using csharp_ls with neovim, and ran into the same issue. I believe that the problem is the default configuration for csharp_ls in nvim-lspconfig. The TLDR is that the csproj file is found before the sln file, and so csharp_ls is started in the project directory, instead of the solution directory.

Updating the root_dir field in my LSP config like this fixed the issue.

lspconfig.csharp_ls.setup({
    root_dir = function(startpath)
        return lspconfig.util.root_pattern("*.sln")(startpath)
            or lspconfig.util.root_pattern("*.csproj")(startpath)
            or lspconfig.util.root_pattern("*.fsproj")(startpath)
            or lspconfig.util.root_pattern(".git")(startpath)
    end,
    on_attach = on_attach,
    capabilities = capabilities,
})

After doing that, csharp_ls correctly identifies the solution file, loads it, and go to definition, renames, etc.. work across multiple projects as expected.

For more info check out the issue I opened here: neovim/nvim-lspconfig#2612

@ckangnz
Copy link
Author

ckangnz commented Jun 9, 2023

Hi there, I'm also using csharp_ls with neovim, and ran into the same issue. I believe that the problem is the default configuration for csharp_ls in nvim-lspconfig. The TLDR is that the csproj file is found before the sln file, and so csharp_ls is started in the project directory, instead of the solution directory.

Updating the root_dir field in my LSP config like this fixed the issue.

lspconfig.csharp_ls.setup({
    root_dir = function(startpath)
        return lspconfig.util.root_pattern("*.sln")(startpath)
            or lspconfig.util.root_pattern("*.csproj")(startpath)
            or lspconfig.util.root_pattern("*.fsproj")(startpath)
            or lspconfig.util.root_pattern(".git")(startpath)
    end,
    on_attach = on_attach,
    capabilities = capabilities,
})

After doing that, csharp_ls correctly identifies the solution file, loads it, and go to definition, renames, etc.. work across multiple projects as expected.

For more info check out the issue I opened here: neovim/nvim-lspconfig#2612

I use coc instead of nvim-lsp. I tried similar approach to update the root pattern of the project by doing

  "languageserver": {
    "csharp": {
      "command": "csharp-ls",
      "rootPatterns": ["*.sln", "*.csproj", ".git"],

      "filetypes": ["cs", "csharp"]
    }
  },
  "workspace.bottomUpFiletypes": ["*.sln", "*.csproj", ".git"],

But the error still persists :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants