minor: address review comments

This commit is contained in:
Dawer 2021-08-18 19:01:29 +05:00
parent 98847e4d5b
commit 08694dc1ef
3 changed files with 9 additions and 10 deletions

View file

@ -46,7 +46,7 @@ pub(crate) fn convert_iter_for_each_to_for(acc: &mut Assists, ctx: &AssistContex
let body = closure.body()?;
let stmt = method.syntax().parent().and_then(ast::ExprStmt::cast);
let range = stmt.as_ref().map_or_else(|| method.syntax(), AstNode::syntax).text_range();
let range = stmt.as_ref().map_or(method.syntax(), AstNode::syntax).text_range();
acc.add(
AssistId("convert_iter_for_each_to_for", AssistKind::RefactorRewrite),
@ -61,7 +61,8 @@ 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().indent(indent);
block.reset_indent();
block.indent(indent);
let expr_for_loop = make::expr_for_loop(param, receiver, block);
builder.replace(range, expr_for_loop.to_string())

View file

@ -117,7 +117,7 @@ impl IndentLevel {
/// }
/// ```
/// if you indent the block, the `{` token would stay put.
pub(in super) fn increase_indent(self, node: &SyntaxNode) {
pub(super) fn increase_indent(self, node: &SyntaxNode) {
let tokens = node.preorder_with_tokens().filter_map(|event| match event {
rowan::WalkEvent::Leave(NodeOrToken::Token(it)) => Some(it),
_ => None,
@ -132,7 +132,7 @@ impl IndentLevel {
}
}
pub(in super) fn decrease_indent(self, node: &SyntaxNode) {
pub(super) fn decrease_indent(self, node: &SyntaxNode) {
let tokens = node.preorder_with_tokens().filter_map(|event| match event {
rowan::WalkEvent::Leave(NodeOrToken::Token(it)) => Some(it),
_ => None,

View file

@ -487,17 +487,15 @@ pub trait Indent: AstNode + Clone + Sized {
fn indent_level(&self) -> IndentLevel {
IndentLevel::from_node(self.syntax())
}
fn indent(&self, level: IndentLevel) -> &Self {
fn indent(&self, level: IndentLevel) {
level.increase_indent(self.syntax());
self
}
fn dedent(&self, level: IndentLevel) -> &Self {
fn dedent(&self, level: IndentLevel) {
level.decrease_indent(self.syntax());
self
}
fn reset_indent(&self) -> &Self {
fn reset_indent(&self) {
let level = IndentLevel::from_node(self.syntax());
self.dedent(level)
self.dedent(level);
}
}