This revision was not accepted when it landed; it landed in state "Needs Revision". This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG81e5f298c431: [clangd] Give the server information about client's remote index protocol… (authored by kbobyrev).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89862/new/ https://reviews.llvm.org/D89862 Files: clang-tools-extra/clangd/index/remote/Client.cpp clang-tools-extra/clangd/index/remote/Index.proto clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp +++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp @@ -133,7 +133,7 @@ // Paths transmitted over the wire can not be absolute, they have to be // relative. - Ref WithAbsolutePath; + v1::Ref WithAbsolutePath; *WithAbsolutePath.mutable_location()->mutable_file_path() = "/usr/local/user/home/HelloWorld.cpp"; Deserialized = ProtobufMarshaller.fromProtobuf(WithAbsolutePath); @@ -282,7 +282,7 @@ Sym.IncludeHeaders.pop_back(); Serialized = ProtobufMarshaller.toProtobuf(Sym); ASSERT_TRUE(bool(Serialized)); - HeaderWithReferences InvalidHeader; + v1::HeaderWithReferences InvalidHeader; InvalidHeader.set_header(convert_to_slash("/absolute/path/Header.h")); InvalidHeader.set_references(9000); *Serialized->add_headers() = InvalidHeader; @@ -388,7 +388,7 @@ } TEST(RemoteMarshallingTest, RelationsRequestFailingSerialization) { - RelationsRequest Serialized; + v1::RelationsRequest Serialized; Serialized.add_subjects("ZZZZZZZZZZZZZZZZ"); Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/")); auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized); Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h =================================================================== --- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h +++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h @@ -38,32 +38,33 @@ Marshaller() = delete; Marshaller(llvm::StringRef RemoteIndexRoot, llvm::StringRef LocalIndexRoot); - llvm::Expected<clangd::Symbol> fromProtobuf(const Symbol &Message); - llvm::Expected<clangd::Ref> fromProtobuf(const Ref &Message); + llvm::Expected<clangd::Symbol> fromProtobuf(const v1::Symbol &Message); + llvm::Expected<clangd::Ref> fromProtobuf(const v1::Ref &Message); llvm::Expected<std::pair<clangd::SymbolID, clangd::Symbol>> - fromProtobuf(const Relation &Message); + fromProtobuf(const v1::Relation &Message); llvm::Expected<clangd::LookupRequest> - fromProtobuf(const LookupRequest *Message); + fromProtobuf(const v1::LookupRequest *Message); llvm::Expected<clangd::FuzzyFindRequest> - fromProtobuf(const FuzzyFindRequest *Message); - llvm::Expected<clangd::RefsRequest> fromProtobuf(const RefsRequest *Message); + fromProtobuf(const v1::FuzzyFindRequest *Message); + llvm::Expected<clangd::RefsRequest> + fromProtobuf(const v1::RefsRequest *Message); llvm::Expected<clangd::RelationsRequest> - fromProtobuf(const RelationsRequest *Message); + fromProtobuf(const v1::RelationsRequest *Message); /// toProtobuf() functions serialize native clangd types and strip IndexRoot /// from the file paths specific to indexing machine. fromProtobuf() functions /// deserialize clangd types and translate relative paths into machine-native /// URIs. - LookupRequest toProtobuf(const clangd::LookupRequest &From); - FuzzyFindRequest toProtobuf(const clangd::FuzzyFindRequest &From); - RefsRequest toProtobuf(const clangd::RefsRequest &From); - RelationsRequest toProtobuf(const clangd::RelationsRequest &From); + v1::LookupRequest toProtobuf(const clangd::LookupRequest &From); + v1::FuzzyFindRequest toProtobuf(const clangd::FuzzyFindRequest &From); + v1::RefsRequest toProtobuf(const clangd::RefsRequest &From); + v1::RelationsRequest toProtobuf(const clangd::RelationsRequest &From); - llvm::Expected<Symbol> toProtobuf(const clangd::Symbol &From); - llvm::Expected<Ref> toProtobuf(const clangd::Ref &From); - llvm::Expected<Relation> toProtobuf(const clangd::SymbolID &Subject, - const clangd::Symbol &Object); + llvm::Expected<v1::Symbol> toProtobuf(const clangd::Symbol &From); + llvm::Expected<v1::Ref> toProtobuf(const clangd::Ref &From); + llvm::Expected<v1::Relation> toProtobuf(const clangd::SymbolID &Subject, + const clangd::Symbol &Object); /// Translates \p RelativePath into the absolute path and builds URI for the /// user machine. This translation happens on the client side with the @@ -77,18 +78,18 @@ llvm::Expected<std::string> uriToRelativePath(llvm::StringRef URI); private: - clangd::SymbolLocation::Position fromProtobuf(const Position &Message); - Position toProtobuf(const clangd::SymbolLocation::Position &Position); - clang::index::SymbolInfo fromProtobuf(const SymbolInfo &Message); - SymbolInfo toProtobuf(const clang::index::SymbolInfo &Info); + clangd::SymbolLocation::Position fromProtobuf(const v1::Position &Message); + v1::Position toProtobuf(const clangd::SymbolLocation::Position &Position); + clang::index::SymbolInfo fromProtobuf(const v1::SymbolInfo &Message); + v1::SymbolInfo toProtobuf(const clang::index::SymbolInfo &Info); llvm::Expected<clangd::SymbolLocation> - fromProtobuf(const SymbolLocation &Message); - llvm::Expected<SymbolLocation> + fromProtobuf(const v1::SymbolLocation &Message); + llvm::Expected<v1::SymbolLocation> toProtobuf(const clangd::SymbolLocation &Location); - llvm::Expected<HeaderWithReferences> + llvm::Expected<v1::HeaderWithReferences> toProtobuf(const clangd::Symbol::IncludeHeaderWithReferences &IncludeHeader); llvm::Expected<clangd::Symbol::IncludeHeaderWithReferences> - fromProtobuf(const HeaderWithReferences &Message); + fromProtobuf(const v1::HeaderWithReferences &Message); /// RemoteIndexRoot and LocalIndexRoot are absolute paths to the project (on /// remote and local machine respectively) and include a trailing slash. One Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp =================================================================== --- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp +++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp @@ -72,7 +72,7 @@ } llvm::Expected<clangd::LookupRequest> -Marshaller::fromProtobuf(const LookupRequest *Message) { +Marshaller::fromProtobuf(const v1::LookupRequest *Message) { clangd::LookupRequest Req; auto IDs = getIDs(Message->ids()); if (!IDs) @@ -82,7 +82,7 @@ } llvm::Expected<clangd::FuzzyFindRequest> -Marshaller::fromProtobuf(const FuzzyFindRequest *Message) { +Marshaller::fromProtobuf(const v1::FuzzyFindRequest *Message) { assert(RemoteIndexRoot); clangd::FuzzyFindRequest Result; Result.Query = Message->query(); @@ -106,7 +106,7 @@ } llvm::Expected<clangd::RefsRequest> -Marshaller::fromProtobuf(const RefsRequest *Message) { +Marshaller::fromProtobuf(const v1::RefsRequest *Message) { clangd::RefsRequest Req; auto IDs = getIDs(Message->ids()); if (!IDs) @@ -119,7 +119,7 @@ } llvm::Expected<clangd::RelationsRequest> -Marshaller::fromProtobuf(const RelationsRequest *Message) { +Marshaller::fromProtobuf(const v1::RelationsRequest *Message) { clangd::RelationsRequest Req; auto IDs = getIDs(Message->subjects()); if (!IDs) @@ -131,7 +131,8 @@ return Req; } -llvm::Expected<clangd::Symbol> Marshaller::fromProtobuf(const Symbol &Message) { +llvm::Expected<clangd::Symbol> +Marshaller::fromProtobuf(const v1::Symbol &Message) { if (!Message.has_info() || !Message.has_canonical_declaration()) return error("Missing info or declaration."); clangd::Symbol Result; @@ -169,7 +170,7 @@ return Result; } -llvm::Expected<clangd::Ref> Marshaller::fromProtobuf(const Ref &Message) { +llvm::Expected<clangd::Ref> Marshaller::fromProtobuf(const v1::Ref &Message) { if (!Message.has_location()) return error("Missing location."); clangd::Ref Result; @@ -182,7 +183,7 @@ } llvm::Expected<std::pair<clangd::SymbolID, clangd::Symbol>> -Marshaller::fromProtobuf(const Relation &Message) { +Marshaller::fromProtobuf(const v1::Relation &Message) { auto SubjectID = SymbolID::fromStr(Message.subject_id()); if (!SubjectID) return SubjectID.takeError(); @@ -194,16 +195,17 @@ return std::make_pair(*SubjectID, *Object); } -LookupRequest Marshaller::toProtobuf(const clangd::LookupRequest &From) { - LookupRequest RPCRequest; +v1::LookupRequest Marshaller::toProtobuf(const clangd::LookupRequest &From) { + v1::LookupRequest RPCRequest; for (const auto &SymbolID : From.IDs) RPCRequest.add_ids(SymbolID.str()); return RPCRequest; } -FuzzyFindRequest Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) { +v1::FuzzyFindRequest +Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) { assert(LocalIndexRoot); - FuzzyFindRequest RPCRequest; + v1::FuzzyFindRequest RPCRequest; RPCRequest.set_query(From.Query); for (const auto &Scope : From.Scopes) RPCRequest.add_scopes(Scope); @@ -222,8 +224,8 @@ return RPCRequest; } -RefsRequest Marshaller::toProtobuf(const clangd::RefsRequest &From) { - RefsRequest RPCRequest; +v1::RefsRequest Marshaller::toProtobuf(const clangd::RefsRequest &From) { + v1::RefsRequest RPCRequest; for (const auto &ID : From.IDs) RPCRequest.add_ids(ID.str()); RPCRequest.set_filter(static_cast<uint32_t>(From.Filter)); @@ -232,8 +234,9 @@ return RPCRequest; } -RelationsRequest Marshaller::toProtobuf(const clangd::RelationsRequest &From) { - RelationsRequest RPCRequest; +v1::RelationsRequest +Marshaller::toProtobuf(const clangd::RelationsRequest &From) { + v1::RelationsRequest RPCRequest; for (const auto &ID : From.Subjects) RPCRequest.add_subjects(ID.str()); RPCRequest.set_predicate(static_cast<uint32_t>(From.Predicate)); @@ -242,8 +245,8 @@ return RPCRequest; } -llvm::Expected<Symbol> Marshaller::toProtobuf(const clangd::Symbol &From) { - Symbol Result; +llvm::Expected<v1::Symbol> Marshaller::toProtobuf(const clangd::Symbol &From) { + v1::Symbol Result; Result.set_id(From.ID.str()); *Result.mutable_info() = toProtobuf(From.SymInfo); Result.set_name(From.Name.str()); @@ -278,8 +281,8 @@ return Result; } -llvm::Expected<Ref> Marshaller::toProtobuf(const clangd::Ref &From) { - Ref Result; +llvm::Expected<v1::Ref> Marshaller::toProtobuf(const clangd::Ref &From) { + v1::Ref Result; Result.set_kind(static_cast<uint32_t>(From.Kind)); auto Location = toProtobuf(From.Location); if (!Location) @@ -288,9 +291,10 @@ return Result; } -llvm::Expected<Relation> Marshaller::toProtobuf(const clangd::SymbolID &Subject, - const clangd::Symbol &Object) { - Relation Result; +llvm::Expected<v1::Relation> +Marshaller::toProtobuf(const clangd::SymbolID &Subject, + const clangd::Symbol &Object) { + v1::Relation Result; *Result.mutable_subject_id() = Subject.str(); auto SerializedObject = toProtobuf(Object); if (!SerializedObject) @@ -335,22 +339,23 @@ } clangd::SymbolLocation::Position -Marshaller::fromProtobuf(const Position &Message) { +Marshaller::fromProtobuf(const v1::Position &Message) { clangd::SymbolLocation::Position Result; Result.setColumn(static_cast<uint32_t>(Message.column())); Result.setLine(static_cast<uint32_t>(Message.line())); return Result; } -Position +v1::Position Marshaller::toProtobuf(const clangd::SymbolLocation::Position &Position) { - remote::Position Result; + remote::v1::Position Result; Result.set_column(Position.column()); Result.set_line(Position.line()); return Result; } -clang::index::SymbolInfo Marshaller::fromProtobuf(const SymbolInfo &Message) { +clang::index::SymbolInfo +Marshaller::fromProtobuf(const v1::SymbolInfo &Message) { clang::index::SymbolInfo Result; Result.Kind = static_cast<clang::index::SymbolKind>(Message.kind()); Result.SubKind = static_cast<clang::index::SymbolSubKind>(Message.subkind()); @@ -360,8 +365,8 @@ return Result; } -SymbolInfo Marshaller::toProtobuf(const clang::index::SymbolInfo &Info) { - SymbolInfo Result; +v1::SymbolInfo Marshaller::toProtobuf(const clang::index::SymbolInfo &Info) { + v1::SymbolInfo Result; Result.set_kind(static_cast<uint32_t>(Info.Kind)); Result.set_subkind(static_cast<uint32_t>(Info.SubKind)); Result.set_language(static_cast<uint32_t>(Info.Lang)); @@ -370,7 +375,7 @@ } llvm::Expected<clangd::SymbolLocation> -Marshaller::fromProtobuf(const SymbolLocation &Message) { +Marshaller::fromProtobuf(const v1::SymbolLocation &Message) { clangd::SymbolLocation Location; auto URIString = relativePathToURI(Message.file_path()); if (!URIString) @@ -381,9 +386,9 @@ return Location; } -llvm::Expected<SymbolLocation> +llvm::Expected<v1::SymbolLocation> Marshaller::toProtobuf(const clangd::SymbolLocation &Location) { - remote::SymbolLocation Result; + remote::v1::SymbolLocation Result; auto RelativePath = uriToRelativePath(Location.FileURI); if (!RelativePath) return RelativePath.takeError(); @@ -393,9 +398,9 @@ return Result; } -llvm::Expected<HeaderWithReferences> Marshaller::toProtobuf( +llvm::Expected<v1::HeaderWithReferences> Marshaller::toProtobuf( const clangd::Symbol::IncludeHeaderWithReferences &IncludeHeader) { - HeaderWithReferences Result; + v1::HeaderWithReferences Result; Result.set_references(IncludeHeader.References); const std::string Header = IncludeHeader.IncludeHeader.str(); if (isLiteralInclude(Header)) { @@ -410,7 +415,7 @@ } llvm::Expected<clangd::Symbol::IncludeHeaderWithReferences> -Marshaller::fromProtobuf(const HeaderWithReferences &Message) { +Marshaller::fromProtobuf(const v1::HeaderWithReferences &Message) { std::string Header = Message.header(); if (!isLiteralInclude(Header)) { auto URIString = relativePathToURI(Header); Index: clang-tools-extra/clangd/index/remote/Index.proto =================================================================== --- clang-tools-extra/clangd/index/remote/Index.proto +++ clang-tools-extra/clangd/index/remote/Index.proto @@ -8,7 +8,7 @@ syntax = "proto3"; -package clang.clangd.remote; +package clang.clangd.remote.v1; // Semantics of SymbolIndex match clangd::SymbolIndex with all required // structures corresponding to their clangd::* counterparts. Index: clang-tools-extra/clangd/index/remote/Client.cpp =================================================================== --- clang-tools-extra/clangd/index/remote/Client.cpp +++ clang-tools-extra/clangd/index/remote/Client.cpp @@ -15,6 +15,7 @@ #include "marshalling/Marshalling.h" #include "support/Logger.h" #include "support/Trace.h" +#include "clang/Basic/Version.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" @@ -28,7 +29,8 @@ class IndexClient : public clangd::SymbolIndex { template <typename RequestT, typename ReplyT> using StreamingCall = std::unique_ptr<grpc::ClientReader<ReplyT>> ( - remote::SymbolIndex::Stub::*)(grpc::ClientContext *, const RequestT &); + remote::v1::SymbolIndex::Stub::*)(grpc::ClientContext *, + const RequestT &); template <typename RequestT, typename ReplyT, typename ClangdRequestT, typename CallbackT> @@ -40,6 +42,7 @@ const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request); SPAN_ATTACH(Tracer, "Request", RPCRequest.DebugString()); grpc::ClientContext Context; + Context.AddMetadata("version", clang::getClangToolFullVersion("clangd")); std::chrono::system_clock::time_point Deadline = std::chrono::system_clock::now() + DeadlineWaitingTime; Context.set_deadline(Deadline); @@ -73,7 +76,7 @@ IndexClient( std::shared_ptr<grpc::Channel> Channel, llvm::StringRef ProjectRoot, std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000)) - : Stub(remote::SymbolIndex::NewStub(Channel)), + : Stub(remote::v1::SymbolIndex::NewStub(Channel)), ProtobufMarshaller(new Marshaller(/*RemoteIndexRoot=*/"", /*LocalIndexRoot=*/ProjectRoot)), DeadlineWaitingTime(DeadlineTime) { @@ -82,25 +85,26 @@ void lookup(const clangd::LookupRequest &Request, llvm::function_ref<void(const clangd::Symbol &)> Callback) const { - streamRPC(Request, &remote::SymbolIndex::Stub::Lookup, Callback); + streamRPC(Request, &remote::v1::SymbolIndex::Stub::Lookup, Callback); } bool fuzzyFind(const clangd::FuzzyFindRequest &Request, llvm::function_ref<void(const clangd::Symbol &)> Callback) const { - return streamRPC(Request, &remote::SymbolIndex::Stub::FuzzyFind, Callback); + return streamRPC(Request, &remote::v1::SymbolIndex::Stub::FuzzyFind, + Callback); } bool refs(const clangd::RefsRequest &Request, llvm::function_ref<void(const clangd::Ref &)> Callback) const { - return streamRPC(Request, &remote::SymbolIndex::Stub::Refs, Callback); + return streamRPC(Request, &remote::v1::SymbolIndex::Stub::Refs, Callback); } void relations(const clangd::RelationsRequest &Request, llvm::function_ref<void(const SymbolID &, const clangd::Symbol &)> Callback) const { - streamRPC(Request, &remote::SymbolIndex::Stub::Relations, + streamRPC(Request, &remote::v1::SymbolIndex::Stub::Relations, // Unpack protobuf Relation. [&](std::pair<SymbolID, clangd::Symbol> SubjectAndObject) { Callback(SubjectAndObject.first, SubjectAndObject.second); @@ -112,7 +116,7 @@ size_t estimateMemoryUsage() const { return 0; } private: - std::unique_ptr<remote::SymbolIndex::Stub> Stub; + std::unique_ptr<remote::v1::SymbolIndex::Stub> Stub; std::unique_ptr<Marshaller> ProtobufMarshaller; // Each request will be terminated if it takes too long. std::chrono::milliseconds DeadlineWaitingTime;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits