Unnamed repository; edit this file 'description' to name the repository.
indent macro output when pprinting
Aleksey Kladov 2021-10-09
parent a0d9e78 · commit 6407e2e
-rw-r--r--crates/hir_def/src/macro_expansion_tests.rs10
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe.rs12
2 files changed, 16 insertions, 6 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs
index d4520939b6..ac0a2d27b3 100644
--- a/crates/hir_def/src/macro_expansion_tests.rs
+++ b/crates/hir_def/src/macro_expansion_tests.rs
@@ -98,6 +98,7 @@ fn reindent(indent: IndentLevel, pp: String) -> String {
fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
let mut res = String::new();
let mut prev_kind = SyntaxKind::EOF;
+ let mut indent_level = 0;
for token in iter::successors(expn.first_token(), |t| t.next_token()) {
let curr_kind = token.kind();
let space = match (prev_kind, curr_kind) {
@@ -113,7 +114,16 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String {
_ => "",
};
+ match prev_kind {
+ T!['{'] => indent_level += 1,
+ T!['}'] => indent_level -= 1,
+ _ => (),
+ }
+
res.push_str(space);
+ if space == "\n" && curr_kind != T!['}'] {
+ res.push_str(&" ".repeat(indent_level));
+ }
prev_kind = curr_kind;
format_to!(res, "{}", token)
}
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs
index 36c1858a04..f5d00b6666 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs
@@ -174,8 +174,8 @@ macro_rules! m {
($($i:ident),*) => ( impl Bar { $(fn $i {})* } );
}
impl Bar {
-fn foo {}
-fn bar {}
+ fn foo {}
+ fn bar {}
}
"#]],
);
@@ -195,8 +195,8 @@ macro_rules! m {
($($i:ident),*) => ( fn baz { $($i ();)* } );
}
fn baz {
-foo();
-bar();
+ foo();
+ bar();
}
"#]],
)
@@ -216,8 +216,8 @@ macro_rules! m {
($($i:ident),*) => ( fn baz { $($i() );* } );
}
fn baz {
-foo();
-bar()
+ foo();
+ bar()
}
"#]],
)