summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp11
-rw-r--r--clang-tools-extra/clangd/TUScheduler.cpp6
-rw-r--r--clang-tools-extra/clangd/TUScheduler.h3
-rw-r--r--clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp12
4 files changed, 30 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index cd1fb33efe6..8da5dec414f 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -482,8 +482,15 @@ void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
void ClangdServer::workspaceSymbols(
StringRef Query, int Limit, Callback<std::vector<SymbolInformation>> CB) {
- CB(clangd::getWorkspaceSymbols(Query, Limit, Index,
- WorkspaceRoot.getValueOr("")));
+ std::string QueryCopy = Query;
+ WorkScheduler.run(
+ "getWorkspaceSymbols",
+ Bind(
+ [QueryCopy, Limit, this](decltype(CB) CB) {
+ CB(clangd::getWorkspaceSymbols(QueryCopy, Limit, Index,
+ WorkspaceRoot.getValueOr("")));
+ },
+ std::move(CB)));
}
void ClangdServer::documentSymbols(
diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index 0c5c6fbdb69..63e9c019c5b 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -720,6 +720,12 @@ void TUScheduler::remove(PathRef File) {
File);
}
+void TUScheduler::run(StringRef Name, unique_function<void()> Action) {
+ if (!PreambleTasks)
+ return Action();
+ PreambleTasks->runAsync(Name, std::move(Action));
+}
+
void TUScheduler::runWithAST(
StringRef Name, PathRef File,
unique_function<void(Expected<InputsAndAST>)> Action) {
diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h
index bfe495e2d4a..da3d5253343 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -108,6 +108,9 @@ public:
/// resources.
void remove(PathRef File);
+ /// Schedule an async task with no dependencies.
+ void run(llvm::StringRef Name, llvm::unique_function<void()> Action);
+
/// Schedule an async read of the AST. \p Action will be called when AST is
/// ready. The AST passed to \p Action refers to the version of \p File
/// tracked at the time of the call, even if new updates are received before
diff --git a/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp b/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
index 936a790c884..125e6be4781 100644
--- a/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
+++ b/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
@@ -532,6 +532,18 @@ TEST_F(TUSchedulerTests, NoChangeDiags) {
ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
}
+TEST_F(TUSchedulerTests, Run) {
+ TUScheduler S(/*AsyncThreadsCount=*/getDefaultAsyncThreadsCount(),
+ /*StorePreambleInMemory=*/true, /*ASTCallbacks=*/nullptr,
+ /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+ ASTRetentionPolicy());
+ std::atomic<int> Counter(0);
+ S.run("add 1", [&] { ++Counter; });
+ S.run("add 2", [&] { Counter += 2; });
+ ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ EXPECT_EQ(Counter.load(), 3);
+}
+
} // namespace
} // namespace clangd
} // namespace clang
OpenPOWER on IntegriCloud