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

refactor: update clangd root detection #1165

Merged
merged 1 commit into from
Jul 21, 2023
Merged

Conversation

amaanq
Copy link
Contributor

@amaanq amaanq commented Jul 20, 2023

It'd be nice if there was a precedence associated w/ the ordering of arguments, but I don't think there is and it seems to match the most nested dir. That's not ideal for a lot of projects, like tree-sitter where compile_flags.txt is in lib/

Suggestions welcome!

@folke
Copy link
Collaborator

folke commented Jul 20, 2023

If you want to have precedence, you can do something like the below:

return function(...)
  return require("lspconfig.util").root_pattern("Makefile")(...) or require("lspconfig.util").root_pattern("another pattern")(...) or --the others
end

@amaanq
Copy link
Contributor Author

amaanq commented Jul 21, 2023

that's smart..thanks!

@amaanq
Copy link
Contributor Author

amaanq commented Jul 21, 2023

updated, that should perform much better

@folke folke merged commit d71ebea into LazyVim:main Jul 21, 2023
3 checks passed
@folke
Copy link
Collaborator

folke commented Jul 21, 2023

thanks!

@lucobellic
Copy link
Contributor

Now that "compile_commands.json" and "compile_flags.txt" are no longer the first default, I was surprised to see several clangd processes running in single file mode on a project with one CMakeLists.txt per folder.

It's easy enough to restore the previous behavior, but @folke, @amaanq, was the default root path search order change expected?

@amaanq
Copy link
Contributor Author

amaanq commented Jul 24, 2023

that's interesting, I guess there's no easy solution for this after all 😅, for me the original behavior was usually fine for projects purely in C, but add anything else like Rust and it can get wonky.. (which I usually work with)

@lucobellic
Copy link
Contributor

My concern is that projects with multiple CMakeLists.txt are common when following "modern" cmake practice. and IMO this change doesn't seem like a good default configuration for C++ development.

Also by default, browsing throw such a code base will start spawning lot of clangd processes and probably gradually increase CPU usage, which may not be noticeable at fisrt since lsp/completion work as expected.

Do you thing removing the search of CMakeLists.txt could provide better default for most C++ users without introducing issue with your way of working?

@amaanq
Copy link
Contributor Author

amaanq commented Jul 24, 2023

we can remove CMakeLists.txt, I don't mind that, typically I work with Makefiles 😅

Or, just give CMakeLists.txt the same precedence as compile_commands.json/compile_flags.txt

@folke
Copy link
Collaborator

folke commented Jul 25, 2023

maybe a good idea to remove indeed.
for reference, this is the default root detection in lspconfig: https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/clangd.lua#L24

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

Successfully merging this pull request may close these issues.

None yet

3 participants