Deprioritize ops function completions for non-method calls
This commit is contained in:
parent
4800c05a20
commit
fcdced115e
@ -1354,7 +1354,7 @@ fn foo(…) []
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn op_method_relevances() {
|
fn op_function_relevances() {
|
||||||
check_relevance(
|
check_relevance(
|
||||||
r#"
|
r#"
|
||||||
#[lang = "sub"]
|
#[lang = "sub"]
|
||||||
@ -1367,7 +1367,30 @@ fn foo(a: u32) { a.$0 }
|
|||||||
expect![[r#"
|
expect![[r#"
|
||||||
me sub(…) (as Sub) [op_method]
|
me sub(…) (as Sub) [op_method]
|
||||||
"#]],
|
"#]],
|
||||||
)
|
);
|
||||||
|
check_relevance(
|
||||||
|
r#"
|
||||||
|
struct Foo;
|
||||||
|
impl Foo {
|
||||||
|
fn new() -> Self {}
|
||||||
|
}
|
||||||
|
#[lang = "eq"]
|
||||||
|
pub trait PartialEq<Rhs: ?Sized = Self> {
|
||||||
|
fn eq(&self, other: &Rhs) -> bool;
|
||||||
|
fn ne(&self, other: &Rhs) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Foo {}
|
||||||
|
fn main() {
|
||||||
|
Foo::$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn new() []
|
||||||
|
me eq(…) (as PartialEq) [op_method]
|
||||||
|
me ne(…) (as PartialEq) [op_method]
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -67,16 +67,14 @@ fn render(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let ret_type = func.ret_type(db);
|
let ret_type = func.ret_type(db);
|
||||||
|
let is_op_method = func
|
||||||
|
.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_));
|
||||||
item.set_relevance(CompletionRelevance {
|
item.set_relevance(CompletionRelevance {
|
||||||
type_match: compute_type_match(completion, &ret_type),
|
type_match: compute_type_match(completion, &ret_type),
|
||||||
exact_name_match: compute_exact_name_match(completion, &call),
|
exact_name_match: compute_exact_name_match(completion, &call),
|
||||||
is_op_method: match func_type {
|
is_op_method,
|
||||||
FuncType::Method(_) => func
|
|
||||||
.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_)),
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
..CompletionRelevance::default()
|
..CompletionRelevance::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user