Unnamed repository; edit this file 'description' to name the repository.
Merge #10015
10015: internal: more declarative re-indentation API r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
bors[bot] 2021-08-30
parent ceecf85 · parent d1cd81f · commit d250aa7
-rw-r--r--crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs3
-rw-r--r--crates/ide_assists/src/handlers/inline_call.rs10
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs15
3 files changed, 14 insertions, 14 deletions
diff --git a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs
index f45dc782e3..de79023f01 100644
--- a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs
+++ b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs
@@ -61,8 +61,7 @@ pub(crate) fn convert_iter_for_each_to_for(acc: &mut Assists, ctx: &AssistContex
_ => make::block_expr(Vec::new(), Some(body)),
}
.clone_for_update();
- block.reset_indent();
- block.indent(indent);
+ block.reindent_to(indent);
let expr_for_loop = make::expr_for_loop(param, receiver, block);
builder.replace(range, expr_for_loop.to_string())
diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs
index 90d83501f2..9cab0487e1 100644
--- a/crates/ide_assists/src/handlers/inline_call.rs
+++ b/crates/ide_assists/src/handlers/inline_call.rs
@@ -3,7 +3,7 @@ use hir::{HasSource, PathResolution, TypeInfo};
use ide_db::{defs::Definition, path_transform::PathTransform, search::FileReference};
use itertools::izip;
use syntax::{
- ast::{self, edit::AstNodeEdit, ArgListOwner},
+ ast::{self, edit_in_place::Indent, ArgListOwner},
ted, AstNode,
};
@@ -217,11 +217,11 @@ pub(crate) fn inline_(
}
let original_indentation = expr.indent_level();
- let replacement = body.reset_indent().indent(original_indentation);
+ body.reindent_to(original_indentation);
- let replacement = match replacement.tail_expr() {
- Some(expr) if replacement.statements().next().is_none() => expr,
- _ => ast::Expr::BlockExpr(replacement),
+ let replacement = match body.tail_expr() {
+ Some(expr) if body.statements().next().is_none() => expr,
+ _ => ast::Expr::BlockExpr(body),
};
builder.replace_ast(expr, replacement);
},
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index 4e0d97c3fd..9c5ae9a156 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -487,15 +487,16 @@ pub trait Indent: AstNode + Clone + Sized {
fn indent_level(&self) -> IndentLevel {
IndentLevel::from_node(self.syntax())
}
- fn indent(&self, level: IndentLevel) {
- level.increase_indent(self.syntax());
+ fn indent(&self, by: IndentLevel) {
+ by.increase_indent(self.syntax());
}
- fn dedent(&self, level: IndentLevel) {
- level.decrease_indent(self.syntax());
+ fn dedent(&self, by: IndentLevel) {
+ by.decrease_indent(self.syntax());
}
- fn reset_indent(&self) {
- let level = IndentLevel::from_node(self.syntax());
- self.dedent(level);
+ fn reindent_to(&self, target_level: IndentLevel) {
+ let current_level = IndentLevel::from_node(self.syntax());
+ self.dedent(current_level);
+ self.indent(target_level)
}
}