[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
Thu Oct 25 07:21:25 PDT 2018


This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rCTE345268: [clangd] workspace/symbol should be async, it reads from the index. (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53644?vs=170874&id=171090#toc

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; });
+  S.run("add 2", [&] { Counter += 2; });
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  EXPECT_EQ(Counter.load(), 3);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
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/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/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.171090.patch
Type: text/x-patch
Size: 2717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181025/aa15898d/attachment.bin>


More information about the cfe-commits mailing list