kadircet created this revision.
kadircet added reviewers: sammccall, dgoldman.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133479

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2589,7 +2589,8 @@
   Opts.Index = &Requests;
 
   auto CompleteAtPoint = [&](StringRef P) {
-    cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
+    auto CCR = cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
+    EXPECT_TRUE(CCR.HasMore);
   };
 
   CompleteAtPoint("1");
Index: clang-tools-extra/clangd/CodeComplete.h
===================================================================
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -31,6 +31,7 @@
 #include "llvm/ADT/StringRef.h"
 #include <functional>
 #include <future>
+#include <utility>
 
 namespace clang {
 class NamedDecl;
@@ -262,7 +263,7 @@
   llvm::Optional<FuzzyFindRequest> NewReq;
   /// The result is consumed by `codeComplete()` if speculation succeeded.
   /// NOTE: the destructor will wait for the async call to finish.
-  std::future<SymbolSlab> Result;
+  std::future<std::pair<bool /*Incomplete*/, SymbolSlab>> Result;
 };
 
 /// Gets code completions at a specified \p Pos in \p FileName.
Index: clang-tools-extra/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -70,6 +70,7 @@
 #include <algorithm>
 #include <iterator>
 #include <limits>
+#include <utility>
 
 // We log detailed candidate here if you run with -debug-only=codecomplete.
 #define DEBUG_TYPE "CodeComplete"
@@ -1343,13 +1344,14 @@
   llvm_unreachable("invalid NestedNameSpecifier kind");
 }
 
-std::future<SymbolSlab> startAsyncFuzzyFind(const SymbolIndex &Index,
-                                            const FuzzyFindRequest &Req) {
-  return runAsync<SymbolSlab>([&Index, Req]() {
+std::future<std::pair<bool, SymbolSlab>>
+startAsyncFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req) {
+  return runAsync<std::pair<bool, SymbolSlab>>([&Index, Req]() {
     trace::Span Tracer("Async fuzzyFind");
     SymbolSlab::Builder Syms;
-    Index.fuzzyFind(Req, [&Syms](const Symbol &Sym) { Syms.insert(Sym); });
-    return std::move(Syms).build();
+    bool Incomplete =
+        Index.fuzzyFind(Req, [&Syms](const Symbol &Sym) { Syms.insert(Sym); });
+    return std::make_pair(Incomplete, std::move(Syms).build());
   });
 }
 
@@ -1678,7 +1680,7 @@
   bool includeSymbolFromIndex(const Symbol &Sym) {
     if (CCContextKind == CodeCompletionContext::CCC_ObjCProtocolName) {
       return Sym.SymInfo.Lang == index::SymbolLanguage::ObjC &&
-          Sym.SymInfo.Kind == index::SymbolKind::Protocol;
+             Sym.SymInfo.Kind == index::SymbolKind::Protocol;
     }
     return true;
   }
@@ -1709,7 +1711,9 @@
       SPAN_ATTACH(Tracer, "Speculative results", true);
 
       trace::Span WaitSpec("Wait speculative results");
-      return SpecFuzzyFind->Result.get();
+      auto SpecRes = SpecFuzzyFind->Result.get();
+      Incomplete |= SpecRes.first;
+      return std::move(SpecRes.second);
     }
 
     SPAN_ATTACH(Tracer, "Speculative results", false);


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2589,7 +2589,8 @@
   Opts.Index = &Requests;
 
   auto CompleteAtPoint = [&](StringRef P) {
-    cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
+    auto CCR = cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
+    EXPECT_TRUE(CCR.HasMore);
   };
 
   CompleteAtPoint("1");
Index: clang-tools-extra/clangd/CodeComplete.h
===================================================================
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -31,6 +31,7 @@
 #include "llvm/ADT/StringRef.h"
 #include <functional>
 #include <future>
+#include <utility>
 
 namespace clang {
 class NamedDecl;
@@ -262,7 +263,7 @@
   llvm::Optional<FuzzyFindRequest> NewReq;
   /// The result is consumed by `codeComplete()` if speculation succeeded.
   /// NOTE: the destructor will wait for the async call to finish.
-  std::future<SymbolSlab> Result;
+  std::future<std::pair<bool /*Incomplete*/, SymbolSlab>> Result;
 };
 
 /// Gets code completions at a specified \p Pos in \p FileName.
Index: clang-tools-extra/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -70,6 +70,7 @@
 #include <algorithm>
 #include <iterator>
 #include <limits>
+#include <utility>
 
 // We log detailed candidate here if you run with -debug-only=codecomplete.
 #define DEBUG_TYPE "CodeComplete"
@@ -1343,13 +1344,14 @@
   llvm_unreachable("invalid NestedNameSpecifier kind");
 }
 
-std::future<SymbolSlab> startAsyncFuzzyFind(const SymbolIndex &Index,
-                                            const FuzzyFindRequest &Req) {
-  return runAsync<SymbolSlab>([&Index, Req]() {
+std::future<std::pair<bool, SymbolSlab>>
+startAsyncFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req) {
+  return runAsync<std::pair<bool, SymbolSlab>>([&Index, Req]() {
     trace::Span Tracer("Async fuzzyFind");
     SymbolSlab::Builder Syms;
-    Index.fuzzyFind(Req, [&Syms](const Symbol &Sym) { Syms.insert(Sym); });
-    return std::move(Syms).build();
+    bool Incomplete =
+        Index.fuzzyFind(Req, [&Syms](const Symbol &Sym) { Syms.insert(Sym); });
+    return std::make_pair(Incomplete, std::move(Syms).build());
   });
 }
 
@@ -1678,7 +1680,7 @@
   bool includeSymbolFromIndex(const Symbol &Sym) {
     if (CCContextKind == CodeCompletionContext::CCC_ObjCProtocolName) {
       return Sym.SymInfo.Lang == index::SymbolLanguage::ObjC &&
-          Sym.SymInfo.Kind == index::SymbolKind::Protocol;
+             Sym.SymInfo.Kind == index::SymbolKind::Protocol;
     }
     return true;
   }
@@ -1709,7 +1711,9 @@
       SPAN_ATTACH(Tracer, "Speculative results", true);
 
       trace::Span WaitSpec("Wait speculative results");
-      return SpecFuzzyFind->Result.get();
+      auto SpecRes = SpecFuzzyFind->Result.get();
+      Incomplete |= SpecRes.first;
+      return std::move(SpecRes.second);
     }
 
     SPAN_ATTACH(Tracer, "Speculative results", false);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to