[clang-tools-extra] [clangd] Respect background index priority (PR #212700)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 29 00:37:06 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangd
Author: Michael Owens (why-does-ie-still-exist)
<details>
<summary>Changes</summary>
The --background-index-priority CLI option was not wired correctly, leading to it being always 'low' even when otherwise specified.
---
Full diff: https://github.com/llvm/llvm-project/pull/212700.diff
3 Files Affected:
- (modified) clang-tools-extra/clangd/ClangdServer.cpp (+10-4)
- (modified) clang-tools-extra/clangd/ClangdServer.h (+1)
- (modified) clang-tools-extra/clangd/unittests/ClangdTests.cpp (+10)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/212700
More information about the cfe-commits
mailing list