mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
tweak syntax
This commit is contained in:
parent
d42fd8efb6
commit
4967b811dd
1 changed files with 41 additions and 50 deletions
|
@ -37,8 +37,7 @@ pub(crate) fn change_lifetime_anon_to_named(acc: &mut Assists, ctx: &AssistConte
|
|||
// only allow naming the last anonymous lifetime
|
||||
return None;
|
||||
}
|
||||
match lifetime_arg.syntax().ancestors().find_map(ast::ImplDef::cast) {
|
||||
Some(impl_def) => {
|
||||
let impl_def = lifetime_arg.syntax().ancestors().find_map(ast::ImplDef::cast)?;
|
||||
// get the `impl` keyword so we know where to add the lifetime argument
|
||||
let impl_kw = impl_def.syntax().first_child_or_token()?.into_token()?;
|
||||
if impl_kw.kind() != SyntaxKind::IMPL_KW {
|
||||
|
@ -73,21 +72,13 @@ pub(crate) fn change_lifetime_anon_to_named(acc: &mut Assists, ctx: &AssistConte
|
|||
);
|
||||
}
|
||||
None => {
|
||||
builder.insert(
|
||||
impl_kw.text_range().end(),
|
||||
format!("<'{}>", new_lifetime_param),
|
||||
);
|
||||
builder
|
||||
.insert(impl_kw.text_range().end(), format!("<'{}>", new_lifetime_param));
|
||||
}
|
||||
}
|
||||
builder.replace(
|
||||
lifetime_arg.syntax().text_range(),
|
||||
format!("'{}", new_lifetime_param),
|
||||
);
|
||||
builder.replace(lifetime_arg.syntax().text_range(), format!("'{}", new_lifetime_param));
|
||||
},
|
||||
)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue