[clang-tools-extra] [clangd] Add background index path mapping (PR #180285)
Justin Cady via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 07:45:15 PST 2026
justincady wrote:
@ArcsinX I updated the PR to:
- Take a more general path mapping approach
- Validate that specifying multiple mappings works as expected
- Apply path mapping to the serialized compile commands
And, I retested your original failed scenario by once again starting with a fresh zlib...
- Copy and extract the archive into two separate directories
- In each:
- `$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON`
- `$ cmake --build build/`
- `$ mv build/compile_commands.json .`
- Open Client A in VSCode with this clangd config (_no mapping flag_):
- `--log=verbose`
- `--background-index=true`
- Observe `.cache` is created and populated in Client A
- `Enqueueing 17 commands for indexing`
- Copy `.cache` into Client B
- `$ cp -R /path/to/zlib-one/zlib-1.3.1/.cache .`
- Open Client B in VSCode with this additional clangd config:
- `--background-index-path-mappings=${workspaceFolder}=/path/to/zlib-one/zlib-1.3.1`
- Observe index is loaded and duplicate files are not created (both cache directories contain 29 files):
```
$ diff -bur .cache/ /path/to/zlib-one/zlib-1.3.1/.cache/`
$
```
- Now modify one file (adding an empty static function):
```
$ diff -bur .cache/ /path/to/zlib-one/zlib-1.3.1/.cache/
Binary files .cache/clangd/index/gzclose.c.74002F0CA97FAD13.idx and /path/to/zlib-one/zlib-1.3.1/.cache/clangd/index/gzclose.c.74002F0CA97FAD13.idx differ
$
```
- Validate that the updated shard still uses `zlib-one` paths (using `dexp`)
The major difference here is true path remapping, as you originally expected. Everything in memory is mapped to `zlib-two`; everything on-disk remains `zlib-one` (including compile commands).
https://github.com/llvm/llvm-project/pull/180285
More information about the cfe-commits
mailing list