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

Allow passing an iterable to splice_children #165

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rowan"
version = "0.15.16"
version = "0.16.0"
authors = ["Aleksey Kladov <[email protected]>"]
repository = "https://github.com/rust-analyzer/rowan"
license = "MIT OR Apache-2.0"
Expand Down
8 changes: 6 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ impl<L: Language> SyntaxNode<L> {
self.raw.detach()
}

pub fn splice_children(&self, to_delete: Range<usize>, to_insert: Vec<SyntaxElement<L>>) {
let to_insert = to_insert.into_iter().map(cursor::SyntaxElement::from).collect::<Vec<_>>();
pub fn splice_children<I: IntoIterator<Item = SyntaxElement<L>>>(
&self,
to_delete: Range<usize>,
to_insert: I,
) {
let to_insert = to_insert.into_iter().map(cursor::SyntaxElement::from);
self.raw.splice_children(to_delete, to_insert)
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,11 @@ impl SyntaxNode {
})
}

pub fn splice_children(&self, to_delete: Range<usize>, to_insert: Vec<SyntaxElement>) {
pub fn splice_children<I: IntoIterator<Item = SyntaxElement>>(
&self,
to_delete: Range<usize>,
to_insert: I,
) {
assert!(self.data().mutable, "immutable tree: {}", self);
for (i, child) in self.children_with_tokens().enumerate() {
if to_delete.contains(&i) {
Expand Down
Loading