Skip to content

Commit

Permalink
more optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
mustakimali committed Feb 12, 2024
1 parent 6c5403e commit 2464387
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions crates/ide-completion/src/render/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<CompletionRelevanceFn> {
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
Expand All @@ -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>(
Expand Down

0 comments on commit 2464387

Please sign in to comment.