Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/render/function.rs')
| -rw-r--r-- | crates/ide-completion/src/render/function.rs | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs index dfae715afe..d23ed71fdc 100644 --- a/crates/ide-completion/src/render/function.rs +++ b/crates/ide-completion/src/render/function.rs @@ -62,6 +62,7 @@ fn render( ), _ => (name.unescaped().to_smol_str(), name.to_smol_str()), }; + let mut item = CompletionItem::new( if func.self_param(db).is_some() { CompletionItemKind::Method @@ -77,8 +78,31 @@ fn render( .as_assoc_item(ctx.db()) .and_then(|trait_| trait_.containing_trait_or_trait_impl(ctx.db())) .map_or(false, |trait_| completion.is_ops_trait(trait_)); + + let (has_dot_receiver, has_call_parens, cap) = match func_kind { + FuncKind::Function(&PathCompletionCtx { + kind: PathKind::Expr { .. }, + has_call_parens, + .. + }) => (false, has_call_parens, ctx.completion.config.snippet_cap), + FuncKind::Method(&DotAccess { kind: DotAccessKind::Method { has_parens }, .. }, _) => { + (true, has_parens, ctx.completion.config.snippet_cap) + } + FuncKind::Method(DotAccess { kind: DotAccessKind::Field { .. }, .. }, _) => { + (true, false, ctx.completion.config.snippet_cap) + } + _ => (false, false, None), + }; + let complete_call_parens = cap + .filter(|_| !has_call_parens) + .and_then(|cap| Some((cap, params(ctx.completion, func, &func_kind, has_dot_receiver)?))); + item.set_relevance(CompletionRelevance { - type_match: compute_type_match(completion, &ret_type), + 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), is_op_method, ..ctx.completion_relevance() @@ -108,42 +132,9 @@ fn render( .detail(detail) .lookup_by(name.unescaped().to_smol_str()); - match ctx.completion.config.snippet_cap { - Some(cap) => { - let complete_params = match func_kind { - FuncKind::Function(PathCompletionCtx { - kind: PathKind::Expr { .. }, - has_call_parens: false, - .. - }) => Some(false), - FuncKind::Method( - DotAccess { - kind: - DotAccessKind::Method { has_parens: false } | DotAccessKind::Field { .. }, - .. - }, - _, - ) => Some(true), - _ => None, - }; - if let Some(has_dot_receiver) = complete_params { - if let Some((self_param, params)) = - params(ctx.completion, func, &func_kind, has_dot_receiver) - { - add_call_parens( - &mut item, - completion, - cap, - call, - escaped_call, - self_param, - params, - ); - } - } - } - _ => (), - }; + if let Some((cap, (self_param, params))) = complete_call_parens { + add_call_parens(&mut item, completion, cap, call, escaped_call, self_param, params); + } match ctx.import_to_add { Some(import_to_add) => { |