Cannot navigate to definition of member in header in files that are outside of compilation database and are alternatively indexed by clangd-indexer
See original GitHub issueIn short
Go to Definition
results in No definition found for [...]
in a file that is outside the compilation database (compile_commands.json
), but is indexed using clangd-indexer
.
Details
I have a project with sources that are build inside the project and pre built libraries that come in by a package manager and bring debug sources in separate folders with them.
- /build
/**/somewhereHere/**/compile_commands.json
- /src
... hpp cpp files
- /externalSources
*.a files
- /debug
hpp cpp files
.clangd
index.dex
I use a compilation database for background indexing and use an external index to index the library sources. (setup this by using .clangd
config file)
The indexed library sources are overall pretty good navigatable. So in general this approach seems to work for me.
In these lib sources there are some class members that are defined/initialised directly in the header (.hpp file) like this:
myType myClassVar {initvalue};
What fails
These members are referenced in the implementation of a class method (.cpp file). When I try to navigate back to their definition in the header file it cannot be found. This behavior applies to multiple members, that all share the property of beeing defined in the header and are referenced in the source.
What works
There are also definitions of members in the header that belong to the main project, so they are in the compile_commands.json
. For these sources the problematic navigation works. So it has to do with the external index.
Investigation
In the index file (which is in YAML format) I can see that the member defined in the header has a declaration and a definition. Both point to the header file. That seems correct. In the indexes references section there is an entry that shows a correct defintion location of the member.
Additional information
I cannot share the project and I was unable to reproduce this in a minimum example project. In a minimal example the problematic navigation always worked.
Logs
When I use verbose logging and start the Go to Definition
function this is the output of the
clangd log (sensible information replaced with [...]
V[09:59:46.130] <<< {"id":15,"jsonrpc":"2.0","method":"textDocument/definition","params":{"position":{"character":10,"line":107},"textDocument":{"uri":"file:///c%3A/Users/[...]/swdev/[...]/debug/portable/WebSocket/MongooseTextWebSocket.cpp"}}}
I[09:59:46.130] <-- textDocument/definition(15)
V[09:59:46.132] ASTWorker running Definitions on version 3 of c:\Users\[...]\swdev\[...]\debug\portable\WebSocket\MongooseTextWebSocket.cpp
I[09:59:46.133] --> reply:textDocument/definition(15) 2 ms
V[09:59:46.133] >>> {"id":15,"jsonrpc":"2.0","result":[]}
I[09:59:46.133] --> textDocument/clangd.fileStatus
V[09:59:46.133] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///c:/Users/[...]/swdev/[...]/debug/portable/WebSocket/MongooseTextWebSocket.cpp"}}
System information
Clangd version (from the log, or clangd --version
): clangd version 15.0.3 (https://github.com/llvm/llvm-project 4a2c05b05ed07f1f620e94f6524a8b4b2760a0b1)
clangd extension version: v0.1.23
Operating system: Windows 10
LLVM (http://llvm.org/):
LLVM version 15.0.3
Optimized build.
Default target: x86_64-pc-windows-msvc
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
I set up the libs with
compile_commands.json
files, put the libs together with theircompile_commands.json
in a workspace and that works pretty well. Thanks for pointing me in that direction.I think I’ll try this, too and follow the instructions from https://github.com/clangd/vscode-clangd/issues/38#issuecomment-639986094 for this. Making the external index perfect might be much effort.