[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 9 03:42:59 PDT 2018


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ioeric, ilya-biryukov.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019

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
@@ -12,8 +12,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../Serialization.h"
-#include "../Dex.h"
+#include "Dex.h"
+#include "Serialization.h"
+#include "SourceCode.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -88,7 +89,6 @@
 };
 
 // FIXME(kbobyrev): Ideas for more commands:
-// * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
@@ -162,13 +162,46 @@
   }
 };
 
+class Refs : public Command {
+  cl::opt<std::string> QualifiedName{
+      "qualified_name", cl::Positional, cl::Required,
+      cl::desc("Qualified name of the symbol being queried."),
+  };
+  cl::opt<std::string> Filter{
+      "filter", cl::init(".*"),
+      cl::desc("Print all results from files matching this filter."),
+  };
+
+  void run() override {
+    FuzzyFindRequest Request;
+    Request.Limit = 1;
+    Request.Scopes.emplace_back();
+    std::tie(Request.Scopes.back(), Request.Query) =
+        clang::clangd::splitQualifiedName(QualifiedName);
+    clang::clangd::SymbolID ID;
+    Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+      llvm::outs() << "Find references for symbol " << Sym.Scope + Sym.Name
+                   << "\n";
+      ID = Sym.ID;
+    });
+    clang::clangd::RefsRequest RefRequest;
+    RefRequest.IDs.insert(ID);
+    llvm::Regex RegexFilter(Filter);
+    Index->refs(RefRequest, [&RegexFilter](const clang::clangd::Ref &R) {
+      if (RegexFilter.match(R.Location.FileURI))
+        llvm::outs() << R << "\n";
+    });
+  }
+};
+
 struct {
   const char *Name;
   const char *Description;
   std::function<std::unique_ptr<Command>()> Implementation;
 } CommandInfo[] = {
     {"find", "Search for symbols with fuzzyFind", llvm::make_unique<FuzzyFind>},
     {"lookup", "Dump symbol details by ID", llvm::make_unique<Lookup>},
+    {"refs", "Find references by qualified name", llvm::make_unique<Refs>},
 };
 
 } // namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53019.168773.patch
Type: text/x-patch
Size: 2400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181009/e4d26c78/attachment.bin>


More information about the cfe-commits mailing list