File tree 1 file changed +36
-14
lines changed
crates/iota-open-rpc-macros/src 1 file changed +36
-14
lines changed Original file line number Diff line number Diff line change @@ -336,21 +336,43 @@ fn respan_token_stream(stream: TokenStream2, span: Span) -> TokenStream2 {
336
336
. collect ( )
337
337
}
338
338
339
+ /// Find doc comments by looking for #[doc = "..."] attributes.
340
+ ///
341
+ /// Consecutive attributes are combined together. If there is a leading space,
342
+ /// it will be removed, and if there is trailing whitespace it will also be
343
+ /// removed. Single newlines in doc comments are replaced by spaces (soft
344
+ /// wrapping), but double newlines (an empty line) are preserved.
339
345
fn extract_doc_comments ( attrs : & [ Attribute ] ) -> String {
340
- let s = attrs
341
- . iter ( )
342
- . filter ( |attr| {
343
- attr. path . is_ident ( "doc" )
344
- && match attr. parse_meta ( ) {
345
- Ok ( syn:: Meta :: NameValue ( meta) ) => matches ! ( & meta. lit, syn:: Lit :: Str ( _) ) ,
346
- _ => false ,
347
- }
348
- } )
349
- . map ( |attr| {
350
- let s = attr. tokens . to_string ( ) ;
351
- s[ 4 ..s. len ( ) - 1 ] . to_string ( )
352
- } )
353
- . join ( " " ) ;
346
+ let mut s = String :: new ( ) ;
347
+ let mut sep = "" ;
348
+
349
+ for attr in attrs {
350
+ if !attr. path . is_ident ( "doc" ) {
351
+ continue ;
352
+ }
353
+
354
+ let Ok ( syn:: Meta :: NameValue ( meta) ) = attr. parse_meta ( ) else {
355
+ continue ;
356
+ } ;
357
+
358
+ let syn:: Lit :: Str ( lit) = & meta. lit else {
359
+ continue ;
360
+ } ;
361
+
362
+ let token = lit. value ( ) ;
363
+ let line = token. strip_prefix ( " " ) . unwrap_or ( & token) . trim_end ( ) ;
364
+
365
+ if line. is_empty ( ) {
366
+ s. push_str ( "\n \n " ) ;
367
+ sep = "" ;
368
+ } else {
369
+ s. push_str ( sep) ;
370
+ sep = " " ;
371
+ }
372
+
373
+ s. push_str ( line) ;
374
+ }
375
+
354
376
unescape ( & s) . unwrap_or_else ( || panic ! ( "Cannot unescape doc comments : [{s}]" ) )
355
377
}
356
378
You can’t perform that action at this time.
0 commit comments