Closed IWANABETHATGUY closed 2 years ago
There is a mutable api, see https://docs.rs/rowan/0.14.1/rowan/api/struct.SyntaxNode.html#method.splice_children and for some example usages https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/syntax/src/ted.rs.
To be able to mutate a node you have to first clone_for_update
it though, https://docs.rs/rowan/0.14.1/rowan/api/struct.SyntaxNode.html#method.clone_for_update, if this isn't done you will panic at runtime when trying to mutate an immutable syntax node.
There is a mutable api, see https://docs.rs/rowan/0.14.1/rowan/api/struct.SyntaxNode.html#method.splice_children and for some example usages https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/syntax/src/ted.rs. To be able to mutate a node you have to first
clone_for_update
it though, https://docs.rs/rowan/0.14.1/rowan/api/struct.SyntaxNode.html#method.clone_for_update, if this isn't done you will panic at runtime when trying to mutate an immutable syntax node.
Still have some question to ask, Could you leave me a way to get in touch, maybe like discord?If not, That's fine too, and thank you again.
You can ask on Zulip.
Thanks a lot
You can ask on Zulip.
It seems that Zulip don't have rowan stream, so which stream should i choose when i have a question?
You can make a new topic in the rust-analyzer stream (which I linked to).
You can make a new topic in the rust-analyzer stream (which I linked to).
Nice, Thank you.
I am using rowan to write a transpiler , but the rowan's syntax node is immutable, so convert ast is very hard. So i am wonder if there has some best practice to do these thing.