mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Add MethodCallExpr::get_or_create_generic_arg_list
Mirrors `PathSegment's` version, except that it always generates a turbofish
This commit is contained in:
parent
3b7c7f97e4
commit
02c7b8b9ba
2 changed files with 26 additions and 1 deletions
|
@ -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] {
|
||||
|
|
|
@ -941,6 +941,13 @@ pub fn lifetime_arg(lifetime: ast::Lifetime) -> ast::LifetimeArg {
|
|||
ast_from_text(&format!("const S: T<{lifetime}> = ();"))
|
||||
}
|
||||
|
||||
pub fn turbofish_generic_arg_list(
|
||||
args: impl IntoIterator<Item = ast::GenericArg>,
|
||||
) -> ast::GenericArgList {
|
||||
let args = args.into_iter().join(", ");
|
||||
ast_from_text(&format!("const S: T::<{args}> = ();"))
|
||||
}
|
||||
|
||||
pub(crate) fn generic_arg_list(
|
||||
args: impl IntoIterator<Item = ast::GenericArg>,
|
||||
) -> ast::GenericArgList {
|
||||
|
|
Loading…
Reference in a new issue