Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert add_braces to SyntaxFactory SyntaxEditor abstraction #18485

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/ide-assists/src/handlers/add_braces.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use syntax::{
ast::{self, edit::AstNodeEdit, make},
ast::{self, edit::AstNodeEdit, make, syntax_factory::SyntaxFactory}, syntax_editor::SyntaxEditor,

Check failure on line 2 in crates/ide-assists/src/handlers/add_braces.rs

View workflow job for this annotation

GitHub Actions / Rust (ubuntu-latest)

unused imports: `make` and `syntax_editor::SyntaxEditor`
AstNode,
};

Expand Down Expand Up @@ -39,12 +39,19 @@
},
expr.syntax().text_range(),
|builder| {

let make = SyntaxFactory::new();
let mut editor = builder.make_editor(&expr.syntax());

let block_expr = AstNodeEdit::indent(
&make::block_expr(None, Some(expr.clone())),
&make.block_expr(None, Some(expr.clone())),
AstNodeEdit::indent_level(&expr),
);

builder.replace(expr.syntax().text_range(), block_expr.syntax().text());
editor.replace(expr.syntax(), block_expr.syntax());

editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.file_id(), editor);
},
)
}
Expand Down
Loading