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,6 +162,38 @@ } }; +class Refs : public Command { + cl::opt QualifiedName{ + "qualified_name", cl::Positional, cl::Required, + cl::desc("Qualified name of the symbol being queried."), + }; + cl::opt 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; @@ -169,6 +201,7 @@ } CommandInfo[] = { {"find", "Search for symbols with fuzzyFind", llvm::make_unique}, {"lookup", "Dump symbol details by ID", llvm::make_unique}, + {"refs", "Find references by qualified name", llvm::make_unique}, }; } // namespace