[clang-tools-extra] [clangd] Add background index format support to clangd-indexer (PR #175209)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 22 23:15:18 PDT 2026


================
@@ -48,6 +64,23 @@ static llvm::cl::list<std::string> QueryDriverGlobs{
     llvm::cl::CommaSeparated,
 };
 
+static llvm::cl::opt<std::string> ProjectRoot{
+    "project-root",
+    llvm::cl::desc(
+        "Path to the project root for --index-type=sharded. "
+        "Determines where to store index shards. Shards are stored in "
+        "<project-root>/.cache/clangd/index/. "
+        "Defaults to current directory if not specified."),
+};
+
+// Tracks the content digest of the last shard written for a given file.
+// Used to avoid writing duplicate shards when multiple TUs include the same
+// header.
+struct ShardVersion {
----------------
HighCommander4 wrote:

This struct should have a `HadErrors` field, like the [background index version](https://searchfox.org/llvm/rev/aff1ba103ab3006242c72af33420a3437f4ff1db/clang-tools-extra/clangd/index/Background.h#188-191).

(In fact, I'd recommend just moving the background indexer's struct to namespace scope in Background.h and reusing it.)

This is important: if a header fails to compile in the context of one translation unit, the contents in its shard are likely to be incorrect or partially complete; if we don't mark it as `HadErrors`, then we lose the opportunity to update the shard if the same header does compile in the context of another translation unit.

https://github.com/llvm/llvm-project/pull/175209


More information about the cfe-commits mailing list