[clang-tools-extra] [clangd] Add background index path mapping (PR #180285)
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 23:51:44 PST 2026
ArcsinX wrote:
> * Generate background index files in Client A (which has a compile_commands.json unique to Client A)
> * Copy background index files to Client B (which has a compile_commands.json unique to Client B)
> * Delete Client A entirely
> * Observe index loaded and no reindexing triggered in Client B
I tried with CMake project and this doesn't work for me. I tried in the following way:
- CMake sources are in two directories (.../foobar/CMake and .../bar/CMake), create build directory in both and generate compile_commands.json
- Build clangd index in .../foobar/CMake
- copy .../foobar/CMake/.cache to .../bar/CMake
- add --background-index-path-mappings=.../bar/CMake=.../foobar/CMake option for clangd which is run in .../bar/CMake
- open .../bar/CMake, reindexing happens for all project files
```
I[10:21:11.643] clangd version 23.0.0git (https://github.com/justincady/llvm-project.git 343b1dddf67dfcc45387d9be8c0741cef16bb42d)
I[10:21:11.643] Features: linux
I[10:21:11.643] PID: 1891072
I[10:21:11.643] Working directory: .../bar/CMake
I[10:21:11.643] argv[0]:.../llvm-project/build_clang/bin/clangd
I[10:21:11.643] argv[1]: --log=verbose
I[10:21:11.643] argv[2]: --query-driver=**
I[10:21:11.643] argv[3]: --background-index-path-mappings=.../bar/CMake=.../foobar/CMake
...
I[10:21:11.723] Enqueueing 1148 commands for indexing
V[10:21:11.724] Failed to load shard: .../bar/CMake/Utilities/cmcurl/lib/curl_fopen.c
V[10:21:11.724] Failed to load shard: .../bar/CMake/Source/kwsys/testDynload.c
V[10:21:11.724] Failed to load shard: .../bar/CMake/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
V[10:21:11.724] Failed to load shard:.../bar/CMake/Utilities/cmcurl/lib/macos.c
```
And I see two .idx files for each source file in .cache/clangd/index/ directory (newly created and one which I copied from foobar
<img width="240" height="260" alt="image" src="https://github.com/user-attachments/assets/846a72f6-f9b6-4aa9-b6a4-d1def62b88e0" />
https://github.com/llvm/llvm-project/pull/180285
More information about the cfe-commits
mailing list