[PATCH] D53644: [clangd] workspace/symbol should be async, it reads from the index.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 24 06:48:28 PDT 2018
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, jfb, arphaman, jkorous, MaskRay, ioeric, javed.absar.
To enable this, TUScheduler has to provide a way to run async tasks without
needing a preamble or AST!
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D53644
Files:
clangd/ClangdServer.cpp
clangd/TUScheduler.cpp
clangd/TUScheduler.h
unittests/clangd/TUSchedulerTests.cpp
Index: unittests/clangd/TUSchedulerTests.cpp
===================================================================
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -532,6 +532,18 @@
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.fetch_add(1); });
+ S.run("add 2", [&] { Counter.fetch_add(2); });
+ ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+ EXPECT_EQ(Counter.load(), 3);
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clangd/TUScheduler.h
===================================================================
--- clangd/TUScheduler.h
+++ clangd/TUScheduler.h
@@ -108,6 +108,9 @@
/// 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
Index: clangd/TUScheduler.cpp
===================================================================
--- clangd/TUScheduler.cpp
+++ clangd/TUScheduler.cpp
@@ -720,6 +720,12 @@
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) {
Index: clangd/ClangdServer.cpp
===================================================================
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -482,8 +482,15 @@
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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53644.170874.patch
Type: text/x-patch
Size: 2736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181024/563bc35c/attachment.bin>
More information about the cfe-commits
mailing list