mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
fix: refactor syntax_editor_add_generic_param to handle new generic parameters
Signed-off-by: Tarek <tareknaser360@gmail.com>
This commit is contained in:
parent
0990d5956d
commit
98e10d76ca
1 changed files with 11 additions and 12 deletions
|
@ -293,22 +293,21 @@ impl ast::GenericParamList {
|
|||
pub fn syntax_editor_add_generic_param(
|
||||
&self,
|
||||
editor: &mut SyntaxEditor,
|
||||
generic_param: ast::GenericParam,
|
||||
new_param: ast::GenericParam,
|
||||
) {
|
||||
match self.generic_params().last() {
|
||||
Some(last_param) => {
|
||||
let position = crate::syntax_editor::Position::after(last_param.syntax());
|
||||
let elements = vec![
|
||||
make::token(T![,]).into(),
|
||||
make::tokens::single_space().into(),
|
||||
generic_param.syntax().clone().into(),
|
||||
];
|
||||
editor.insert_all(position, elements);
|
||||
Some(_) => {
|
||||
let mut params =
|
||||
self.generic_params().map(|param| param.clone()).collect::<Vec<_>>();
|
||||
params.push(new_param.into());
|
||||
let new_param_list = make::generic_param_list(params);
|
||||
|
||||
editor.replace(self.syntax(), new_param_list.syntax());
|
||||
}
|
||||
None => {
|
||||
let after_l_angle =
|
||||
crate::syntax_editor::Position::after(self.l_angle_token().unwrap());
|
||||
editor.insert(after_l_angle, generic_param.syntax());
|
||||
let position = crate::syntax_editor::Position::after(self.l_angle_token().unwrap());
|
||||
let new_param_list = make::generic_param_list(once(new_param.clone()));
|
||||
editor.insert(position, new_param_list.syntax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue