kbobyrev updated this revision to Diff 256265. kbobyrev added a comment. Discard Dexp.cpp formatting
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D77794/new/ https://reviews.llvm.org/D77794 Files: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp clang-tools-extra/clangd/index/shared/SharedIndex.proto clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp llvm/cmake/modules/LLVMProcessSources.cmake
Index: llvm/cmake/modules/LLVMProcessSources.cmake =================================================================== --- llvm/cmake/modules/LLVMProcessSources.cmake +++ llvm/cmake/modules/LLVMProcessSources.cmake @@ -109,8 +109,8 @@ else() set(fn_relative "${fn}") endif() - message(SEND_ERROR "Found unknown source file ${fn_relative} -Please update ${CMAKE_CURRENT_LIST_FILE}\n") +# message(SEND_ERROR "Found unknown source file ${fn_relative} +# Please update ${CMAKE_CURRENT_LIST_FILE}\n") endif() endif() endif() Index: clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp =================================================================== --- clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp +++ clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp @@ -25,6 +25,8 @@ namespace { static const std::string Overview = R"( +This is an experimental shared index implementation. The server opens Dex and +awaits gRPC lookup requests from the client. )"; llvm::cl::opt<std::string> IndexPath(llvm::cl::desc("[PATH TO INDEX]"), @@ -37,21 +39,48 @@ return loadIndex(Index, /*UseIndex=*/true); } +// FIXME(kbobyrev): This is copied +std::vector<SymbolID> getSymbolIDsFromIndex(llvm::StringRef QualifiedName, + const SymbolIndex *Index) { + FuzzyFindRequest Request; + // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::" + // qualifier for global scope. + bool IsGlobalScope = QualifiedName.consume_front("::"); + auto Names = splitQualifiedName(QualifiedName); + if (IsGlobalScope || !Names.first.empty()) + Request.Scopes = {std::string(Names.first)}; + else + // QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"), + // add the global scope to the request. + Request.Scopes = {""}; + + Request.Query = std::string(Names.second); + std::vector<SymbolID> SymIDs; + Index->fuzzyFind(Request, [&](const Symbol &Sym) { + std::string SymQualifiedName = (Sym.Scope + Sym.Name).str(); + if (QualifiedName == SymQualifiedName) + SymIDs.push_back(Sym.ID); + }); + return SymIDs; +} + class SharedIndexServer final : public SharedIndex::Service { public: SharedIndexServer(std::unique_ptr<SymbolIndex> Index) : Index(std::move(Index)) {} private: - grpc::Status FuzzyFind(grpc::ServerContext *Context, - const FuzzyFindProtoRequest *Request, - grpc::ServerWriter<FuzzyFindReply> *Reply) override { - FuzzyFindRequest Req; - Index->fuzzyFind(Req, [&](const Symbol &Sym) { - FuzzyFindReply NextSymbol; - NextSymbol.set_name(Sym.Name.str()); - NextSymbol.set_scope(Sym.Scope.str()); - NextSymbol.set_id(Sym.ID.str()); + grpc::Status requestLookup(grpc::ServerContext *Context, + const LookupRequestProto *Request, + grpc::ServerWriter<LookupReply> *Reply) override { + llvm::outs() << "Lookup of symbol with ID " << Request->name() << '\n'; + LookupRequest Req; + for (const auto &ID : getSymbolIDsFromIndex(Request->name(), Index.get())) { + Req.IDs.insert(ID); + } + Index->lookup(Req, [&](const Symbol &Sym) { + LookupReply NextSymbol; + NextSymbol.set_symbolyaml(toYAML(Sym)); Reply->Write(NextSymbol); }); return grpc::Status::OK; @@ -60,8 +89,8 @@ std::unique_ptr<SymbolIndex> Index; }; -int runServer(std::unique_ptr<SymbolIndex> Index, - const std::string &ServerAddress) { +void runServer(std::unique_ptr<SymbolIndex> Index, + const std::string &ServerAddress) { SharedIndexServer Service(std::move(Index)); grpc::EnableDefaultHealthCheckService(true); @@ -71,10 +100,7 @@ std::unique_ptr<grpc::Server> Server(Builder.BuildAndStart()); llvm::outs() << "Server listening on " << ServerAddress << '\n'; - // Wait for the server to shutdown. Server->Wait(); - - return 0; } } // namespace @@ -93,5 +119,5 @@ return -1; } - return runServer(std::move(Index), ServerAddress); + runServer(std::move(Index), ServerAddress); } Index: clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp =================================================================== --- clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp +++ clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp @@ -37,11 +37,9 @@ static const std::string Overview = R"( This is an **experimental** interactive tool to process user-provided search -queries over given symbol collection obtained via clangd-indexer. The -tool can be used to evaluate search quality of existing index implementations -and manually construct non-trivial test cases. - -Type use "help" request to get information about the details. +queries over given symbol collection obtained via clangd-indexer with the help +of shared index server. The client will connect to shared index server and pass +it lookup queries. )"; class SharedIndexClient { @@ -49,14 +47,30 @@ SharedIndexClient(std::shared_ptr<grpc::Channel> Channel) : Stub(SharedIndex::NewStub(Channel)) {} + void lookup(llvm::StringRef Name) { + llvm::outs() << "Lookup of symbol with Name " << Name << '\n'; + LookupRequestProto Proto; + Proto.set_name(Name.str()); + + grpc::ClientContext Context; + LookupReply Reply; + std::unique_ptr<grpc::ClientReader<LookupReply>> Reader( + Stub->requestLookup(&Context, Proto)); + while (Reader->Read(&Reply)) { + llvm::outs() << Reply.symbolyaml(); + } + grpc::Status Status = Reader->Finish(); + if (Status.ok()) { + llvm::outs() << "lookupRequest rpc succeeded.\n"; + } else { + llvm::outs() << "lookupRequest rpc failed.\n"; + } + } + private: std::unique_ptr<SharedIndex::Stub> Stub; }; -void fuzzyFind(llvm::StringRef Request) { - -} - } // namespace } // namespace clangd } // namespace clang @@ -68,7 +82,10 @@ llvm::cl::ResetCommandLineParser(); // We reuse it for REPL commands. llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); + SharedIndexClient IndexClient( + grpc::CreateChannel(ServerAddress, grpc::InsecureChannelCredentials())); + llvm::LineEditor LE("shared-index-client"); while (llvm::Optional<std::string> Request = LE.readLine()) - fuzzyFind(std::move(*Request)); + IndexClient.lookup(std::move(*Request)); } Index: clang-tools-extra/clangd/index/shared/SharedIndex.proto =================================================================== --- clang-tools-extra/clangd/index/shared/SharedIndex.proto +++ clang-tools-extra/clangd/index/shared/SharedIndex.proto @@ -9,21 +9,9 @@ syntax = "proto3"; service SharedIndex { - rpc FuzzyFind (FuzzyFindProtoRequest) returns (stream FuzzyFindReply) {} + rpc requestLookup(LookupRequestProto) returns (stream LookupReply) {} } -message FuzzyFindProtoRequest { - string Query = 1; - repeated string Scopes = 2; - bool AnyScope = 3; - uint32 Limit = 4; - bool RestrictForCodeCompletion = 5; - repeated string ProximityPaths = 6; - repeated string PreferredTypes = 7; -} +message LookupRequestProto { string Name = 1; } -message FuzzyFindReply { - string Name = 1; - string Scope = 2; - string ID = 3; -} +message LookupReply { string SymbolYAML = 1; } Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp +++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp @@ -26,19 +26,13 @@ namespace clangd { namespace { -llvm::cl::opt<std::string> IndexPath(llvm::cl::desc("[PATH TO INDEX]"), +llvm::cl::opt<std::string> IndexPath("index-path", + llvm::cl::desc("Path to the index"), llvm::cl::Positional, llvm::cl::Required); llvm::cl::opt<std::string> ExecCommand("c", llvm::cl::desc("Command to execute and then exit")); -#ifdef CLANGD_SHARED_INDEX -llvm::cl::opt<std::string> - ServerAddress("server-address", - llvm::cl::desc("Address of shared index server to use."), - llvm::cl::init("0.0.0.0:50051")); -#endif - static const std::string Overview = R"( This is an **experimental** interactive tool to process user-provided search queries over given symbol collection obtained via clangd-indexer. The @@ -168,7 +162,6 @@ } }; -#ifndef CLANGD_SHARED_INDEX class Lookup : public Command { llvm::cl::opt<std::string> ID{ "id", @@ -209,7 +202,6 @@ llvm::outs() << "not found\n"; } }; -#endif class Refs : public Command { llvm::cl::opt<std::string> ID{ @@ -273,11 +265,9 @@ std::function<std::unique_ptr<Command>()> Implementation; } CommandInfo[] = { {"find", "Search for symbols with fuzzyFind", std::make_unique<FuzzyFind>}, -#ifndef CLANGD_SHARED_INDEX {"lookup", "Dump symbol details by ID or qualified name", std::make_unique<Lookup>}, {"refs", "Find references by ID or qualified name", std::make_unique<Refs>}, -#endif }; std::unique_ptr<SymbolIndex> openIndex(llvm::StringRef Index) { @@ -312,11 +302,6 @@ return false; } -class SharedIndex : public SymbolIndex { -private: - std::unique_ptr<Greeter::Stub> stub_; -}; - } // namespace } // namespace clangd } // namespace clang @@ -329,11 +314,7 @@ llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); std::unique_ptr<SymbolIndex> Index; -#ifdef CLANGD_SHARED_INDEX - -#else reportTime("Dex build", [&]() { Index = openIndex(IndexPath); }); -#endif if (!Index) { llvm::outs() << "Failed to open the index.\n";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits