Unnamed repository; edit this file 'description' to name the repository.
Indent 'inline_macro' expanded code
A4-Tacks 4 weeks ago
parent 519b08c · commit dc8bf1f
-rw-r--r--crates/ide-assists/src/handlers/inline_macro.rs15
-rw-r--r--crates/syntax/src/ast/edit.rs4
2 files changed, 12 insertions, 7 deletions
diff --git a/crates/ide-assists/src/handlers/inline_macro.rs b/crates/ide-assists/src/handlers/inline_macro.rs
index 81f1a8a73f..ef9b5d093f 100644
--- a/crates/ide-assists/src/handlers/inline_macro.rs
+++ b/crates/ide-assists/src/handlers/inline_macro.rs
@@ -1,6 +1,6 @@
use hir::db::ExpandDatabase;
use ide_db::syntax_helpers::prettify_macro_expansion;
-use syntax::ast::{self, AstNode};
+use syntax::ast::{self, AstNode, edit::AstNodeEdit};
use crate::{AssistContext, AssistId, Assists};
@@ -52,6 +52,7 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
// Don't call `prettify_macro_expansion()` outside the actual assist action; it does some heavy rowan tree manipulation,
// which can be very costly for big macros when it is done *even without the assist being invoked*.
let expanded = prettify_macro_expansion(ctx.db(), expanded, &span_map, target_crate_id);
+ let expanded = ast::edit::indent(&expanded, unexpanded.indent_level());
editor.replace(unexpanded.syntax(), expanded);
builder.add_file_edits(ctx.vfs_file_id(), editor);
},
@@ -299,12 +300,12 @@ macro_rules! foo {
}
fn main() {
cfg_if!{
- if #[cfg(test)]{
- 1;
- }else {
- 1;
- }
-};
+ if #[cfg(test)]{
+ 1;
+ }else {
+ 1;
+ }
+ };
}
"#,
);
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs
index b20aa90d06..0ffcbd212b 100644
--- a/crates/syntax/src/ast/edit.rs
+++ b/crates/syntax/src/ast/edit.rs
@@ -252,6 +252,10 @@ impl ast::IdentPat {
}
}
+pub fn indent(node: &SyntaxNode, level: IndentLevel) -> SyntaxNode {
+ level.clone_increase_indent(node)
+}
+
#[test]
fn test_increase_indent() {
let arm_list = {