aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/ast.rs5
-rw-r--r--crates/ra_syntax/src/ast/traits.rs13
2 files changed, 5 insertions, 13 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 8ac313e6e..6f0489617 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -181,10 +181,7 @@ fn test_doc_comment_multi_line_block_strips_suffix() {
181 .ok() 181 .ok()
182 .unwrap(); 182 .unwrap();
183 let module = file.syntax().descendants().find_map(Module::cast).unwrap(); 183 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
184 assert_eq!( 184 assert_eq!(" this\n is\n mod foo", module.doc_comment_text().unwrap());
185 " this\n is\n mod foo\n ",
186 module.doc_comment_text().unwrap()
187 );
188} 185}
189 186
190#[test] 187#[test]
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 0c193e019..1b9a2b20c 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -115,8 +115,8 @@ pub trait DocCommentsOwner: AstNode {
115 } 115 }
116 116
117 /// Returns the textual content of a doc comment block as a single string. 117 /// Returns the textual content of a doc comment block as a single string.
118 /// That is, strips leading `///` or trailing `*/` (+ optional 1 character of whitespace in either direction) 118 /// That is, strips leading `///` (+ optional 1 character of whitespace),
119 /// and joins lines. 119 /// trailing `*/`, trailing whitespace and then joins the lines.
120 fn doc_comment_text(&self) -> Option<String> { 120 fn doc_comment_text(&self) -> Option<String> {
121 let mut has_comments = false; 121 let mut has_comments = false;
122 let docs = self 122 let docs = self
@@ -137,17 +137,12 @@ pub trait DocCommentsOwner: AstNode {
137 }; 137 };
138 138
139 let end = if comment.kind().shape.is_block() && line.ends_with("*/") { 139 let end = if comment.kind().shape.is_block() && line.ends_with("*/") {
140 // FIXME: Use `nth_back` here once stable 140 line.len() - 2
141 if line.chars().rev().nth(2).map(|c| c.is_whitespace()).unwrap_or(false) {
142 line.len() - 3
143 } else {
144 line.len() - 2
145 }
146 } else { 141 } else {
147 line.len() 142 line.len()
148 }; 143 };
149 144
150 line[pos..end].to_owned() 145 line[pos..end].trim_end().to_owned()
151 }) 146 })
152 .join("\n"); 147 .join("\n");
153 148