Skip to content

Commit 0f61aa1

Browse files
committed
Unconditionally trim the end of comments
1 parent d65dc40 commit 0f61aa1

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

crates/ra_syntax/src/ast.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ fn test_doc_comment_multi_line_block_strips_suffix() {
181181
.ok()
182182
.unwrap();
183183
let module = file.syntax().descendants().find_map(Module::cast).unwrap();
184-
assert_eq!(
185-
" this\n is\n mod foo\n ",
186-
module.doc_comment_text().unwrap()
187-
);
184+
assert_eq!(" this\n is\n mod foo", module.doc_comment_text().unwrap());
188185
}
189186

190187
#[test]

crates/ra_syntax/src/ast/traits.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ pub trait DocCommentsOwner: AstNode {
115115
}
116116

117117
/// 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)
119-
/// and joins lines.
118+
/// That is, strips leading `///` (+ optional 1 character of whitespace),
119+
/// trailing `*/`, trailing whitespace and then joins the lines.
120120
fn doc_comment_text(&self) -> Option<String> {
121121
let mut has_comments = false;
122122
let docs = self
@@ -137,17 +137,12 @@ pub trait DocCommentsOwner: AstNode {
137137
};
138138

139139
let end = if comment.kind().shape.is_block() && line.ends_with("*/") {
140-
// FIXME: Use `nth_back` here once stable
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-
}
140+
line.len() - 2
146141
} else {
147142
line.len()
148143
};
149144

150-
line[pos..end].to_owned()
145+
line[pos..end].trim_end().to_owned()
151146
})
152147
.join("\n");
153148

0 commit comments

Comments
 (0)