fix some edge cases around multiline attributes

This commit is contained in:
Evan Almloff committed 2023-07-19 16:59:20 -07:00
1 parent f69b84bf34
commit b6ea722d94
7 files changed
+77 -205

No files matched your search

+13 -7
View File
@@ -58,7 +58,7 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
let mut writer = Writer::new(contents);
// Dont parse nested macros
// Don't parse nested macros
let mut end_span = LineColumn { column: 0, line: 0 };
for item in macros {
let macro_path = &item.path.segments[0].ident;
@@ -68,16 +68,11 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
continue;
}
// item.parse_body::<CallBody>();
let body = item.parse_body::<CallBody>().unwrap();
let rsx_start = macro_path.span().start();
writer.out.indent = &writer.src[rsx_start.line - 1]
.chars()
.take_while(|c| *c == ' ')
.count()
/ 4;
writer.out.indent = leading_whitespaces(&writer.src[rsx_start.line - 1]) / 4;
write_body(&mut writer, &body);
@@ -230,3 +225,14 @@ pub(crate) fn write_ifmt(input: &IfmtInput, writable: &mut impl Write) -> std::f
let display = DisplayIfmt(input);
write!(writable, "{}", display)
}
pub fn leading_whitespaces(input: &str) -> usize {
input
.chars()
.map_while(|c| match c {
' ' => Some(1),
'\t' => Some(4),
_ => None,
})
.sum()
}