fix(autofmt): preserve indentation of commented-out RSX blocks (#5464)
* test: add failing idempotency tests for commented-out RSX blocks Two variants of the regression introduced in v0.7.4 (#5257): - commented_rsx_block: first line keeps indent, rest gets dedented - commented_rsx_block_nested: entire block gets dedented See #5463 * fix(autofmt): preserve indentation of commented-out RSX blocks Trailing comments before `}` in write_rsx_block were indented at parent level instead of child level. Truncate the tab from tabbed_line() and bump indent to child level before apply_line_comments, same approach as write_trailing_body_comments. Fixes #5463
This commit is contained in:
1 parent
cd54f5953b
commit
82c3cab25f
7 files changed
+60
No files matched your search
@@ -426,7 +426,13 @@ impl<'a> Writer<'a> {
|
|||||||
{
|
{
|
||||||
let comments = self.accumulate_full_line_comments(brace.span.span().end());
|
let comments = self.accumulate_full_line_comments(brace.span.span().end());
|
||||||
if !comments.is_empty() {
|
if !comments.is_empty() {
|
||||||
|
// Undo the tab from tabbed_line(). It positioned for the closing
|
||||||
|
// brace, but trailing comments need child-level indentation
|
||||||
|
let tab_width = self.out.indent.indent_str().len() * self.out.indent_level;
|
||||||
|
self.out.buf.truncate(self.out.buf.len() - tab_width);
|
||||||
|
self.out.indent_level += 1;
|
||||||
self.apply_line_comments(comments)?;
|
self.apply_line_comments(comments)?;
|
||||||
|
self.out.indent_level -= 1;
|
||||||
self.out.tab()?;
|
self.out.tab()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ twoway![
|
|||||||
blank_lines,
|
blank_lines,
|
||||||
blank_lines_preserved,
|
blank_lines_preserved,
|
||||||
forloop_tuple,
|
forloop_tuple,
|
||||||
|
commented_rsx_block,
|
||||||
|
commented_rsx_block_nested,
|
||||||
|
commented_rsx_block_only,
|
||||||
|
commented_rsx_block_between,
|
||||||
|
commented_rsx_block_deep,
|
||||||
];
|
];
|
||||||
|
|
||||||
fn assert_idempotent(src: &str) {
|
fn assert_idempotent(src: &str) {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
rsx! {
|
||||||
|
div {
|
||||||
|
h2 { "Title" }
|
||||||
|
// div { class: "wrapper",
|
||||||
|
// p { "A" }
|
||||||
|
// p { "B" }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
rsx! {
|
||||||
|
div {
|
||||||
|
h1 { "Before" }
|
||||||
|
// div { class: "commented",
|
||||||
|
// p { "A" }
|
||||||
|
// }
|
||||||
|
h2 { "After" }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
rsx! {
|
||||||
|
div {
|
||||||
|
div {
|
||||||
|
div {
|
||||||
|
h2 { "Title" }
|
||||||
|
// div { class: "deep",
|
||||||
|
// p { "A" }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
rsx! {
|
||||||
|
Component {
|
||||||
|
field: rsx! {
|
||||||
|
div {
|
||||||
|
h2 { "Title" }
|
||||||
|
// div { class: "wrapper",
|
||||||
|
// // nested comment
|
||||||
|
// p { "A" }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
rsx! {
|
||||||
|
div {
|
||||||
|
// p { "A" }
|
||||||
|
// p { "B" }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user