How can I configure nvim-lspconfig & clangd to continue using my compile_commands.json after jumping to external definition? #28654
Unanswered
tomasgareau
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
Say I have a root directory containing a C project called
my_project
which depends on some external dependencyfoo
outside the root directory. I've builtmy_project
and generated acompile_commands.json
file.Within
my_project
, LSP commands work great. Theclangd
instance picks up mycompile_commands.json
compilation database and is able to resolve anyfoo
symbols. I can, for example, hover over functions from the external dependencyfoo
and see their documentation. Great!If I
go-to-definition
onfoo_init
, Neovim will jump to (for example)external/foo/include/foo.h
. This will spawn a new LSP client with a root dir somewhere in my external dependency tree......and this LSP client doesn't find any
compile_commands.json
(which makes sense -- the external dependency is just source code, no build artifacts). But this means I can't use LSP features to navigate this external dependency: all the compilation information thatclangd
requires for this is in my originalmy_project/compile_commands.json
.If I manually symlink
my_project/compile_commands.json
toexternal/compile_commands.json
, then the second LSP instance does pick it up and I can navigate the external dependency using the compilation info frommy_project
.Question
Is there a recommended approach to using compilation info in external dependencies? I'm not sure whether I'm supposed to:
my_project
as a root, even for external codecompile_commands.json
as my first clientRelated issues
This seems related to neovim/nvim-lspconfig#2287, which allowed using the same LSP server for a filetype if it exists, and neovim/nvim-lspconfig#2330, which disabled re-using the same server for multiple instances if the LSP server does not have the
workspaceFolders
server capability (which AFAIK clangd does not).Beta Was this translation helpful? Give feedback.
All reactions