Fix removal of generic param from list

This removes an existing generic param from the `GenericParamList`. It
also considers to remove the extra colon & whitespace to the previous
sibling.

* change order to get all param types first and mark them as mutable
  before the first edit happens
* add helper function to remove a generic parameter
* fix test output
This commit is contained in:
Sebastian Ziebell 2023-05-15 17:38:25 +02:00
parent 59f8827a6f
commit 95f59668e6
2 changed files with 30 additions and 17 deletions

View file

@ -236,6 +236,21 @@ impl ast::GenericParamList {
}
}
/// Removes the existing generic param
pub fn remove_generic_param(&self, generic_param: ast::GenericParam) {
if let Some(previous) = generic_param.syntax().prev_sibling() {
if let Some(next_token) = previous.next_sibling_or_token() {
ted::remove_all(next_token..=generic_param.syntax().clone().into());
}
} else if let Some(next) = generic_param.syntax().next_sibling() {
if let Some(next_token) = next.prev_sibling_or_token() {
ted::remove_all(generic_param.syntax().clone().into()..=next_token);
}
} else {
ted::remove(generic_param.syntax());
}
}
/// Constructs a matching [`ast::GenericArgList`]
pub fn to_generic_args(&self) -> ast::GenericArgList {
let args = self.generic_params().filter_map(|param| match param {