diff --git a/clang-tools-extra/clangd/index/remote/Index.proto b/clang-tools-extra/clangd/index/remote/Index.proto --- a/clang-tools-extra/clangd/index/remote/Index.proto +++ b/clang-tools-extra/clangd/index/remote/Index.proto @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -syntax = "proto3"; +syntax = "proto2"; package clang.clangd.remote.v1; // Semantics of SymbolIndex match clangd::SymbolIndex with all required // structures corresponding to their clangd::* counterparts. +// NOTE: Enum values are offset by one to detect missing values. service SymbolIndex { rpc Lookup(LookupRequest) returns (stream LookupReply) {} @@ -34,11 +35,11 @@ } message FuzzyFindRequest { - string query = 1; + optional string query = 1; repeated string scopes = 2; - bool any_scope = 3; - uint32 limit = 4; - bool restricted_for_code_completion = 5; + optional bool any_scope = 3; + optional uint32 limit = 4; + optional bool restricted_for_code_completion = 5; repeated string proximity_paths = 6; repeated string preferred_types = 7; } @@ -54,8 +55,8 @@ message RefsRequest { repeated string ids = 1; - uint32 filter = 2; - uint32 limit = 3; + optional uint32 filter = 2; + optional uint32 limit = 3; } // The response is a stream of reference messages, and one terminating has_more @@ -68,59 +69,59 @@ } message Symbol { - string id = 1; - SymbolInfo info = 2; - string name = 3; - SymbolLocation definition = 4; - string scope = 5; - SymbolLocation canonical_declaration = 6; - int32 references = 7; - uint32 origin = 8; - string signature = 9; - string template_specialization_args = 10; - string completion_snippet_suffix = 11; - string documentation = 12; - string return_type = 13; - string type = 14; + optional string id = 1; + optional SymbolInfo info = 2; + optional string name = 3; + optional SymbolLocation definition = 4; + optional string scope = 5; + optional SymbolLocation canonical_declaration = 6; + optional int32 references = 7; + optional uint32 origin = 8; + optional string signature = 9; + optional string template_specialization_args = 10; + optional string completion_snippet_suffix = 11; + optional string documentation = 12; + optional string return_type = 13; + optional string type = 14; repeated HeaderWithReferences headers = 15; - uint32 flags = 16; + optional uint32 flags = 16; } message Ref { - SymbolLocation location = 1; - uint32 kind = 2; + optional SymbolLocation location = 1; + optional uint32 kind = 2; } message SymbolInfo { - uint32 kind = 1; - uint32 subkind = 2; - uint32 language = 3; - uint32 properties = 4; + optional uint32 kind = 1; + optional uint32 subkind = 2; + optional uint32 language = 3; + optional uint32 properties = 4; } message SymbolLocation { - Position start = 1; - Position end = 2; + optional Position start = 1; + optional Position end = 2; // clangd::SymbolLocation stores FileURI, but the protocol transmits a the // relative path. Because paths are different on the remote and local machines // they will be translated in the marshalling layer. - string file_path = 3; + optional string file_path = 3; } message Position { - uint32 line = 1; - uint32 column = 2; + optional uint32 line = 1; + optional uint32 column = 2; } message HeaderWithReferences { - string header = 1; - uint32 references = 2; + optional string header = 1; + optional uint32 references = 2; } message RelationsRequest { repeated string subjects = 1; - uint32 predicate = 2; - uint32 limit = 3; + optional uint32 predicate = 2; + optional uint32 limit = 3; } // The response is a stream of reference messages, and one terminating has_more @@ -135,6 +136,6 @@ // This struct does not mirror clangd::Relation but rather the arguments of // SymbolIndex::relations callback. message Relation { - string subject_id = 1; - Symbol object = 2; + optional string subject_id = 1; + optional Symbol object = 2; } diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp --- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp +++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp @@ -11,6 +11,7 @@ #include "Index.pb.h" #include "Protocol.h" #include "index/Index.h" +#include "index/Ref.h" #include "index/Serialization.h" #include "index/Symbol.h" #include "index/SymbolID.h" @@ -114,7 +115,12 @@ if (!IDs) return IDs.takeError(); Req.IDs = std::move(*IDs); - Req.Filter = static_cast(Message->filter()); + // This sets a default for RefKind. Doing it explicitly in proto definition + // is error-prone because clangd::RefKind::All can change unexpectedly. + if (Message->has_filter()) + Req.Filter = static_cast(Message->filter()); + else + Req.Filter = clangd::RefKind::All; if (Message->limit()) Req.Limit = Message->limit(); return Req; @@ -127,7 +133,10 @@ if (!IDs) return IDs.takeError(); Req.Subjects = std::move(*IDs); + if (!Message->has_predicate()) + return error("RelationnsRequest requires RelationKind predicate."); Req.Predicate = static_cast(Message->predicate()); + if (Message->limit()) Req.Limit = Message->limit(); return Req; @@ -180,7 +189,7 @@ if (!Location) return Location.takeError(); Result.Location = *Location; - Result.Kind = static_cast(Message.kind()); + Result.Kind = static_cast(Message.kind()); return Result; } diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp --- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp +++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp @@ -377,6 +377,7 @@ EXPECT_EQ(static_cast(Serialized.subjects_size()), Request.Subjects.size()); EXPECT_EQ(Serialized.limit(), Request.Limit); + // Serialized enums are offset by one. EXPECT_EQ(static_cast(Serialized.predicate()), Request.Predicate); auto Deserialized = ProtobufMarshaller.fromProtobuf(&Serialized);