@@ -142,25 +142,26 @@ def _traverse(path, items):
142
142
)
143
143
144
144
145
- def get_comment (proto_file , path : List [int ]) -> str :
145
+ def get_comment (proto_file , path : List [int ], indent : int = 4 ) -> str :
146
+ pad = " " * indent
146
147
for sci in proto_file .source_code_info .location :
147
148
# print(list(sci.path), path, file=sys.stderr)
148
149
if list (sci .path ) == path and sci .leading_comments :
149
150
lines = textwrap .wrap (
150
- sci .leading_comments .strip ().replace ("\n " , "" ), width = 75
151
+ sci .leading_comments .strip ().replace ("\n " , "" ), width = 79 - indent
151
152
)
152
153
153
154
if path [- 2 ] == 2 and path [- 4 ] != 6 :
154
155
# This is a field
155
- return " # " + "\n # " .join (lines )
156
+ return f" { pad } # " + f "\n { pad } # " .join (lines )
156
157
else :
157
158
# This is a message, enum, service, or method
158
- if len (lines ) == 1 and len (lines [0 ]) < 70 :
159
+ if len (lines ) == 1 and len (lines [0 ]) < 79 - indent - 6 :
159
160
lines [0 ] = lines [0 ].strip ('"' )
160
- return f' """{ lines [0 ]} """'
161
+ return f'{ pad } """{ lines [0 ]} """'
161
162
else :
162
- joined = "\n " .join (lines )
163
- return f' """\n { joined } \n """'
163
+ joined = f "\n { pad } " .join (lines )
164
+ return f'{ pad } """\n { pad } { joined } \n { pad } """'
164
165
165
166
return ""
166
167
@@ -371,7 +372,7 @@ def generate_code(request, response):
371
372
{
372
373
"name" : method .name ,
373
374
"py_name" : stringcase .snakecase (method .name ),
374
- "comment" : get_comment (proto_file , [6 , i , 2 , j ]),
375
+ "comment" : get_comment (proto_file , [6 , i , 2 , j ], indent = 8 ),
375
376
"route" : f"/{ package } .{ service .name } /{ method .name } " ,
376
377
"input" : get_ref_type (
377
378
package , output ["imports" ], method .input_type
0 commit comments