diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -44,6 +44,7 @@ #include "TUScheduler.h" #include "Cancellation.h" #include "Compiler.h" +#include "Context.h" #include "Diagnostics.h" #include "GlobalCompilationDatabase.h" #include "Logger.h" @@ -919,7 +920,11 @@ llvm::unique_function Action) { if (!PreambleTasks) return Action(); - PreambleTasks->runAsync(Name, std::move(Action)); + PreambleTasks->runAsync(Name, [Ctx = Context::current().clone(), + Action = std::move(Action)]() mutable { + WithContext WC(std::move(Ctx)); + Action(); + }); } void TUScheduler::runWithAST( diff --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp --- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp +++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp @@ -688,6 +688,15 @@ S.run("add 2", [&] { Counter += 2; }); ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10))); EXPECT_EQ(Counter.load(), 3); + + Notification TaskRun; + Key TestKey; + WithContextValue CtxWithKey(TestKey, 10); + S.run("props context", [&] { + EXPECT_EQ(Context::current().getExisting(TestKey), 10); + TaskRun.notify(); + }); + TaskRun.wait(); } TEST_F(TUSchedulerTests, TUStatus) {