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.rs67
1 files changed, 27 insertions, 40 deletions
diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs
index ff84aa8742..d23ed71fdc 100644
--- a/crates/ide-completion/src/render/function.rs
+++ b/crates/ide-completion/src/render/function.rs
@@ -9,9 +9,7 @@ use syntax::{AstNode, SmolStr};
use crate::{
context::{CompletionContext, DotAccess, DotAccessKind, PathCompletionCtx, PathKind},
item::{Builder, CompletionItem, CompletionItemKind, CompletionRelevance},
- render::{
- compute_exact_name_match, compute_function_type_match, compute_ref_match, RenderContext,
- },
+ render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
CallableSnippets,
};
@@ -81,8 +79,30 @@ fn render(
.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_function_type_match(completion, &func),
+ 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()
@@ -112,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) => {