#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"
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>
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);
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) {
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);
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;
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.
}
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)
}
llvm::Expected<clangd::FuzzyFindRequest>
-Marshaller::fromProtobuf(const FuzzyFindRequest *Message) {
+Marshaller::fromProtobuf(const v1::FuzzyFindRequest *Message) {
assert(RemoteIndexRoot);
clangd::FuzzyFindRequest Result;
Result.Query = Message->query();
}
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)
}
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)
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;
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;
}
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();
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);
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));
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));
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());
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)
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)
}
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());
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));
}
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)
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();
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)) {
}
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);
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
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
// 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);
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;
}
TEST(RemoteMarshallingTest, RelationsRequestFailingSerialization) {
- RelationsRequest Serialized;
+ v1::RelationsRequest Serialized;
Serialized.add_subjects("ZZZZZZZZZZZZZZZZ");
Marshaller ProtobufMarshaller(testPath("remote/"), testPath("local/"));
auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);