Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 35 | ||||
| -rw-r--r-- | crates/syntax/src/syntax_editor/edit_algo.rs | 6 |
2 files changed, 13 insertions, 28 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 1eb658f4b8..00aeb1dfeb 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -3,7 +3,7 @@ //! //! These methods should only do simple, shallow tasks related to the syntax of the node itself. -use std::{borrow::Cow, fmt, iter::successors}; +use std::{fmt, iter::successors}; use itertools::Itertools; use parser::SyntaxKind; @@ -31,15 +31,9 @@ impl ast::Name { pub fn text(&self) -> TokenText<'_> { text_of_first_token(self.syntax()) } - pub fn text_non_mutable(&self) -> &str { - fn first_token(green_ref: &GreenNodeData) -> &GreenTokenData { - green_ref.children().next().and_then(NodeOrToken::into_token).unwrap() - } - match self.syntax().green() { - Cow::Borrowed(green_ref) => first_token(green_ref).text(), - Cow::Owned(_) => unreachable!(), - } + pub fn text_non_mutable(&self) -> &str { + first_token(self.syntax().green()).text() } } @@ -47,15 +41,9 @@ impl ast::NameRef { pub fn text(&self) -> TokenText<'_> { text_of_first_token(self.syntax()) } - pub fn text_non_mutable(&self) -> &str { - fn first_token(green_ref: &GreenNodeData) -> &GreenTokenData { - green_ref.children().next().and_then(NodeOrToken::into_token).unwrap() - } - match self.syntax().green() { - Cow::Borrowed(green_ref) => first_token(green_ref).text(), - Cow::Owned(_) => unreachable!(), - } + pub fn text_non_mutable(&self) -> &str { + first_token(self.syntax().green()).text() } pub fn as_tuple_field(&self) -> Option<usize> { @@ -67,15 +55,12 @@ impl ast::NameRef { } } -fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> { - fn first_token(green_ref: &GreenNodeData) -> &GreenTokenData { - green_ref.children().next().and_then(NodeOrToken::into_token).unwrap() - } +fn first_token(green_ref: &GreenNodeData) -> &GreenTokenData { + green_ref.children().next().and_then(NodeOrToken::into_token).unwrap() +} - match node.green() { - Cow::Borrowed(green_ref) => TokenText::borrowed(first_token(green_ref).text()), - Cow::Owned(green) => TokenText::owned(first_token(&green).to_owned()), - } +fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> { + TokenText::borrowed(first_token(node.green()).text()) } fn into_comma(it: NodeOrToken<SyntaxNode, SyntaxToken>) -> Option<SyntaxToken> { diff --git a/crates/syntax/src/syntax_editor/edit_algo.rs b/crates/syntax/src/syntax_editor/edit_algo.rs index d24d9b1334..24e7016f5b 100644 --- a/crates/syntax/src/syntax_editor/edit_algo.rs +++ b/crates/syntax/src/syntax_editor/edit_algo.rs @@ -449,7 +449,7 @@ impl TreeState { let parent = parent_path.resolve(&self.root).and_then(SyntaxElement::into_node).unwrap(); let green = rowan::GreenNodeData::splice_children( - parent.green().as_ref(), + parent.green(), deleted.clone(), inserted.into_iter().map(PreparedElement::into_green), ); @@ -466,7 +466,7 @@ impl TreeState { let NodeOrToken::Node(node) = replacement.syntax else { panic!("root node replacement should be a node") }; - self.root = SyntaxNode::new_root(node.green().into_owned()); + self.root = SyntaxNode::new_root(node.green().to_owned()); self.changed.clear(); if track_as_changed { self.changed.push(SyntaxPath { child_indices: Vec::new() }); @@ -543,7 +543,7 @@ struct PreparedElement { impl PreparedElement { fn into_green(self) -> rowan::NodeOrToken<rowan::GreenNode, rowan::GreenToken> { match self.syntax { - SyntaxElement::Node(node) => NodeOrToken::Node(node.green().into_owned()), + SyntaxElement::Node(node) => NodeOrToken::Node(node.green().to_owned()), SyntaxElement::Token(token) => NodeOrToken::Token(token.green().to_owned()), } } |