Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proto_indexer): add kinds to signatures #5827

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions kythe/cxx/indexer/proto/marked_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "kythe/cxx/indexer/proto/marked_source.h"

#include "absl/strings/str_split.h"
#include "marked_source.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a redundant include (please use repo-relative include paths)


namespace kythe {
bool GenerateMarkedSourceForDottedName(absl::string_view name,
Expand Down Expand Up @@ -46,6 +47,31 @@ bool GenerateMarkedSourceForDottedName(absl::string_view name,
return true;
}

template <typename T>
std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
schroederc marked this conversation as resolved.
Show resolved Hide resolved
absl::string_view kind, const T* descriptor) {
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())) {
return ms;
}
return std::nullopt;
}

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

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

std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
const google::protobuf::EnumValueDescriptor* descriptor) {
// EnumValueDescriptor::full_name leaves off the parent enum's name.
Expand Down Expand Up @@ -74,4 +100,14 @@ std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
return std::nullopt;
}

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

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

} // namespace kythe
12 changes: 12 additions & 0 deletions kythe/cxx/indexer/proto/marked_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@ std::optional<MarkedSource> GenerateMarkedSourceForDescriptor(
return std::nullopt;
}

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

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

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

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

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

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

} // namespace kythe

#endif // KYTHE_CXX_INDEXER_PROTO_MARKED_SOURCE_H_
13 changes: 8 additions & 5 deletions kythe/cxx/indexer/proto/testdata/basic/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ message EnumMessage {
//- EnumTestNode childof EnumMessageNode
//- EnumTestNode.node/kind sum
//- EnumTest code ETRoot
//- ETRoot child.0 ETContext
//- ETRoot child.1 ETIdent
//- ETRoot child.0 ETKind
//- ETKind.pre_text "enum"
//- ETRoot child.1 ETName
//- ETName child.0 ETContext
//- ETName child.1 ETIdent
//- ETContext child.1 ETContext1
//- ETContext1.pre_text "EnumMessage"
//- ETIdent.pre_text "EnumTest"
Expand Down Expand Up @@ -52,8 +55,9 @@ message EnumMessage {
//- TopLevelNode childof PackageNode
//- TopLevelNode.node/kind sum
//- TopLevelNode code TLRoot
//- TLRoot child.0 TLContext
//- TLRoot child.1 TLIdent
//- TLRoot child.1 TLName
//- TLName child.0 TLContext
//- TLName child.1 TLIdent
//- TLIdent.pre_text "TopLevel"
//- TLContext child.0 TLContext0
//- TLContext0.pre_text "proto_kythe_test"
Expand All @@ -79,4 +83,3 @@ enum TopLevel {
//- ValueWestNode childof TopLevelNode
WEST = 4;
}

13 changes: 8 additions & 5 deletions kythe/cxx/indexer/proto/testdata/basic/nested-message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ option java_package = "io.kythe";
//- @ParentMessage defines/binding ParentMessageNode
//- ParentMessageNode childof ThePackage
//- ParentMessageNode code PMRoot
//- PMRoot child.0 PMContext
//- PMRoot child.1 PMIdent
//- PMRoot child.0 PMKind
//- PMKind.pre_text "message"
//- PMRoot child.1 PMName
//- PMName child.0 PMContext
//- PMName child.1 PMIdent
//- PMIdent.kind "IDENTIFIER"
//- PMIdent.pre_text "ParentMessage"
//- PMContext.kind "CONTEXT"
Expand All @@ -20,8 +23,9 @@ message ParentMessage {
//- @NestedMessage defines/binding NestedMessageNode
//- NestedMessageNode childof ParentMessageNode
//- NestedMessageNode code NMRoot
//- NMRoot child.0 NMContext
//- NMRoot child.1 NMIdent
//- NMRoot child.1 NMName
//- NMName child.0 NMContext
//- NMName child.1 NMIdent
//- NMIdent.pre_text "NestedMessage"
//- NMContext child.1 NMContext1
//- NMContext1.pre_text "ParentMessage"
Expand All @@ -35,4 +39,3 @@ message ParentMessage {
//- NamedFieldNode childof ParentMessageNode
optional NestedMessage field_name = 1;
}

24 changes: 14 additions & 10 deletions kythe/cxx/indexer/proto/testdata/basic/services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ message TestReply {
//- ServiceNode childof _PackageNode
//- ServiceNode.node/kind interface
//- ServiceNode code SNRoot
//- SNRoot child.0 SNContext
//- SNRoot child.1 SNIdent
//- SNRoot child.0 SNKind
//- SNKind.pre_text "service"
//- SNRoot child.1 SNName
//- SNName child.0 SNContext
//- SNName child.1 SNIdent
//- SNIdent.pre_text "TestService"
//- SNContext child.0 SNContext0
//- SNContext0.pre_text "proto_kythe_test"
Expand All @@ -31,19 +34,20 @@ service TestService {
//- @TestRequest ref RequestNode
//- @TestReply ref ReplyNode
//- MethodNode code MNRoot
//- MNRoot child.0 MNContext
//- MNRoot child.1 MNIdent
//- MNRoot child.0 MNKind
//- MNKind.pre_text "rpc"
//- MNRoot child.1 MNName
//- MNName child.0 MNContext
//- MNName child.1 MNIdent
//- MNIdent.pre_text "TestMethod"
//- MNContext child.0 MNContext0
//- MNContext child.1 MNContext1
//- MNContext0.pre_text "proto_kythe_test"
//- MNContext1.pre_text "TestService"
rpc TestMethod(TestRequest) returns (TestReply);

//- @+3"TestRequest" ref RequestNode
//- @+4"TestReply" ref ReplyNode
rpc FullTestMethod(proto_kythe_test.
TestRequest) returns (
proto_kythe_test.
TestReply);
//- @TestRequest ref RequestNode
//- @+2"TestReply" ref ReplyNode
rpc FullTestMethod(proto_kythe_test.TestRequest)
returns (proto_kythe_test.TestReply);
}
8 changes: 4 additions & 4 deletions kythe/cxx/indexer/proto/testdata/basic/signatures.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package proto_kythe_test;

//- @Message defines/binding Message
//- Message.code/rendered/qualified_name "proto_kythe_test.Message"
//- Message.code/rendered/signature "Message"
//- Message.code/rendered/signature "message Message"
message Message {
//- @R defines/binding R
//- R.code/rendered/qualified_name "proto_kythe_test.Message.R"
Expand All @@ -26,7 +26,7 @@ message Message {

//- @Enum defines/binding Enum
//- Enum.code/rendered/qualified_name "proto_kythe_test.Enum"
//- Enum.code/rendered/signature "Enum"
//- Enum.code/rendered/signature "enum Enum"
enum Enum {
//- @DEFAULT defines/binding Default
//- Default.code/rendered/qualified_name "proto_kythe_test.Enum.DEFAULT"
Expand All @@ -36,10 +36,10 @@ enum Enum {

//- @Service defines/binding Service
//- Service.code/rendered/qualified_name "proto_kythe_test.Service"
//- Service.code/rendered/signature "Service"
//- Service.code/rendered/signature "service Service"
service Service {
//- @Method defines/binding M
//- M.code/rendered/qualified_name "proto_kythe_test.Service.Method"
//- M.code/rendered/signature "Method"
//- M.code/rendered/signature "rpc Method"
rpc Method(Message) returns (Message) {}
}