Add MethodCallExpr::get_or_create_generic_arg_list

Mirrors `PathSegment's` version, except that it always generates a
turbofish
This commit is contained in:
DropDemBits 2023-07-10 23:56:59 -04:00
parent 3b7c7f97e4
commit 02c7b8b9ba
No known key found for this signature in database
GPG key ID: 7FE02A6C1EDFA075
2 changed files with 26 additions and 1 deletions

View file

@ -14,7 +14,7 @@ use crate::{
SyntaxNode, SyntaxToken,
};
use super::HasName;
use super::{HasArgList, HasName};
pub trait GenericParamsOwnerEdit: ast::HasGenericParams {
fn get_or_create_generic_param_list(&self) -> ast::GenericParamList;
@ -362,6 +362,24 @@ impl ast::PathSegment {
}
}
impl ast::MethodCallExpr {
pub fn get_or_create_generic_arg_list(&self) -> ast::GenericArgList {
if self.generic_arg_list().is_none() {
let generic_arg_list = make::turbofish_generic_arg_list(empty()).clone_for_update();
if let Some(arg_list) = self.arg_list() {
ted::insert_raw(
ted::Position::before(arg_list.syntax()),
generic_arg_list.syntax(),
);
} else {
ted::append_child(self.syntax(), generic_arg_list.syntax());
}
}
self.generic_arg_list().unwrap()
}
}
impl Removable for ast::UseTree {
fn remove(&self) {
for dir in [Direction::Next, Direction::Prev] {