diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs index 0bd8070be164..dc92a127de1b 100644 --- a/crates/ide-completion/src/render/function.rs +++ b/crates/ide-completion/src/render/function.rs @@ -104,19 +104,21 @@ fn render( .filter(|_| !has_call_parens) .and_then(|cap| Some((cap, params(ctx.completion, func, &func_kind, has_dot_receiver)?))); - let type_match = if has_call_parens || complete_call_parens.is_some() { - compute_type_match(completion, &ret_type) - } else { - compute_type_match(completion, &func.ty(db)) - }; - - let function = - assoc_item.and_then(|assoc_item| assoc_item.implementing_ty(db)).and_then(|self_type| { - compute_function_match(db, &ctx, self_type, func, has_self_param, &ret_type) + let function = assoc_item + .and_then(|assoc_item| assoc_item.implementing_ty(db)) + .map(|self_type| compute_return_type_match(db, &ctx, self_type, &ret_type)) + .map(|return_type| CompletionRelevanceFn { + has_params: has_self_param || func.num_params(db) > 0, + has_self_param, + return_type, }); item.set_relevance(CompletionRelevance { - type_match, + type_match: if has_call_parens || complete_call_parens.is_some() { + compute_type_match(completion, &ret_type) + } else { + compute_type_match(completion, &func.ty(db)) + }, exact_name_match: compute_exact_name_match(completion, &call), function, is_op_method, @@ -169,17 +171,13 @@ fn render( item } -fn compute_function_match( +fn compute_return_type_match( db: &dyn HirDatabase, ctx: &RenderContext<'_>, self_type: hir::Type, - func: hir::Function, - has_self_param: bool, ret_type: &hir::Type, -) -> Option { - let has_params = func.num_params(db) > 0; - - let return_type = if match_types(ctx.completion, &self_type, &ret_type).is_some() { +) -> CompletionRelevanceReturnType { + if match_types(ctx.completion, &self_type, &ret_type).is_some() { // fn([..]) -> Self CompletionRelevanceReturnType::DirectConstructor } else if ret_type @@ -197,9 +195,7 @@ fn compute_function_match( CompletionRelevanceReturnType::Builder } else { CompletionRelevanceReturnType::Other - }; - - Some(CompletionRelevanceFn { return_type, has_params, has_self_param }) + } } pub(super) fn add_call_parens<'b>(