[clang-tools-extra] [clangd] Respect background index priority (PR #212700)
Michael Owens via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 29 00:36:07 PDT 2026
https://github.com/why-does-ie-still-exist created https://github.com/llvm/llvm-project/pull/212700
The --background-index-priority CLI option was not wired correctly, leading to it being always 'low' even when otherwise specified.
>From 2f12b4c95e0387019c49265084cad825cedd266c Mon Sep 17 00:00:00 2001
From: Michael <33632547+why-does-ie-still-exist at users.noreply.github.com>
Date: Wed, 29 Jul 2026 00:34:06 -0700
Subject: [PATCH] [clangd] Respect background index priority
The --background-index-priority CLI option was not wired correctly, leading to it being always 'low' even when otherwise specified.
---
clang-tools-extra/clangd/ClangdServer.cpp | 14 ++++++++++----
clang-tools-extra/clangd/ClangdServer.h | 1 +
clang-tools-extra/clangd/unittests/ClangdTests.cpp | 10 ++++++++++
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 37eb82116f3a9..a176d8b2022e1 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -211,6 +211,15 @@ ClangdServer::Options::operator TUScheduler::Options() const {
return Opts;
}
+ClangdServer::Options::operator BackgroundIndex::Options() const {
+ BackgroundIndex::Options Opts;
+ Opts.ThreadPoolSize = std::max(AsyncThreadsCount, 1u);
+ Opts.IndexingPriority = BackgroundIndexPriority;
+ Opts.ContextProvider = ContextProvider;
+ Opts.SupportContainedRefs = EnableOutgoingCalls;
+ return Opts;
+}
+
ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
const ThreadsafeFS &TFS, const Options &Opts,
Callbacks *Callbacks)
@@ -253,14 +262,11 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
if (Opts.StaticIndex)
AddIndex(Opts.StaticIndex);
if (Opts.BackgroundIndex) {
- BackgroundIndex::Options BGOpts;
- BGOpts.ThreadPoolSize = std::max(Opts.AsyncThreadsCount, 1u);
+ BackgroundIndex::Options BGOpts(Opts);
BGOpts.OnProgress = [Callbacks](BackgroundQueue::Stats S) {
if (Callbacks)
Callbacks->onBackgroundIndexProgress(S);
};
- BGOpts.ContextProvider = Opts.ContextProvider;
- BGOpts.SupportContainedRefs = Opts.EnableOutgoingCalls;
BackgroundIdx = std::make_unique<BackgroundIndex>(
TFS, CDB,
BackgroundIndexStorage::createDiskBackedStorageFactory(
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 264ab7437c248..125aa761619bb 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -203,6 +203,7 @@ class ClangdServer {
bool PublishInactiveRegions = false;
explicit operator TUScheduler::Options() const;
+ explicit operator BackgroundIndex::Options() const;
};
// Sensible default options for use in tests.
// Features like indexing must be enabled if desired.
diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index 9ea7c3e02411d..6e99d7f2583b6 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1361,6 +1361,16 @@ int endPreamble;
Source.range("inactive3"), Source.range("inactive4"))));
}
+TEST(ClangdServer, BackgroundIndexPriorityPropagatesToIndexingThreads) {
+ auto Opts = ClangdServer::optsForTest();
+ for (auto Priority :
+ {llvm::ThreadPriority::Background, llvm::ThreadPriority::Low,
+ llvm::ThreadPriority::Default}) {
+ Opts.BackgroundIndexPriority = Priority;
+ EXPECT_EQ(BackgroundIndex::Options(Opts).IndexingPriority, Priority);
+ }
+}
+
} // namespace
} // namespace clangd
} // namespace clang
More information about the cfe-commits
mailing list