-
Notifications
You must be signed in to change notification settings - Fork 1.9k
internal: Migrate convert_bool_then to SyntaxEditor
#19253
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
internal: Migrate convert_bool_then to SyntaxEditor
#19253
Conversation
30c23d7 to
f6ea1c4
Compare
|
Oh, I accidentally added part of another migration - |
DropDemBits
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only looked at the convert_bool_then-related changes, but looks good to me & approving those changes.
Waiting on convert_closure_to_fn changes to be split out. Surprised that it's using splice_children in the first place, but shouldn't be too hard to replace it with the SyntaxEditor equivalent.
Update assist docs
f6ea1c4 to
37822d5
Compare
|
Dropped unfinished |
| use syntax::{ | ||
| ast::{self, edit::AstNodeEdit, make, HasArgList}, | ||
| ted, AstNode, SyntaxNode, | ||
| ast::{self, edit::AstNodeEdit, syntax_factory::SyntaxFactory, HasArgList}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does still use AstNodeEdit for indentation, I assume that's mainly to not regress indentation for now? (merging either way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, currently we have two ways to indent things (except manually indenting all lines in a syntax node):
rust-analyzer/crates/syntax/src/ast/edit.rs
Lines 119 to 133 in 81ff38f
| /// Soft-deprecated in favor of mutable tree editing API `edit_in_place::Ident`. | |
| pub trait AstNodeEdit: AstNode + Clone + Sized { | |
| fn indent_level(&self) -> IndentLevel { | |
| IndentLevel::from_node(self.syntax()) | |
| } | |
| #[must_use] | |
| fn indent(&self, level: IndentLevel) -> Self { | |
| fn indent_inner(node: &SyntaxNode, level: IndentLevel) -> SyntaxNode { | |
| let res = node.clone_subtree().clone_for_update(); | |
| level.increase_indent(&res); | |
| res.clone_subtree() | |
| } | |
| Self::cast(indent_inner(self.syntax(), level)).unwrap() | |
| } |
rust-analyzer/crates/syntax/src/ast/edit_in_place.rs
Lines 964 to 970 in 81ff38f
| pub trait Indent: AstNode + Clone + Sized { | |
| fn indent_level(&self) -> IndentLevel { | |
| IndentLevel::from_node(self.syntax()) | |
| } | |
| fn indent(&self, by: IndentLevel) { | |
| by.increase_indent(self.syntax()); | |
| } |
and both of them utilizes mutable syntax trees.l
I'll add a non-mutable syntax tree alternative and replace previous usages with it in next PR 😄
Part of #18285