Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/syntax_editor.rs')
-rw-r--r--crates/syntax/src/syntax_editor.rs21
1 files changed, 7 insertions, 14 deletions
diff --git a/crates/syntax/src/syntax_editor.rs b/crates/syntax/src/syntax_editor.rs
index 15515dd1fe..473d9c04ca 100644
--- a/crates/syntax/src/syntax_editor.rs
+++ b/crates/syntax/src/syntax_editor.rs
@@ -33,7 +33,7 @@ pub struct SyntaxEditor {
impl SyntaxEditor {
/// Creates a syntax editor to start editing from `root`
pub fn new(root: SyntaxNode) -> Self {
- Self { root, changes: vec![], mappings: SyntaxMapping::new(), annotations: vec![] }
+ Self { root, changes: vec![], mappings: SyntaxMapping::default(), annotations: vec![] }
}
pub fn add_annotation(&mut self, element: impl Element, annotation: SyntaxAnnotation) {
@@ -151,9 +151,8 @@ impl SyntaxEdit {
#[repr(transparent)]
pub struct SyntaxAnnotation(NonZeroU32);
-impl SyntaxAnnotation {
- /// Creates a unique syntax annotation to attach data to.
- pub fn new() -> Self {
+impl Default for SyntaxAnnotation {
+ fn default() -> Self {
static COUNTER: AtomicU32 = AtomicU32::new(1);
// Only consistency within a thread matters, as SyntaxElements are !Send
@@ -163,12 +162,6 @@ impl SyntaxAnnotation {
}
}
-impl Default for SyntaxAnnotation {
- fn default() -> Self {
- Self::new()
- }
-}
-
/// Position describing where to insert elements
#[derive(Debug)]
pub struct Position {
@@ -411,12 +404,12 @@ mod tests {
let to_replace = root.syntax().descendants().find_map(ast::BinExpr::cast).unwrap();
let mut editor = SyntaxEditor::new(root.syntax().clone());
- let make = SyntaxFactory::new();
+ let make = SyntaxFactory::with_mappings();
let name = make::name("var_name");
let name_ref = make::name_ref("var_name").clone_for_update();
- let placeholder_snippet = SyntaxAnnotation::new();
+ let placeholder_snippet = SyntaxAnnotation::default();
editor.add_annotation(name.syntax(), placeholder_snippet);
editor.add_annotation(name_ref.syntax(), placeholder_snippet);
@@ -522,7 +515,7 @@ mod tests {
let second_let = root.syntax().descendants().find_map(ast::LetStmt::cast).unwrap();
let mut editor = SyntaxEditor::new(root.syntax().clone());
- let make = SyntaxFactory::new();
+ let make = SyntaxFactory::with_mappings();
let new_block_expr = make.block_expr([], Some(ast::Expr::BlockExpr(inner_block.clone())));
@@ -574,7 +567,7 @@ mod tests {
let inner_block = root.clone();
let mut editor = SyntaxEditor::new(root.syntax().clone());
- let make = SyntaxFactory::new();
+ let make = SyntaxFactory::with_mappings();
let new_block_expr = make.block_expr([], Some(ast::Expr::BlockExpr(inner_block.clone())));