1

How does clangd know where a function definition is when only one file has been indexed through the LSP (Language Server Protocol) message textDocument/didOpen?

This question is based off of the assumption that there is no compile_commands.json file for clangd to work with.

To the best of my knowledge clangd will partially index(?) a given file when clangd receives the LSP message textDocument/didOpen with no compile_commands.json file in the workspace(?).

Thus the index of the file being partially indexed will only reside in memory.

So how is clangd aware of definitions outside of the partially indexed file when it has no awareness of any outside files?

Or is it aware?

Or is it made aware of other files by some heuristic that looks at the relative path or the includes (#include "<filename.hpp>") that only reside in directories root-project-dir/src and the likes thereof?

John DeBord
  • 638
  • 1
  • 5
  • 17
  • Since that's not well documented, the best way might be to debug into the source code. – Lex Li Sep 15 '20 at 23:10
  • I had [arguments](http://codinggorilla.com/?p=2377) about this whole thing with both LSP and Clangd folk. Clangd opens files from disk even though it does not receive a DidOpen call specifically for the include files. It does so in order to compile the source code, which would be impossible without the header files. So, yes, it's aware of far more than the DidOpen. That said, I'm not sure how it figures out the workspace and how it figures out the include paths. It's either asked for via message to client or something figures it out on the client side and then sends that to server. – kaby76 Sep 22 '20 at 19:20

0 Answers0