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());


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());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to