mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
define syntax_editor_add_generic_param
Signed-off-by: Tarek <tareknaser360@gmail.com>
This commit is contained in:
parent
4af3d6f598
commit
642d4f3385
3 changed files with 34 additions and 7 deletions
|
@ -7,6 +7,7 @@ use parser::{SyntaxKind, T};
|
|||
use crate::{
|
||||
algo::{self, neighbor},
|
||||
ast::{self, edit::IndentLevel, make, HasGenericArgs, HasGenericParams},
|
||||
syntax_editor::SyntaxEditor,
|
||||
ted::{self, Position},
|
||||
AstNode, AstToken, Direction, SyntaxElement,
|
||||
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
||||
|
@ -257,6 +258,29 @@ impl ast::GenericParamList {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn syntax_editor_add_generic_param(
|
||||
&self,
|
||||
editor: &mut SyntaxEditor,
|
||||
generic_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);
|
||||
}
|
||||
None => {
|
||||
let after_l_angle =
|
||||
crate::syntax_editor::Position::after(self.l_angle_token().unwrap());
|
||||
editor.insert(after_l_angle, generic_param.syntax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the existing generic param
|
||||
pub fn remove_generic_param(&self, generic_param: ast::GenericParam) {
|
||||
if let Some(previous) = generic_param.syntax().prev_sibling() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue