Skip to content

Commit 48ea382

Browse files
committed
Introduce and use get_fn_target_info
1 parent d8e7419 commit 48ea382

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,10 @@ fn fn_target_info(
104104
call: &CallExpr,
105105
fn_name: &str,
106106
) -> Option<TargetInfo> {
107-
let target_module;
108-
let adt_name = None;
109-
let (target, file, insert_offset) = match path.qualifier() {
107+
match path.qualifier() {
110108
Some(qualifier) => match ctx.sema.resolve_path(&qualifier) {
111109
Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) => {
112-
target_module = Some(module);
113-
get_fn_target(ctx, &target_module, call.clone())?
110+
get_fn_target_info(ctx, &Some(module), call.clone())
114111
}
115112
Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
116113
if let hir::Adt::Enum(_) = adt {
@@ -120,22 +117,16 @@ fn fn_target_info(
120117
}
121118
}
122119

123-
return assoc_fn_target_info(ctx, call, adt, fn_name);
120+
assoc_fn_target_info(ctx, call, adt, fn_name)
124121
}
125122
Some(hir::PathResolution::SelfType(impl_)) => {
126123
let adt = impl_.self_ty(ctx.db()).as_adt()?;
127-
return assoc_fn_target_info(ctx, call, adt, fn_name);
128-
}
129-
_ => {
130-
return None;
124+
assoc_fn_target_info(ctx, call, adt, fn_name)
131125
}
126+
_ => None,
132127
},
133-
_ => {
134-
target_module = None;
135-
get_fn_target(ctx, &target_module, call.clone())?
136-
}
137-
};
138-
Some(TargetInfo::new(target_module, adt_name, target, file, insert_offset))
128+
_ => get_fn_target_info(ctx, &None, call.clone()),
129+
}
139130
}
140131

141132
fn gen_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
@@ -391,6 +382,15 @@ fn make_return_type(
391382
(ret_type, should_focus_return_type)
392383
}
393384

385+
fn get_fn_target_info(
386+
ctx: &AssistContext<'_>,
387+
target_module: &Option<Module>,
388+
call: CallExpr,
389+
) -> Option<TargetInfo> {
390+
let (target, file, insert_offset) = get_fn_target(ctx, target_module, call)?;
391+
Some(TargetInfo::new(*target_module, None, target, file, insert_offset))
392+
}
393+
394394
fn get_fn_target(
395395
ctx: &AssistContext<'_>,
396396
target_module: &Option<Module>,

0 commit comments

Comments
 (0)