How to use offline index file generated by clangd-indexer in vscode?

I experimented with using offline index and generated index files using clangd-indexer:
clangd-indexer --executor=all-TUs llvm-project/build_19.1.2/compile_commands.json >ll19.idx

in ~/.config/clangd/config.yaml, add these line:
..
Index:
External:
File: /home/luk/llvm-project/build_19.1.2/ll19.idx
MountPoint: /home/luk/llvm-project/

The VSCode workspace configuration about clangd is as follows:
{
“clangd.path”: “/usr/bin/clangd”,
“clangd.arguments”: [
“–enable-config”,
“–log=verbose”,
//“–index-file=/home/luk/llvm-project/build_19.1.2/ll19.idx”
],
}

But in VSCode, I couldn’t find the reference symbols that should be there by right clicking on symbols such as identifiers/functions to find all references.

Found the reason,
The clangd parameter needs to add the option ‘–compile-commands-dir’.

1 Like