[PATCH] D54106: [clangd] Limit the index-returned results in dexp.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 6 03:11:11 PST 2018


hokein updated this revision to Diff 172736.
hokein added a comment.

Update based on the offline discussion.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54106

Files:
  clangd/index/dex/dexp/Dexp.cpp


Index: clangd/index/dex/dexp/Dexp.cpp
===================================================================
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -50,8 +50,10 @@
 }
 
 std::vector<SymbolID> getSymbolIDsFromIndex(StringRef QualifiedName,
-                                            const SymbolIndex *Index) {
+                                            const SymbolIndex *Index,
+                                            unsigned Limit) {
   FuzzyFindRequest Request;
+  Request.Limit = Limit;
   // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
   // qualifier for global scope.
   bool IsGlobalScope = QualifiedName.consume_front("::");
@@ -158,6 +160,12 @@
   cl::opt<std::string> Name{
       "name", cl::desc("Qualified name to look up."),
   };
+  cl::opt<unsigned> Limit{
+      "limit",
+      cl::init(10),
+      cl::desc("Max results to display. This flag is only meaningful when -name"
+               " is set."),
+  };
 
   void run() override {
     if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
@@ -173,7 +181,7 @@
       }
       IDs.push_back(*SID);
     } else {
-      IDs = getSymbolIDsFromIndex(Name, Index);
+      IDs = getSymbolIDsFromIndex(Name, Index, Limit);
     }
 
     LookupRequest Request;
@@ -216,7 +224,13 @@
       }
       IDs.push_back(*SID);
     } else {
-      IDs = getSymbolIDsFromIndex(Name, Index);
+      IDs = getSymbolIDsFromIndex(Name, Index, /*Limit=*/1);
+      if (IDs.size() != 1) {
+        outs() << formatv("The name {0} is ambiguous, found {1} different "
+                          "symbols. Please use id flag to disambiguate.\n",
+                          Name, IDs.size());
+        return;
+      }
     }
     RefsRequest RefRequest;
     RefRequest.IDs.insert(IDs.begin(), IDs.end());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54106.172736.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181106/fdd362bf/attachment-0001.bin>


More information about the cfe-commits mailing list