-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
csharp_ls
default config finds incorrect root directory
#2612
Labels
bug
Something isn't working
Comments
there has a plan to rewrite root use vim.fs module then maybe we can handle this situation. |
Thanks for your comment. I'd like to propose that we go for the second option above, updating the default config for the |
dundargoc
added a commit
to dundargoc/neovim
that referenced
this issue
Jan 21, 2025
It's needed to replace util.root_patterns in lspconfig. Somewhat related: neovim/nvim-lspconfig#2612 The time and space analysis of DFS differs according to its application area. In theoretical computer science, DFS is typically used to pad the commit stats so much linkedin AIs starts pinging you about Gregory Gregory or something.
dundargoc
added a commit
to dundargoc/neovim
that referenced
this issue
Jan 21, 2025
It's needed to replace util.root_patterns in lspconfig. Somewhat related: neovim/nvim-lspconfig#2612 The time and space analysis of DFS differs according to its application area. In theoretical computer science, DFS is typically used to pad the commit stats so much linkedin AIs starts pinging you about Gregory Gregory or something.
dundargoc
added a commit
to dundargoc/neovim
that referenced
this issue
Jan 21, 2025
It's needed to replace util.root_patterns in lspconfig. Somewhat related: neovim/nvim-lspconfig#2612
dundargoc
added a commit
to dundargoc/neovim
that referenced
this issue
Jan 21, 2025
It's needed to replace util.root_patterns in lspconfig. Somewhat related: neovim/nvim-lspconfig#2612
dundargoc
added a commit
to dundargoc/neovim
that referenced
this issue
Jan 21, 2025
It's needed to replace util.root_patterns in lspconfig. Somewhat related: neovim/nvim-lspconfig#2612
dundargoc
added a commit
to dundargoc/neovim
that referenced
this issue
Jan 22, 2025
It's needed to replace util.root_patterns in lspconfig. Somewhat related: neovim/nvim-lspconfig#2612
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The default config for
csharp_ls
does not identify the correct root directory. Consider the following example filestructure.If you open
/MyProject/MyProject.Program/Program.cs
then the language server identifies the root_dir as/MyProject/MyProject.Program
. This is not correct. Logically this is one project (MyProject
as indicated byMyProject.sln
solution file), with two subprojects (MyProject.Program
andMyProject.Library
) which each have their respecive project files (MyProject.Program.csproj
andMyProject.Library.csproj
). Ideally, you would want one language server running for the entire solution.Here is the relevant line of the default config for
csharp_ls
:nvim-lspconfig/lua/lspconfig/server_configurations/csharp_ls.lua
Line 6 in df58d91
What is happening here is that
util.root_pattern
is visiting each ancestor directory (including the current directory), checking if any of the specified patterns match. The.csproj
file is discovered before the.sln
file, and the wrong root directory gets set.I managed to get around this by overriding the
root_dir
field like thisThis searches ancestor directories for any
.sln
file, and if none are found then tries the same thing looking for a.csproj
file, and so on.Others are also experiencing this, and there is an open issue in the
csharp_ls
repo: razzmatazz/csharp-language-server#62I see three possible ways to remedy the situation:
util.root_pattern
, doutil.search_ancestors
once for each supplied pattern, instead of once with all patterns (as it does currently). This is less efficient, as you have to explore ancestors at most N times for N supplied patterns. This is a bit of an edge case so maybe not the best idea to negatively impact performance for the unaffected language servers.csharp_ls
default config with something like the above.csharp_ls
defaults the same, but add a note suggesting the above.I'm happy to make an attempt at fixing it.
Neovim version
NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3
Nvim-lspconfig version
df58d91
Operating system and version
macOS 13.3
Affected language servers
csharp_ls
Steps to reproduce
Run
:LspInfo
and see that root dir is set toMyProject/MyProject.Program
Actual behavior
csharp_ls
finds thecsproj
file before thesln
file, and the incorrectroot_dir
is set for the LSP.Expected behavior
If a
sln
file is present, this should be preferred over anycsproj
file. Only usecsproj
file if nosln
file exists in the directory's ancestors.Minimal config
LSP log
https://gist.github.com/emilioziniades/2bfff850f2c22f143c3864b17fe8df86
The text was updated successfully, but these errors were encountered: