Skip to content

[clangd] Respect background index priority - #212700

Open
why-does-ie-still-exist wants to merge 1 commit into
llvm:mainfrom
why-does-ie-still-exist:micowens/bg-index-fix
Open

[clangd] Respect background index priority#212700
why-does-ie-still-exist wants to merge 1 commit into
llvm:mainfrom
why-does-ie-still-exist:micowens/bg-index-fix

Conversation

@why-does-ie-still-exist

@why-does-ie-still-exist why-does-ie-still-exist commented Jul 29, 2026

Copy link
Copy Markdown

The --background-index-priority CLI option was not wired correctly, leading to it being always 'low' even when otherwise specified.

This code was written by Claude Opus 5. I wrote the description myself and read the code.

The --background-index-priority CLI option was not wired correctly, leading to it being always 'low' even when otherwise specified.
@github-actions

Copy link
Copy Markdown

Hello @why-does-ie-still-exist 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions

llvmorg-github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Michael Owens (why-does-ie-still-exist)

Changes

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 --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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant