aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-24 20:57:24 +0100
committerGitHub <[email protected]>2020-04-24 20:57:24 +0100
commitbdd22eb8bd35dc4d5ff1bc8e00eb44bc48d14dcd (patch)
treed45970bbfa388a83dfef0fb63f3257d5b7a0ca77 /crates/ra_ide
parent5d97667f8dd467e7382885fcae40bcdbac63ae4f (diff)
parent7b9553a7039a5307b8c436d4128e08b74f75c55b (diff)
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]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/completion/complete_qualified_path.rs44
1 files changed, 38 insertions, 6 deletions
diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs
index 9f795e441..5a5139e14 100644
--- a/crates/ra_ide/src/completion/complete_qualified_path.rs
+++ b/crates/ra_ide/src/completion/complete_qualified_path.rs
@@ -57,9 +57,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
57 } 57 }
58 match item { 58 match item {
59 hir::AssocItem::Function(func) => { 59 hir::AssocItem::Function(func) => {
60 if !func.has_self_param(ctx.db) { 60 acc.add_function(ctx, func, None);
61 acc.add_function(ctx, func, None);
62 }
63 } 61 }
64 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), 62 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
65 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), 63 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
86 } 84 }
87 match item { 85 match item {
88 hir::AssocItem::Function(func) => { 86 hir::AssocItem::Function(func) => {
89 if !func.has_self_param(ctx.db) { 87 acc.add_function(ctx, func, None);
90 acc.add_function(ctx, func, None);
91 }
92 } 88 }
93 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), 89 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
94 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), 90 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
@@ -483,6 +479,42 @@ mod tests {
483 } 479 }
484 480
485 #[test] 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
517 #[test]
486 fn completes_struct_associated_const() { 518 fn completes_struct_associated_const() {
487 assert_debug_snapshot!( 519 assert_debug_snapshot!(
488 do_reference_completion( 520 do_reference_completion(