mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 10:17:15 +00:00
Modify around add_trait_assoc_items_to_impl to migrate add_missing_impl_members
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
This commit is contained in:
parent
827e3f7c17
commit
82dfdacb78
6 changed files with 229 additions and 110 deletions
|
|
@ -237,7 +237,7 @@ pub fn assoc_item_list(
|
|||
let body_indent = if is_break_braces { " ".to_owned() } else { String::new() };
|
||||
|
||||
let body = match body {
|
||||
Some(bd) => bd.iter().map(|elem| elem.to_string()).join(""),
|
||||
Some(bd) => bd.iter().map(|elem| elem.to_string()).join("\n\n "),
|
||||
None => String::new(),
|
||||
};
|
||||
ast_from_text(&format!("impl C for D {{{body_newline}{body_indent}{body}{body_newline}}}"))
|
||||
|
|
|
|||
|
|
@ -92,6 +92,42 @@ fn get_or_insert_comma_after(editor: &mut SyntaxEditor, syntax: &SyntaxNode) ->
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::AssocItemList {
|
||||
/// Adds a new associated item after all of the existing associated items.
|
||||
///
|
||||
/// Attention! This function does align the first line of `item` with respect to `self`,
|
||||
/// but it does _not_ change indentation of other lines (if any).
|
||||
pub fn add_items(&self, editor: &mut SyntaxEditor, items: Vec<ast::AssocItem>) {
|
||||
let (indent, position, whitespace) = match self.assoc_items().last() {
|
||||
Some(last_item) => (
|
||||
IndentLevel::from_node(last_item.syntax()),
|
||||
Position::after(last_item.syntax()),
|
||||
"\n\n",
|
||||
),
|
||||
None => match self.l_curly_token() {
|
||||
Some(l_curly) => {
|
||||
normalize_ws_between_braces(editor, self.syntax());
|
||||
(IndentLevel::from_token(&l_curly) + 1, Position::after(&l_curly), "\n")
|
||||
}
|
||||
None => (IndentLevel::single(), Position::last_child_of(self.syntax()), "\n"),
|
||||
},
|
||||
};
|
||||
|
||||
let elements: Vec<SyntaxElement> = items
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, item)| {
|
||||
let whitespace = if i != 0 { "\n\n" } else { whitespace };
|
||||
vec![
|
||||
make::tokens::whitespace(&format!("{whitespace}{indent}")).into(),
|
||||
item.syntax().clone().into(),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
editor.insert_all(position, elements);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::VariantList {
|
||||
pub fn add_variant(&self, editor: &mut SyntaxEditor, variant: &ast::Variant) {
|
||||
let make = SyntaxFactory::without_mappings();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue