mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Refactor method candidate generation a bit
This fixes the order in which candidates are chosen a bit (not completely though, as the ignored test demonstrates), and makes autoderef work with trait methods. As a side effect, this also makes completion of trait methods work :)
This commit is contained in:
parent
88be6f3217
commit
4f8a49f43c
4 changed files with 179 additions and 58 deletions
|
@ -37,7 +37,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
|
|||
}
|
||||
|
||||
fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
|
||||
receiver.iterate_methods(ctx.db, |_ty, func| {
|
||||
ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| {
|
||||
let sig = func.signature(ctx.db);
|
||||
if sig.has_self_param() {
|
||||
acc.add_function(ctx, func);
|
||||
|
@ -195,6 +195,32 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trait_method_completion() {
|
||||
assert_debug_snapshot_matches!(
|
||||
do_ref_completion(
|
||||
r"
|
||||
struct A {}
|
||||
trait Trait { fn the_method(&self); }
|
||||
impl Trait for A {}
|
||||
fn foo(a: A) {
|
||||
a.<|>
|
||||
}
|
||||
",
|
||||
),
|
||||
@r###"[
|
||||
CompletionItem {
|
||||
label: "the_method",
|
||||
source_range: [151; 151),
|
||||
delete: [151; 151),
|
||||
insert: "the_method()$0",
|
||||
kind: Method,
|
||||
detail: "fn the_method(&self)"
|
||||
}
|
||||
]"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_non_self_method() {
|
||||
assert_debug_snapshot_matches!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue