about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-24 19:57:24 +0000
committerGitHub <noreply@github.com>2020-04-24 19:57:24 +0000
commitbdd22eb8bd35dc4d5ff1bc8e00eb44bc48d14dcd (patch)
treed45970bbfa388a83dfef0fb63f3257d5b7a0ca77
parent5d97667f8dd467e7382885fcae40bcdbac63ae4f (diff)
parent7b9553a7039a5307b8c436d4128e08b74f75c55b (diff)
downloadrust-bdd22eb8bd35dc4d5ff1bc8e00eb44bc48d14dcd.tar.gz
rust-bdd22eb8bd35dc4d5ff1bc8e00eb44bc48d14dcd.zip
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 <jonasschievink@gmail.com>
-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 9f795e44144..5a5139e14c2 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
                     }
                     match item {
                         hir::AssocItem::Function(func) => {
-                            if !func.has_self_param(ctx.db) {
-                                acc.add_function(ctx, func, None);
-                            }
+                            acc.add_function(ctx, func, None);
                         }
                         hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
                         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
                 }
                 match item {
                     hir::AssocItem::Function(func) => {
-                        if !func.has_self_param(ctx.db) {
-                            acc.add_function(ctx, func, None);
-                        }
+                        acc.add_function(ctx, func, None);
                     }
                     hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
                     hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
@@ -483,6 +479,42 @@ mod tests {
     }
 
     #[test]
+    fn completes_struct_associated_method_with_self() {
+        assert_debug_snapshot!(
+            do_reference_completion(
+                "
+                //- /lib.rs
+                /// A Struct
+                struct S;
+
+                impl S {
+                    /// An associated method
+                    fn m(&self) { }
+                }
+
+                fn foo() { let _ = S::<|> }
+                "
+            ),
+            @r###"
+        [
+            CompletionItem {
+                label: "m()",
+                source_range: [105; 105),
+                delete: [105; 105),
+                insert: "m()$0",
+                kind: Method,
+                lookup: "m",
+                detail: "fn m(&self)",
+                documentation: Documentation(
+                    "An associated method",
+                ),
+            },
+        ]
+        "###
+        );
+    }
+
+    #[test]
     fn completes_struct_associated_const() {
         assert_debug_snapshot!(
             do_reference_completion(