mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Merge pull request #20345 from Hmikihiro/Migrate_add_trait_assoc_items_to_impl
Some checks failed
metrics / build_metrics (push) Has been cancelled
rustdoc / rustdoc (push) Has been cancelled
metrics / other_metrics (diesel-1.4.8) (push) Has been cancelled
metrics / other_metrics (hyper-0.14.18) (push) Has been cancelled
metrics / other_metrics (ripgrep-13.0.0) (push) Has been cancelled
metrics / other_metrics (self) (push) Has been cancelled
metrics / other_metrics (webrender-2022) (push) Has been cancelled
metrics / generate_final_metrics (push) Has been cancelled
Some checks failed
metrics / build_metrics (push) Has been cancelled
rustdoc / rustdoc (push) Has been cancelled
metrics / other_metrics (diesel-1.4.8) (push) Has been cancelled
metrics / other_metrics (hyper-0.14.18) (push) Has been cancelled
metrics / other_metrics (ripgrep-13.0.0) (push) Has been cancelled
metrics / other_metrics (self) (push) Has been cancelled
metrics / other_metrics (webrender-2022) (push) Has been cancelled
metrics / generate_final_metrics (push) Has been cancelled
add `SyntaxEditor::delete_all` to migrate utils.rs `add_trait_assoc_items_to_impl`
This commit is contained in:
commit
68e7ec90bf
3 changed files with 68 additions and 27 deletions
|
|
@ -83,6 +83,16 @@ impl SyntaxEditor {
|
|||
self.changes.push(Change::Replace(element.syntax_element(), None));
|
||||
}
|
||||
|
||||
pub fn delete_all(&mut self, range: RangeInclusive<SyntaxElement>) {
|
||||
if range.start() == range.end() {
|
||||
self.delete(range.start());
|
||||
return;
|
||||
}
|
||||
|
||||
debug_assert!(is_ancestor_or_self_of_element(range.start(), &self.root));
|
||||
self.changes.push(Change::ReplaceAll(range, Vec::new()))
|
||||
}
|
||||
|
||||
pub fn replace(&mut self, old: impl Element, new: impl Element) {
|
||||
let old = old.syntax_element();
|
||||
debug_assert!(is_ancestor_or_self_of_element(&old, &self.root));
|
||||
|
|
|
|||
|
|
@ -153,6 +153,23 @@ impl ast::VariantList {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::Fn {
|
||||
pub fn replace_or_insert_body(&self, editor: &mut SyntaxEditor, body: ast::BlockExpr) {
|
||||
if let Some(old_body) = self.body() {
|
||||
editor.replace(old_body.syntax(), body.syntax());
|
||||
} else {
|
||||
let single_space = make::tokens::single_space();
|
||||
let elements = vec![single_space.into(), body.syntax().clone().into()];
|
||||
|
||||
if let Some(semicolon) = self.semicolon_token() {
|
||||
editor.replace_with_many(semicolon, elements);
|
||||
} else {
|
||||
editor.insert_all(Position::last_child_of(self.syntax()), elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_ws_between_braces(editor: &mut SyntaxEditor, node: &SyntaxNode) -> Option<()> {
|
||||
let make = SyntaxFactory::without_mappings();
|
||||
let l = node
|
||||
|
|
@ -184,6 +201,15 @@ pub trait Removable: AstNode {
|
|||
fn remove(&self, editor: &mut SyntaxEditor);
|
||||
}
|
||||
|
||||
impl Removable for ast::TypeBoundList {
|
||||
fn remove(&self, editor: &mut SyntaxEditor) {
|
||||
match self.syntax().siblings_with_tokens(Direction::Prev).find(|it| it.kind() == T![:]) {
|
||||
Some(colon) => editor.delete_all(colon..=self.syntax().clone().into()),
|
||||
None => editor.delete(self.syntax()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Removable for ast::Use {
|
||||
fn remove(&self, editor: &mut SyntaxEditor) {
|
||||
let make = SyntaxFactory::without_mappings();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue