Skip to content

csharp_ls not correctly using root_dir using 0.11 setup #3849

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

Open
jjiangweilan opened this issue May 13, 2025 · 6 comments
Open

csharp_ls not correctly using root_dir using 0.11 setup #3849

jjiangweilan opened this issue May 13, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@jjiangweilan
Copy link

Description

I have switched to the new 0.11 setup, both clangd and lua_ls work find. After inspecting lsp log, it seems csharp_ls is not looking for .sln and .csproj in root dir but in the current working directory. If I manually call the old lspconfig.csharp_ls.setup{}, It correctly use the root dir.

@jjiangweilan jjiangweilan added the bug Something isn't working label May 13, 2025
@lithammer
Copy link
Collaborator

From what I can tell they have more or less identical root dir logic. So that's surprising.

root_dir = function(bufnr, on_dir)
local fname = vim.api.nvim_buf_get_name(bufnr)
on_dir(util.root_pattern '*.sln'(fname) or util.root_pattern '*.csproj'(fname))
end,

root_dir = function(fname)
return util.root_pattern '*.sln'(fname) or util.root_pattern '*.csproj'(fname)
end,

@jjiangweilan
Copy link
Author

From what I can tell they have more or less identical root dir logic. So that's surprising.

nvim-lspconfig/lsp/csharp_ls.lua

Lines 15 to 18 in 61e5109

root_dir = function(bufnr, on_dir)
local fname = vim.api.nvim_buf_get_name(bufnr)
on_dir(util.root_pattern '.sln'(fname) or util.root_pattern '.csproj'(fname))
end,
nvim-lspconfig/lua/lspconfig/configs/csharp_ls.lua

Lines 6 to 8 in 61e5109

root_dir = function(fname)
return util.root_pattern '.sln'(fname) or util.root_pattern '.csproj'(fname)
end,

pardon me if this is not the correct place to report this. In both cases, lspconfig does found the correct root dir, but csharp_ls is not using the root dir under 0.11 setup.

0.11 setup (incorrect in bullet 3):

  • cwd: E:/MyProject/Package
  • LspInfo reports root dir: E:/MyProject
  • csharp_ls' LspLog reports: "looking for project under E:/MyProject/Package"

0.10 setup (correct):
new setup:

  • cwd: E:/MyProject/Package
  • LspInfo reports root dir: E:/MyProject
  • csharp_ls' LspLog reports: "looking for project under E:/MyProject"

@justinmk
Copy link
Member

what is the filename of the current buffer in each case?

@jjiangweilan
Copy link
Author

what is the filename of the current buffer in each case?

using ls they show the same filename for the same file

@justinmk
Copy link
Member

but what is a concrete example? wondering how it compares to the cwd, etc.

@jjiangweilan
Copy link
Author

but what is a concrete example? wondering how it compares to the cwd, etc.

Here is the minimum config to reproduce this error

-- init.lua

vim.opt.rtp:append("path/to/local/nvim-lspconfig")

-- Setup 1
------------------------------ 
vim.lsp.config("csharp_ls", {
  capabilities = vim.lsp.protocol.make_client_capabilities()
 })
vim.lsp.enable({"csharp_ls"})

-- Setup 2
------------------------------- 
-- lspconfig = require("lspconfig")
-- lspconfig.csharp_ls.setup({})

Setup 1

Note how csharp-ls attempting to find and load solution based on cwd instead of root project

pwd and ls

C:\Users\weilan\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime

:ls
1  h   "~\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime" line 1
3 %a   "DeferredLights.cs"            line 1
4  h-  "health://"                    line 0  

lsp messages

LSP[csharp_ls][Info] csharp-ls: initializing, version 0.16.0.0 LSP[csharp_ls][Info] csharp-ls: csharp-ls is released under MIT license and is not affiliated with Microsoft Corp.; see https://github.com/razzmatazz/csharp-language-server LSP[csharp_ls][Info] csharp-ls: attempting to find and load solution based on root path ("C:\Users\weilan\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime").. LSP[csharp_ls][Info] csharp-ls: 0 solution(s) found: [] LSP[csharp_ls][Info] csharp-ls: no or multiple .sln files found on C:\Users\weilan\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime LSP[csharp_ls][Info] csharp-ls: looking for .csproj/fsproj files on C:\Users\weilan\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime.. LSP[csharp_ls][Info] csharp-ls: no or .csproj/.fsproj or sln files found on C:\Users\weilan\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime

LspInfo

- LSP log level : WARN
- Log path: C:/Users/weilan/AppData/Local/nvim-data/lsp.log
- Log size: 218 KB

vim.lsp: Active Clients ~
- csharp_ls (id: 1)
  - Version: 0.16.0.0
  - Root directory: ~\Desktop\test\My project
  - Command: { "csharp-ls" }
  - Settings: {}
  - Attached buffers: 3

Setup 2

pwd and ls

:ls
1  h   "~\Desktop\test\My project\Packages\com.unity.render-pipelines.universal\Runtime" line 1
3 %a   "DeferredLights.cs" line 18

lsp messages

good, correctly loaded the .sln and reports an error

LSP[csharp_ls][Info] csharp-ls: initializing, version 0.16.0.0 LSP[csharp_ls][Info] csharp-ls: csharp-ls is released under MIT license and is not affiliated with Microsoft Corp.; see https://github.com/razzmatazz/csharp-language-server LSP[csharp_ls][Info] csharp-ls: attempting to find and load solution based on root path ("C:\Users\weilan\Desktop\test\My project").. LSP[csharp_ls][Info] csharp-ls: 1 solution(s) found: [C:\Users\weilan\Desktop\test\My project\My project.sln] LSP[csharp_ls][Info] csharp-ls: Loading solution "C:\Users\weilan\Desktop\test\My project\My project.sln"... LSP[csharp_ls][Info] csharp-ls: Solution "C:\Users\weilan\Desktop\test\My project\My project.sln" could not be loaded: System.AggregateException: One or more errors occurred. (The solution file has two projects named "Assembly-CSharp". C:\Users\weilan\Desktop\test\My project\My project.sln) ---> Microsoft.Build.Exceptions.InvalidProjectFileException: The solution file has two projects named "Assembly-CSharp". C:\Users\weilan\Desktop\test\My project\My project.sln at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, String resourceName, Object[] args) at Microsoft.Build.Construction.SolutionFile.ParseSolution() at Microsoft.Build.Construction.SolutionFile.ParseSolutionFile() at Microsoft.Build.Construction.SolutionFile.Parse(String solutionFile) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress1 progress, ILogger msbuildLogger, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, ILogger msbuildLogger, IProgress1 progress, CancellationToken cancellationToken) --- End of inner exception stack trace ---

LspInfo

- LSP log level : WARN
- Log path: C:/Users/weilan/AppData/Local/nvim-data/lsp.log
- Log size: 220 KB

vim.lsp: Active Clients ~
- csharp_ls (id: 1)
  - Version: 0.16.0.0
  - Root directory: ~\Desktop\test\My project
  - Command: { "C:\\Users\\weilan\\AppData\\Local\\nvim-data\\mason\\packages\\csharp-language-server\\csharp-ls.EXE" }
  - Settings: vim.empty_dict()
  - Attached buffers: 3

I found depending on how I enter the file, directly e filename.cs or e . then found the file, the filename from ls different but that doesn't have any effect on the behaviour of lsp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants