1
+ use std:: collections:: HashSet ;
2
+
1
3
use super :: { Attributes , Method , Service } ;
2
4
use crate :: { generate_doc_comment, generate_doc_comments, naive_snake_case} ;
3
5
use proc_macro2:: { Span , TokenStream } ;
@@ -14,6 +16,7 @@ pub fn generate<T: Service>(
14
16
proto_path : & str ,
15
17
compile_well_known_types : bool ,
16
18
attributes : & Attributes ,
19
+ disable_comments : & HashSet < String > ,
17
20
) -> TokenStream {
18
21
let methods = generate_methods ( service, proto_path, compile_well_known_types) ;
19
22
@@ -22,11 +25,12 @@ pub fn generate<T: Service>(
22
25
let server_mod = quote:: format_ident!( "{}_server" , naive_snake_case( service. name( ) ) ) ;
23
26
let generated_trait = generate_trait (
24
27
service,
28
+ emit_package,
25
29
proto_path,
26
30
compile_well_known_types,
27
31
server_trait. clone ( ) ,
32
+ disable_comments,
28
33
) ;
29
- let service_doc = generate_doc_comments ( service. comment ( ) ) ;
30
34
let package = if emit_package { service. package ( ) } else { "" } ;
31
35
// Transport based implementations
32
36
let path = format ! (
@@ -35,6 +39,13 @@ pub fn generate<T: Service>(
35
39
if package. is_empty( ) { "" } else { "." } ,
36
40
service. identifier( )
37
41
) ;
42
+
43
+ let service_doc = if disable_comments. contains ( & path) {
44
+ TokenStream :: new ( )
45
+ } else {
46
+ generate_doc_comments ( service. comment ( ) )
47
+ } ;
48
+
38
49
let named = generate_named ( & server_service, & server_trait, & path) ;
39
50
let mod_attributes = attributes. for_mod ( package) ;
40
51
let struct_attributes = attributes. for_struct ( & path) ;
@@ -167,11 +178,19 @@ pub fn generate<T: Service>(
167
178
168
179
fn generate_trait < T : Service > (
169
180
service : & T ,
181
+ emit_package : bool ,
170
182
proto_path : & str ,
171
183
compile_well_known_types : bool ,
172
184
server_trait : Ident ,
185
+ disable_comments : & HashSet < String > ,
173
186
) -> TokenStream {
174
- let methods = generate_trait_methods ( service, proto_path, compile_well_known_types) ;
187
+ let methods = generate_trait_methods (
188
+ service,
189
+ emit_package,
190
+ proto_path,
191
+ compile_well_known_types,
192
+ disable_comments,
193
+ ) ;
175
194
let trait_doc = generate_doc_comment ( & format ! (
176
195
" Generated trait containing gRPC methods that should be implemented for use with {}Server." ,
177
196
service. name( )
@@ -188,18 +207,31 @@ fn generate_trait<T: Service>(
188
207
189
208
fn generate_trait_methods < T : Service > (
190
209
service : & T ,
210
+ emit_package : bool ,
191
211
proto_path : & str ,
192
212
compile_well_known_types : bool ,
213
+ disable_comments : & HashSet < String > ,
193
214
) -> TokenStream {
194
215
let mut stream = TokenStream :: new ( ) ;
195
216
217
+ let package = if emit_package { service. package ( ) } else { "" } ;
196
218
for method in service. methods ( ) {
197
219
let name = quote:: format_ident!( "{}" , method. name( ) ) ;
198
220
199
221
let ( req_message, res_message) =
200
222
method. request_response_name ( proto_path, compile_well_known_types) ;
201
223
202
- let method_doc = generate_doc_comments ( method. comment ( ) ) ;
224
+ let method_doc = if disable_comments. contains ( & format ! (
225
+ "{}{}{}.{}" ,
226
+ package,
227
+ if package. is_empty( ) { "" } else { "." } ,
228
+ service. identifier( ) ,
229
+ method. identifier( )
230
+ ) ) {
231
+ TokenStream :: new ( )
232
+ } else {
233
+ generate_doc_comments ( method. comment ( ) )
234
+ } ;
203
235
204
236
let method = match ( method. client_streaming ( ) , method. server_streaming ( ) ) {
205
237
( false , false ) => {
0 commit comments