Skip to content

Commit bdd22eb

Browse files
Merge #4126
4126: Don't omit methods with self from path completion r=matklad a=jonas-schievink It's sometimes useful to create a reference to these items (eg. for use as a function pointer). Perhaps these should be given lower score though, if that's possible? Co-authored-by: Jonas Schievink <[email protected]>
2 parents 5d97667 + 7b9553a commit bdd22eb

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

crates/ra_ide/src/completion/complete_qualified_path.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
5757
}
5858
match item {
5959
hir::AssocItem::Function(func) => {
60-
if !func.has_self_param(ctx.db) {
61-
acc.add_function(ctx, func, None);
62-
}
60+
acc.add_function(ctx, func, None);
6361
}
6462
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
6563
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
@@ -86,9 +84,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
8684
}
8785
match item {
8886
hir::AssocItem::Function(func) => {
89-
if !func.has_self_param(ctx.db) {
90-
acc.add_function(ctx, func, None);
91-
}
87+
acc.add_function(ctx, func, None);
9288
}
9389
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
9490
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
@@ -482,6 +478,42 @@ mod tests {
482478
);
483479
}
484480

481+
#[test]
482+
fn completes_struct_associated_method_with_self() {
483+
assert_debug_snapshot!(
484+
do_reference_completion(
485+
"
486+
//- /lib.rs
487+
/// A Struct
488+
struct S;
489+
490+
impl S {
491+
/// An associated method
492+
fn m(&self) { }
493+
}
494+
495+
fn foo() { let _ = S::<|> }
496+
"
497+
),
498+
@r###"
499+
[
500+
CompletionItem {
501+
label: "m()",
502+
source_range: [105; 105),
503+
delete: [105; 105),
504+
insert: "m()$0",
505+
kind: Method,
506+
lookup: "m",
507+
detail: "fn m(&self)",
508+
documentation: Documentation(
509+
"An associated method",
510+
),
511+
},
512+
]
513+
"###
514+
);
515+
}
516+
485517
#[test]
486518
fn completes_struct_associated_const() {
487519
assert_debug_snapshot!(

0 commit comments

Comments
 (0)