File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change 6
6
use std:: sync:: Arc ;
7
7
8
8
use either:: Either ;
9
- use syntax:: ast;
9
+ use itertools:: Itertools ;
10
+ use syntax:: { ast, SmolStr } ;
10
11
11
12
use crate :: {
12
13
db:: DefDatabase ,
@@ -93,7 +94,7 @@ fn merge_doc_comments_and_attrs(
93
94
) -> Option < String > {
94
95
match ( doc_comment_text, doc_attr_text) {
95
96
( Some ( mut comment_text) , Some ( attr_text) ) => {
96
- comment_text. push_str ( "\n \n " ) ;
97
+ comment_text. push_str ( "\n " ) ;
97
98
comment_text. push_str ( & attr_text) ;
98
99
Some ( comment_text)
99
100
}
@@ -105,17 +106,16 @@ fn merge_doc_comments_and_attrs(
105
106
106
107
fn expand_doc_attrs ( owner : & dyn ast:: AttrsOwner ) -> Option < String > {
107
108
let mut docs = String :: new ( ) ;
108
- for attr in owner. attrs ( ) {
109
- if let Some ( ( "doc" , value) ) =
110
- attr. as_simple_key_value ( ) . as_ref ( ) . map ( |( k, v) | ( k. as_str ( ) , v. as_str ( ) ) )
111
- {
112
- docs. push_str ( value) ;
113
- docs. push_str ( "\n \n " ) ;
114
- }
115
- }
109
+ owner
110
+ . attrs ( )
111
+ . filter_map ( |attr| attr. as_simple_key_value ( ) . filter ( |( key, _) | key == "doc" ) )
112
+ . map ( |( _, value) | value)
113
+ . intersperse ( SmolStr :: new_inline ( "\n " ) )
114
+ // No FromIterator<SmolStr> for String
115
+ . for_each ( |s| docs. push_str ( s. as_str ( ) ) ) ;
116
116
if docs. is_empty ( ) {
117
117
None
118
118
} else {
119
- Some ( docs. trim_end_matches ( " \n \n " ) . to_owned ( ) )
119
+ Some ( docs)
120
120
}
121
121
}
Original file line number Diff line number Diff line change @@ -1525,9 +1525,7 @@ fn foo() { let bar = Ba<|>r; }
1525
1525
---
1526
1526
1527
1527
bar docs 0
1528
-
1529
1528
bar docs 1
1530
-
1531
1529
bar docs 2
1532
1530
"# ] ] ,
1533
1531
) ;
You can’t perform that action at this time.
0 commit comments