[clang-tools-extra] 81e5f29 - [clangd] Give the server information about client's remote index protocol version
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 22 12:35:32 PDT 2020
Author: Kirill Bobyrev
Date: 2020-10-22T21:35:18+02:00
New Revision: 81e5f298c431555d809f898c196945ca879c1150
URL: https://github.com/llvm/llvm-project/commit/81e5f298c431555d809f898c196945ca879c1150
DIFF: https://github.com/llvm/llvm-project/commit/81e5f298c431555d809f898c196945ca879c1150.diff
LOG: [clangd] Give the server information about client's remote index protocol version
And also introduce Protobuf package versioning, it will help to deal
with breaking changes. Inroducing package version itself is a breaking
change, clients and servers need to be updated.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D89862
Added:
Modified:
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
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/index/remote/Client.cpp b/clang-tools-extra/clangd/index/remote/Client.cpp
index 131e4c0b2fce..d01dd4483974 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/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 @@ namespace {
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 @@ class IndexClient : public clangd::SymbolIndex {
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 @@ class IndexClient : public clangd::SymbolIndex {
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 @@ class IndexClient : public clangd::SymbolIndex {
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 @@ class IndexClient : public clangd::SymbolIndex {
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;
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto b/clang-tools-extra/clangd/index/remote/Index.proto
index 305164ffef77..34c49756b1da 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/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.
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 6285022fc0a8..23ed67653b8b 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -72,7 +72,7 @@ Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
}
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 @@ Marshaller::fromProtobuf(const LookupRequest *Message) {
}
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 @@ Marshaller::fromProtobuf(const FuzzyFindRequest *Message) {
}
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 @@ Marshaller::fromProtobuf(const RefsRequest *Message) {
}
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 @@ Marshaller::fromProtobuf(const RelationsRequest *Message) {
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 @@ llvm::Expected<clangd::Symbol> Marshaller::fromProtobuf(const Symbol &Message) {
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<clangd::Ref> Marshaller::fromProtobuf(const Ref &Message) {
}
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 @@ Marshaller::fromProtobuf(const Relation &Message) {
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 @@ FuzzyFindRequest Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) {
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 @@ RefsRequest Marshaller::toProtobuf(const clangd::RefsRequest &From) {
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 @@ RelationsRequest Marshaller::toProtobuf(const clangd::RelationsRequest &From) {
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 @@ llvm::Expected<Symbol> Marshaller::toProtobuf(const clangd::Symbol &From) {
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 @@ llvm::Expected<Ref> Marshaller::toProtobuf(const clangd::Ref &From) {
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 @@ llvm::Expected<std::string> Marshaller::uriToRelativePath(llvm::StringRef URI) {
}
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 @@ clang::index::SymbolInfo Marshaller::fromProtobuf(const SymbolInfo &Message) {
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 @@ SymbolInfo Marshaller::toProtobuf(const clang::index::SymbolInfo &Info) {
}
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 @@ Marshaller::fromProtobuf(const SymbolLocation &Message) {
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 @@ Marshaller::toProtobuf(const clangd::SymbolLocation &Location) {
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<HeaderWithReferences> Marshaller::toProtobuf(
}
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);
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
index 18ce6074264c..9faa55e77e24 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
@@ -38,32 +38,33 @@ class Marshaller {
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 @@ class Marshaller {
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
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index 6ef8da59861f..df4811a8635c 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -133,7 +133,7 @@ TEST(RemoteMarshallingTest, URITranslation) {
// 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 @@ TEST(RemoteMarshallingTest, IncludeHeaderURIs) {
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, RelationsRequestSerialization) {
}
TEST(RemoteMarshallingTest, RelationsRequestFailingSerialization) {
- RelationsRequest Serialized;
+ v1::RelationsRequest Serialized;
Serialized.add_subjects("ZZZZZZZZZZZZZZZZ");
Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);
More information about the cfe-commits
mailing list