Skip to content

Commit 3edde6f

Browse files
committed
Support generic function in generate_function assist
1 parent 32955c3 commit 3edde6f

File tree

5 files changed

+888
-45
lines changed

5 files changed

+888
-45
lines changed

crates/hir/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,16 @@ impl AsAssocItem for ModuleDef {
21652165
}
21662166
}
21672167
}
2168+
impl AsAssocItem for DefWithBody {
2169+
fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> {
2170+
match self {
2171+
DefWithBody::Function(it) => it.as_assoc_item(db),
2172+
DefWithBody::Const(it) => it.as_assoc_item(db),
2173+
DefWithBody::Static(_) | DefWithBody::Variant(_) => None,
2174+
}
2175+
}
2176+
}
2177+
21682178
fn as_assoc_item<ID, DEF, CTOR, AST>(db: &dyn HirDatabase, ctor: CTOR, id: ID) -> Option<AssocItem>
21692179
where
21702180
ID: Lookup<Data = AssocItemLoc<AST>>,
@@ -2560,6 +2570,14 @@ impl GenericParam {
25602570
GenericParam::LifetimeParam(it) => it.name(db),
25612571
}
25622572
}
2573+
2574+
pub fn parent(self) -> GenericDef {
2575+
match self {
2576+
GenericParam::TypeParam(it) => it.id.parent().into(),
2577+
GenericParam::ConstParam(it) => it.id.parent().into(),
2578+
GenericParam::LifetimeParam(it) => it.id.parent.into(),
2579+
}
2580+
}
25632581
}
25642582

25652583
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
109109
let tail_expr_finished =
110110
if is_async { make::expr_await(tail_expr) } else { tail_expr };
111111
let body = make::block_expr([], Some(tail_expr_finished));
112-
let f = make::fn_(vis, name, type_params, params, body, ret_type, is_async)
112+
let f = make::fn_(vis, name, type_params, None, params, body, ret_type, is_async)
113113
.indent(ast::edit::IndentLevel(1))
114114
.clone_for_update();
115115

0 commit comments

Comments
 (0)