Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs')
-rw-r--r--crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs b/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs
index 3b8988db7a..90c621c85d 100644
--- a/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs
+++ b/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs
@@ -2,7 +2,7 @@ use ide_db::source_change::SourceChangeBuilder;
use itertools::Itertools;
use syntax::{
NodeOrToken, SyntaxToken, T, TextRange, algo,
- ast::{self, AstNode, edit::AstNodeEdit, make, syntax_factory::SyntaxFactory},
+ ast::{self, AstNode, edit::AstNodeEdit, make},
};
use crate::{AssistContext, AssistId, Assists};
@@ -192,25 +192,25 @@ fn wrap_derive(
}
}
let handle_source_change = |edit: &mut SourceChangeBuilder| {
- let make = SyntaxFactory::with_mappings();
let mut editor = edit.make_editor(attr.syntax());
- let new_derive = make.attr_outer(
- make.meta_token_tree(make.ident_path("derive"), make.token_tree(T!['('], new_derive)),
- );
- let meta = make.cfg_attr_meta(
- make.cfg_flag("cfg"),
- [make.meta_token_tree(
- make.ident_path("derive"),
- make.token_tree(T!['('], cfg_derive_tokens),
+ let new_derive = editor.make().attr_outer(editor.make().meta_token_tree(
+ editor.make().ident_path("derive"),
+ editor.make().token_tree(T!['('], new_derive),
+ ));
+ let meta = editor.make().cfg_attr_meta(
+ editor.make().cfg_flag("cfg"),
+ [editor.make().meta_token_tree(
+ editor.make().ident_path("derive"),
+ editor.make().token_tree(T!['('], cfg_derive_tokens),
)],
);
- let cfg_attr = make.attr_outer(meta.clone().into());
+ let cfg_attr = editor.make().attr_outer(meta.clone().into());
editor.replace_with_many(
attr.syntax(),
vec![
new_derive.syntax().clone().into(),
- make.whitespace("\n").into(),
+ editor.make().whitespace("\n").into(),
cfg_attr.syntax().clone().into(),
],
);
@@ -221,8 +221,6 @@ fn wrap_derive(
let tabstop = edit.make_placeholder_snippet(snippet_cap);
editor.add_annotation(cfg_predicate.syntax(), tabstop);
}
-
- editor.add_mappings(make.finish_with_mappings());
edit.add_file_edits(ctx.vfs_file_id(), editor);
};
@@ -239,14 +237,15 @@ fn wrap_cfg_attrs(acc: &mut Assists, ctx: &AssistContext<'_>, attrs: Vec<ast::At
let (first_attr, last_attr) = (attrs.first()?, attrs.last()?);
let range = first_attr.syntax().text_range().cover(last_attr.syntax().text_range());
let handle_source_change = |edit: &mut SourceChangeBuilder| {
- let make = SyntaxFactory::with_mappings();
let mut editor = edit.make_editor(first_attr.syntax());
- let meta =
- make.cfg_attr_meta(make.cfg_flag("cfg"), attrs.iter().filter_map(|attr| attr.meta()));
+ let meta = editor.make().cfg_attr_meta(
+ editor.make().cfg_flag("cfg"),
+ attrs.iter().filter_map(|attr| attr.meta()),
+ );
let cfg_attr = if first_attr.excl_token().is_some() {
- make.attr_inner(meta.clone().into())
+ editor.make().attr_inner(meta.clone().into())
} else {
- make.attr_outer(meta.clone().into())
+ editor.make().attr_outer(meta.clone().into())
};
let syntax_range = first_attr.syntax().clone().into()..=last_attr.syntax().clone().into();
@@ -258,8 +257,6 @@ fn wrap_cfg_attrs(acc: &mut Assists, ctx: &AssistContext<'_>, attrs: Vec<ast::At
let tabstop = edit.make_placeholder_snippet(snippet_cap);
editor.add_annotation(cfg_flag.syntax(), tabstop);
}
-
- editor.add_mappings(make.finish_with_mappings());
edit.add_file_edits(ctx.vfs_file_id(), editor);
};
acc.add(