Skip to content

Commit

Permalink
feat(proto_indexer): link the rest of the MarkedSource (#5866)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Sep 28, 2023
1 parent 774ac20 commit 7835faa
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 32 deletions.
27 changes: 16 additions & 11 deletions kythe/cxx/indexer/proto/file_descriptor_walker.cc
Expand Up @@ -566,8 +566,8 @@ void FileDescriptorWalker::VisitNestedEnumTypes(const std::string& message_name,
if (nested_proto->options().deprecated()) {
builder_->SetDeprecated(v_name);
}
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(nested_proto));
AttachMarkedSource(
v_name, GenerateMarkedSourceForDescriptor(nested_proto, builder_));
}

// Visit values
Expand Down Expand Up @@ -611,8 +611,8 @@ void FileDescriptorWalker::VisitNestedTypes(const std::string& message_name,
if (nested_proto->options().deprecated()) {
builder_->SetDeprecated(v_name);
}
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(nested_proto));
AttachMarkedSource(
v_name, GenerateMarkedSourceForDescriptor(nested_proto, builder_));
}

// Need to visit nested enum and message types first!
Expand Down Expand Up @@ -646,7 +646,8 @@ void FileDescriptorWalker::VisitOneofs(const std::string& message_name,
InitializeLocation(span, &location);

builder_->AddOneofToMessage(message, v_name, location);
AttachMarkedSource(v_name, GenerateMarkedSourceForDescriptor(oneof));
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(oneof, builder_));
}

// No need to add fields; they're also fields of the message
Expand Down Expand Up @@ -679,7 +680,8 @@ void FileDescriptorWalker::VisitMessagesAndEnums(const std::string* ns_name,
InitializeLocation(span, &location);

builder_->AddMessageType(ns, v_name, location);
AttachMarkedSource(v_name, GenerateMarkedSourceForDescriptor(dp));
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(dp, builder_));
if (dp->options().deprecated()) {
builder_->SetDeprecated(v_name);
}
Expand Down Expand Up @@ -713,7 +715,8 @@ void FileDescriptorWalker::VisitMessagesAndEnums(const std::string* ns_name,
InitializeLocation(span, &location);

builder_->AddEnumType(ns, v_name, location);
AttachMarkedSource(v_name, GenerateMarkedSourceForDescriptor(dp));
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(dp, builder_));
}

// Visit enum values and add kythe bindings for them
Expand Down Expand Up @@ -742,7 +745,8 @@ void FileDescriptorWalker::VisitEnumValues(const EnumDescriptor* dp,
if (val_dp->options().deprecated()) {
builder_->SetDeprecated(v_name);
}
AttachMarkedSource(v_name, GenerateMarkedSourceForDescriptor(val_dp));
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(val_dp, builder_));
}
}

Expand Down Expand Up @@ -893,7 +897,8 @@ void FileDescriptorWalker::VisitRpcServices(const std::string* ns_name,
InitializeLocation(span, &location);

builder_->AddService(ns, v_name, location);
AttachMarkedSource(v_name, GenerateMarkedSourceForDescriptor(dp));
AttachMarkedSource(v_name,
GenerateMarkedSourceForDescriptor(dp, builder_));
}

// Visit methods
Expand All @@ -913,8 +918,8 @@ void FileDescriptorWalker::VisitRpcServices(const std::string* ns_name,
MethodDescriptorProto::kNameFieldNumber);
Location method_location;
InitializeLocation(location_map_[lookup_path], &method_location);
AttachMarkedSource(method,
GenerateMarkedSourceForDescriptor(method_dp));
AttachMarkedSource(
method, GenerateMarkedSourceForDescriptor(method_dp, builder_));
builder_->AddMethodToService(v_name, method, method_location);
}

