Skip to content

Commit faea7fc

Browse files
committed
fix: keep attrs for assist 'generate_delegate_trait'
1 parent 7c786ed commit faea7fc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use syntax::{
1616
ast::{
1717
self,
1818
edit::{self, AstNodeEdit},
19-
make, AssocItem, GenericArgList, GenericParamList, HasGenericParams, HasName,
19+
edit_in_place::AttrsOwnerEdit,
20+
make, AssocItem, GenericArgList, GenericParamList, HasAttrs, HasGenericParams, HasName,
2021
HasTypeBounds, HasVisibility as astHasVisibility, Path, WherePred,
2122
},
2223
ted::{self, Position},
@@ -619,7 +620,8 @@ fn process_assoc_item(
619620
qual_path_ty: ast::Path,
620621
base_name: &str,
621622
) -> Option<ast::AssocItem> {
622-
match item {
623+
let attrs = item.attrs();
624+
let assoc = match item {
623625
AssocItem::Const(c) => const_assoc_item(c, qual_path_ty),
624626
AssocItem::Fn(f) => func_assoc_item(f, qual_path_ty, base_name),
625627
AssocItem::MacroCall(_) => {
@@ -628,7 +630,18 @@ fn process_assoc_item(
628630
None
629631
}
630632
AssocItem::TypeAlias(ta) => ty_assoc_item(ta, qual_path_ty),
633+
};
634+
if let Some(assoc) = &assoc {
635+
attrs.for_each(|attr| {
636+
assoc.add_attr(attr.clone());
637+
// fix indentations
638+
if let Some(tok) = attr.syntax().next_sibling_or_token() {
639+
let pos = Position::after(tok);
640+
ted::insert(pos, make::tokens::whitespace(" "));
641+
}
642+
})
631643
}
644+
assoc
632645
}
633646

634647
fn const_assoc_item(item: syntax::ast::Const, qual_path_ty: ast::Path) -> Option<AssocItem> {

0 commit comments

Comments
 (0)