Skip to content

Commit ee0d99d

Browse files
committed
Auto merge of #16081 - riverbl:trailing-whitespace, r=Veykril
Don't trim trailing whitespace from doc comments Don't trim trailing whitespace from doc comments as multiple trailing spaces indicates a hard line break in Markdown. I'd have liked to add a unit test for `docs_from_attrs`, but couldn't find a reasonable way to get an `&Attrs` object for use in the test. Fixes #15877.
2 parents 60fe5fd + 99b30ba commit ee0d99d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

crates/ide-db/src/documentation.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,13 @@ pub fn docs_from_attrs(attrs: &hir::Attrs) -> Option<String> {
138138
for doc in docs {
139139
// str::lines doesn't yield anything for the empty string
140140
if !doc.is_empty() {
141-
buf.extend(Itertools::intersperse(
142-
doc.lines().map(|line| {
143-
line.char_indices()
144-
.nth(indent)
145-
.map_or(line, |(offset, _)| &line[offset..])
146-
.trim_end()
147-
}),
148-
"\n",
149-
));
141+
// We don't trim trailing whitespace from doc comments as multiple trailing spaces
142+
// indicates a hard line break in Markdown.
143+
let lines = doc.lines().map(|line| {
144+
line.char_indices().nth(indent).map_or(line, |(offset, _)| &line[offset..])
145+
});
146+
147+
buf.extend(Itertools::intersperse(lines, "\n"));
150148
}
151149
buf.push('\n');
152150
}

0 commit comments

Comments
 (0)