Skip to content

Commit a33d92d

Browse files
committed
gRPC service/method comments
1 parent 45a6da0 commit a33d92d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

betterproto/plugin.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def get_comment(proto_file, path: List[int]) -> str:
114114
sci.leading_comments.strip().replace("\n", ""), width=75
115115
)
116116

117-
if path[-2] == 2:
117+
if path[-2] == 2 and path[-4] != 6:
118118
# This is a field
119119
return " # " + " # ".join(lines)
120120
else:
121-
# This is a class
121+
# This is a message, enum, service, or method
122122
if len(lines) == 1 and len(lines[0]) < 70:
123123
lines[0] = lines[0].strip('"')
124124
return f' """{lines[0]}"""'
@@ -278,13 +278,16 @@ def generate_code(request, response):
278278

279279
output["enums"].append(data)
280280

281-
for service in proto_file.service:
281+
for i, service in enumerate(proto_file.service):
282282
# print(service, file=sys.stderr)
283283

284-
# TODO: comments
285-
data = {"name": service.name, "methods": []}
284+
data = {
285+
"name": service.name,
286+
"comment": get_comment(proto_file, [6, i]),
287+
"methods": [],
288+
}
286289

287-
for method in service.method:
290+
for j, method in enumerate(service.method):
288291
if method.client_streaming:
289292
raise NotImplementedError("Client streaming not yet supported")
290293

@@ -304,6 +307,7 @@ def generate_code(request, response):
304307
{
305308
"name": method.name,
306309
"py_name": snake_case(method.name),
310+
"comment": get_comment(proto_file, [6, i, 2, j]),
307311
"route": f"/{package}.{service.name}/{method.name}",
308312
"input": get_ref_type(
309313
package, output["imports"], method.input_type

betterproto/templates/template.py

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)