Skip to content

Commit c7ef0ac

Browse files
committed
[clangd] Drop required attributes from ContainedRef protos
Per https://protobuf.dev/programming-guides/dos-donts/#add-required this is discouraged and we already handle errors when marshalling protos. This also ensures new message types are consistent with the rest in the file.
1 parent 61fe67a commit c7ef0ac

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

clang-tools-extra/clangd/index/remote/Index.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ message Relation {
133133
}
134134

135135
message ContainedRefsRequest {
136-
required string id = 1;
136+
optional string id = 1;
137137
optional uint32 limit = 2;
138138
}
139139

@@ -145,7 +145,7 @@ message ContainedRefsReply {
145145
}
146146

147147
message ContainedRef {
148-
required SymbolLocation location = 1;
149-
required uint32 kind = 2;
150-
required string symbol = 3;
148+
optional SymbolLocation location = 1;
149+
optional uint32 kind = 2;
150+
optional string symbol = 3;
151151
}

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Marshaller::fromProtobuf(const RefsRequest *Message) {
129129
llvm::Expected<clangd::ContainedRefsRequest>
130130
Marshaller::fromProtobuf(const ContainedRefsRequest *Message) {
131131
clangd::ContainedRefsRequest Req;
132+
if (!Message->has_id())
133+
return error("ContainedRefsRequest requires an id.");
132134
auto ID = SymbolID::fromStr(Message->id());
133135
if (!ID)
134136
return ID.takeError();
@@ -207,6 +209,12 @@ llvm::Expected<clangd::Ref> Marshaller::fromProtobuf(const Ref &Message) {
207209
llvm::Expected<clangd::ContainedRefsResult>
208210
Marshaller::fromProtobuf(const ContainedRef &Message) {
209211
clangd::ContainedRefsResult Result;
212+
if (!Message.has_location())
213+
return error("ContainedRef must have a location.");
214+
if (!Message.has_kind())
215+
return error("ContainedRef must have a kind.");
216+
if (!Message.has_symbol())
217+
return error("ContainedRef must have a symbol.");
210218
auto Location = fromProtobuf(Message.location());
211219
if (!Location)
212220
return Location.takeError();

0 commit comments

Comments
 (0)