Expand Down
43 changes: 28 additions & 15 deletions kythe/cxx/indexer/proto/marked_source.cc
Expand Up @@ -62,36 +62,44 @@ bool GenerateMarkedSourceForDottedName(absl::string_view name,

template <typename T>
static std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
absl::string_view kind, const T* descriptor) {
absl::string_view kind, const T* descriptor, ProtoGraphBuilder* builder) {
MarkedSource ms;
auto* mod = ms.add_child();
mod->set_kind(MarkedSource::MODIFIER);
mod->set_pre_text(kind);
mod->set_post_text(" ");
if (GenerateMarkedSourceForDottedName(descriptor->full_name(),
ms.add_child())) {
std::optional<proto::VName> vname;
if (builder) {
vname = builder->VNameForDescriptor(descriptor);
}
if (GenerateMarkedSourceForDottedName(descriptor->full_name(), ms.add_child(),
vname)) {
return ms;
}
return std::nullopt;
}

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::Descriptor* descriptor) {
return GenerateMarkedSourceForDescriptor("message", descriptor);
const google::protobuf::Descriptor* descriptor,
ProtoGraphBuilder* builder) {
return GenerateMarkedSourceForDescriptor("message", descriptor, builder);
}

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::EnumDescriptor* descriptor) {
return GenerateMarkedSourceForDescriptor("enum", descriptor);
const google::protobuf::EnumDescriptor* descriptor,
ProtoGraphBuilder* builder) {
return GenerateMarkedSourceForDescriptor("enum", descriptor, builder);
}

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::EnumValueDescriptor* descriptor) {
const google::protobuf::EnumValueDescriptor* descriptor,
ProtoGraphBuilder* builder) {
// EnumValueDescriptor::full_name leaves off the parent enum's name.
std::string full_name =
descriptor->type()->full_name() + "." + descriptor->name();
MarkedSource ms;
if (GenerateMarkedSourceForDottedName(full_name, &ms)) {
if (GenerateMarkedSourceForDottedName(
full_name, &ms, builder->VNameForDescriptor(descriptor))) {
return ms;
}
return std::nullopt;
Expand Down Expand Up @@ -179,19 +187,24 @@ std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
}

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::ServiceDescriptor* descriptor) {
return GenerateMarkedSourceForDescriptor("service", descriptor);
const google::protobuf::ServiceDescriptor* descriptor,
ProtoGraphBuilder* builder) {
return GenerateMarkedSourceForDescriptor("service", descriptor, builder);
}

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::MethodDescriptor* descriptor) {
return GenerateMarkedSourceForDescriptor("rpc", descriptor);
const google::protobuf::MethodDescriptor* descriptor,
ProtoGraphBuilder* builder) {
return GenerateMarkedSourceForDescriptor("rpc", descriptor, builder);
}

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::OneofDescriptor* descriptor) {
const google::protobuf::OneofDescriptor* descriptor,
ProtoGraphBuilder* builder) {
MarkedSource ms;
if (GenerateMarkedSourceForDottedName(descriptor->full_name(), &ms)) {
if (GenerateMarkedSourceForDottedName(
descriptor->full_name(), &ms,
builder->VNameForDescriptor(descriptor))) {
return ms;
}
return std::nullopt;
Expand Down
17 changes: 11 additions & 6 deletions kythe/cxx/indexer/proto/marked_source.h
Expand Up @@ -35,26 +35,31 @@ bool GenerateMarkedSourceForDottedName(
std::optional<proto::VName> vname = std::nullopt);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::Descriptor* descriptor);
const google::protobuf::Descriptor* descriptor, ProtoGraphBuilder* builder);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::EnumDescriptor* descriptor);
const google::protobuf::EnumDescriptor* descriptor,
ProtoGraphBuilder* builder);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::EnumValueDescriptor* descriptor);
const google::protobuf::EnumValueDescriptor* descriptor,
ProtoGraphBuilder* builder);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::FieldDescriptor* descriptor,
ProtoGraphBuilder* builder);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::ServiceDescriptor* descriptor);
const google::protobuf::ServiceDescriptor* descriptor,
ProtoGraphBuilder* builder);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::MethodDescriptor* descriptor);
const google::protobuf::MethodDescriptor* descriptor,
ProtoGraphBuilder* builder);

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::OneofDescriptor* descriptor);
const google::protobuf::OneofDescriptor* descriptor,
ProtoGraphBuilder* builder);

} // namespace kythe

Expand Down
2 changes: 2 additions & 0 deletions kythe/cxx/indexer/proto/testdata/basic/enums.proto
Expand Up @@ -19,6 +19,7 @@ message EnumMessage {
//- ETContext child.1 ETContext1
//- ETContext1.pre_text "EnumMessage"
//- ETIdent.pre_text "EnumTest"
//- ETIdent link EnumTestNode
enum EnumTest {
//- @PROTO defines/binding ValueProtoNode
//- ValueProtoNode childof EnumTest
Expand All @@ -29,6 +30,7 @@ message EnumMessage {
//- VKRoot child.0 VKContext
//- VKRoot child.1 VKIdent
//- VKIdent.pre_text "KYTHE"
//- VKIdent link ValueKytheNode
//- VKContext child.0 VKContext0
//- VKContext child.1 VKContext1
//- VKContext child.2 VKContext2
Expand Down
2 changes: 2 additions & 0 deletions kythe/cxx/indexer/proto/testdata/basic/nested-message.proto
Expand Up @@ -16,6 +16,7 @@ option java_package = "io.kythe";
//- PMName child.1 PMIdent
//- PMIdent.kind "IDENTIFIER"
//- PMIdent.pre_text "ParentMessage"
//- PMIdent link ParentMessageNode
//- PMContext.kind "CONTEXT"
//- PMContext child.0 PMContext0
//- PMContext0.pre_text "proto_kythe_test"
Expand All @@ -27,6 +28,7 @@ message ParentMessage {
//- NMName child.0 NMContext
//- NMName child.1 NMIdent
//- NMIdent.pre_text "NestedMessage"
//- NMIdent link NestedMessageNode
//- NMContext child.1 NMContext1
//- NMContext1.pre_text "ParentMessage"
message NestedMessage {
Expand Down
1 change: 1 addition & 0 deletions kythe/cxx/indexer/proto/testdata/basic/oneof.proto
Expand Up @@ -17,6 +17,7 @@ message Container {
//- NVRoot child.0 NVContext
//- NVRoot child.1 NVIdent
//- NVIdent.pre_text "variant_name"
//- NVIdent link NamedVariantType
//- NVContext child.0 NVContext0
//- NVContext child.1 NVContext1
//- NVContext0.pre_text "proto_kythe_test"
Expand Down
2 changes: 2 additions & 0 deletions kythe/cxx/indexer/proto/testdata/basic/services.proto
Expand Up @@ -25,6 +25,7 @@ message TestReply {
//- SNName child.0 SNContext
//- SNName child.1 SNIdent
//- SNIdent.pre_text "TestService"
//- SNIdent link ServiceNode
//- SNContext child.0 SNContext0
//- SNContext0.pre_text "proto_kythe_test"
service TestService {
Expand All @@ -40,6 +41,7 @@ service TestService {
//- MNName child.0 MNContext
//- MNName child.1 MNIdent
//- MNIdent.pre_text "TestMethod"
//- MNIdent link MethodNode
//- MNContext child.0 MNContext0
//- MNContext child.1 MNContext1
//- MNContext0.pre_text "proto_kythe_test"
Expand Down

0 comments on commit 7835faa

Please sign in to comment.