Skip to content

Commit

Permalink
feat(proto_indexer): add types to field MarkedSource (#5837)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Sep 11, 2023
1 parent aca6a8a commit 71b5038
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
22 changes: 21 additions & 1 deletion kythe/cxx/indexer/proto/marked_source.cc
Expand Up @@ -96,7 +96,27 @@ std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
full_name = descriptor->full_name();
}
MarkedSource ms;
if (GenerateMarkedSourceForDottedName(full_name, &ms)) {
auto* type = ms.add_child();
type->set_kind(MarkedSource::TYPE);
switch (descriptor->type()) {
case google::protobuf::FieldDescriptor::TYPE_MESSAGE:
if (!GenerateMarkedSourceForDottedName(
descriptor->message_type()->full_name(), type->add_child())) {
return std::nullopt;
}
break;
case google::protobuf::FieldDescriptor::TYPE_ENUM:
if (!GenerateMarkedSourceForDottedName(
descriptor->enum_type()->full_name(), type->add_child())) {
return std::nullopt;
}
break;
default:
type->set_pre_text(descriptor->type_name());
break;
}
type->set_post_text(" ");
if (GenerateMarkedSourceForDottedName(full_name, ms.add_child())) {
return ms;
}
return std::nullopt;
Expand Down
5 changes: 3 additions & 2 deletions kythe/cxx/indexer/proto/testdata/basic/message-fields.proto
Expand Up @@ -16,8 +16,9 @@ message MessageFields {
//- FieldNameNode.subkind field
//- FieldNameNode typed Type1Node
//- FieldNameNode code FNRoot
//- FNRoot child.0 FNQualName
//- FNRoot child.1 FNIdent
//- FNRoot child.1 FNName
//- FNName child.0 FNQualName
//- FNName child.1 FNIdent
//- FNIdent.pre_text field_name
//- FNIdent.kind "IDENTIFIER"
//- FNQualName.kind "CONTEXT"
Expand Down
8 changes: 6 additions & 2 deletions kythe/cxx/indexer/proto/testdata/basic/oneof.proto
Expand Up @@ -26,8 +26,12 @@ message Container {
//- TextVariant childof ContainerMessage
//- TextVariant childof NamedVariantType
//- TextVariant code TVRoot
//- TVRoot child.0 TVContext
//- TVRoot child.1 TVIdent
//- TVRoot child.0 TVType
//- TVType.kind "TYPE"
//- TVType.pre_text "string"
//- TVRoot child.1 TVName
//- TVName child.0 TVContext
//- TVName child.1 TVIdent
//- TVIdent.pre_text "text"
//- TVContext child.0 TVContext0
//- TVContext child.1 TVContext1
Expand Down
11 changes: 8 additions & 3 deletions kythe/cxx/indexer/proto/testdata/basic/signatures.proto
Expand Up @@ -10,18 +10,23 @@ package proto_kythe_test;
message Message {
//- @R defines/binding R
//- R.code/rendered/qualified_name "proto_kythe_test.Message.R"
//- R.code/rendered/signature "R"
//- R.code/rendered/signature "string R"
required string R = 1;

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

//- @L defines/binding L
//- L.code/rendered/qualified_name "proto_kythe_test.Message.L"
//- L.code/rendered/signature "L"
//- L.code/rendered/signature "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"
optional Enum E = 4;
}

//- @Enum defines/binding Enum
Expand Down

0 comments on commit 71b5038

Please sign in to comment.