Skip to content

Commit

Permalink
feat(proto_indexer): add labels to field MarkedSource (#5838)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Sep 11, 2023
1 parent 71b5038 commit 1552f67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
16 changes: 16 additions & 0 deletions kythe/cxx/indexer/proto/marked_source.cc
Expand Up @@ -96,6 +96,22 @@ std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
full_name = descriptor->full_name();
}
MarkedSource ms;
if (!descriptor->containing_oneof() && descriptor->label()) {
auto* mod = ms.add_child();
mod->set_kind(MarkedSource::MODIFIER);
switch (descriptor->label()) {
case google::protobuf::FieldDescriptor::Label::LABEL_OPTIONAL:
mod->set_pre_text("optional");
break;
case google::protobuf::FieldDescriptor::Label::LABEL_REQUIRED:
mod->set_pre_text("required");
break;
case google::protobuf::FieldDescriptor::Label::LABEL_REPEATED:
mod->set_pre_text("repeated");
break;
}
mod->set_post_text(" ");
}
auto* type = ms.add_child();
type->set_kind(MarkedSource::TYPE);
switch (descriptor->type()) {
Expand Down
5 changes: 4 additions & 1 deletion kythe/cxx/indexer/proto/testdata/basic/message-fields.proto
Expand Up @@ -16,7 +16,10 @@ message MessageFields {
//- FieldNameNode.subkind field
//- FieldNameNode typed Type1Node
//- FieldNameNode code FNRoot
//- FNRoot child.1 FNName
//- FNRoot child.0 FNLabel
//- FNLabel.kind "MODIFIER"
//- FNLabel.pre_text "optional"
//- FNRoot child.2 FNName
//- FNName child.0 FNQualName
//- FNName child.1 FNIdent
//- FNIdent.pre_text field_name
Expand Down
8 changes: 4 additions & 4 deletions kythe/cxx/indexer/proto/testdata/basic/signatures.proto
Expand Up @@ -10,22 +10,22 @@ package proto_kythe_test;
message Message {
//- @R defines/binding R
//- R.code/rendered/qualified_name "proto_kythe_test.Message.R"
//- R.code/rendered/signature "string R"
//- R.code/rendered/signature "required string R"
required string R = 1;

//- @I defines/binding I
//- I.code/rendered/qualified_name "proto_kythe_test.Message.I"
//- I.code/rendered/signature "int32 I"
//- I.code/rendered/signature "optional int32 I"
optional int32 I = 2;

//- @L defines/binding L
//- L.code/rendered/qualified_name "proto_kythe_test.Message.L"
//- L.code/rendered/signature "Message L"
//- L.code/rendered/signature "repeated Message L"
repeated Message L = 3;

//- @#1E defines/binding E
//- E.code/rendered/qualified_name "proto_kythe_test.Message.E"
//- E.code/rendered/signature "Enum E"
//- E.code/rendered/signature "optional Enum E"
optional Enum E = 4;
}

Expand Down

0 comments on commit 1552f67

Please sign in to comment.