-fn introduction_builder(ast_func: &ast::Fn) -> String {
- let is_new = ast_func.name().map(|name| &name.to_string() == "new").unwrap_or(false);
- if is_new {
- let ret_type = return_type(ast_func).map(|ret_type| ret_type.to_string());
- let self_type = self_type(ast_func);
- if ret_type.as_deref() == Some("Self") || ret_type == self_type {
- if let Some(self_type) = self_type {
- return format!("Creates a new [`{}`].", self_type);
+fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext) -> String {
+ || -> Option<String> {
+ let hir_func = ctx.sema.to_def(ast_func)?;
+ let container = hir_func.as_assoc_item(ctx.db())?.container(ctx.db());
+ if let hir::AssocItemContainer::Impl(implementation) = container {
+ let ret_ty = hir_func.ret_type(ctx.db());
+ let self_ty = implementation.self_ty(ctx.db());
+
+ let is_new = ast_func.name()?.to_string() == "new";
+ match is_new && ret_ty == self_ty {
+ true => Some(format!("Creates a new [`{}`].", self_type(ast_func)?)),
+ false => None,