about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-03-21 19:41:39 +0100
committerLukas Wirth <lukastw97@gmail.com>2022-03-21 19:41:39 +0100
commit7370a6b5b84d6378eb6808430635e881c2369b8a (patch)
tree9e863238477ea11e983c0ae100f01638a37d1f80
parent6a0b199c8232a62227fe2785ea6b8e7a4924fb3e (diff)
downloadrust-7370a6b5b84d6378eb6808430635e881c2369b8a.tar.gz
rust-7370a6b5b84d6378eb6808430635e881c2369b8a.zip
fix: Fix flyimport showing functions in pattern position
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs19
-rw-r--r--crates/ide_completion/src/tests/flyimport.rs11
-rw-r--r--crates/ide_db/src/imports/import_assets.rs2
3 files changed, 19 insertions, 13 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 6c8878a7bb0..ee751f9f773 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -141,15 +141,18 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
         &ctx.sema,
     )?;
 
+    let path_kind = match ctx.path_kind() {
+        Some(kind) => Some(kind),
+        None if ctx.pattern_ctx.is_some() => Some(PathKind::Pat),
+        None => None,
+    };
     let ns_filter = |import: &LocatedImport| {
-        let path_kind = match ctx.path_kind() {
-            Some(kind) => kind,
-            None => {
-                return match import.original_item {
-                    ItemInNs::Macros(mac) => mac.is_fn_like(ctx.db),
-                    _ => true,
-                }
-            }
+        let path_kind = match path_kind {
+            Some(path_kind) => path_kind,
+            None => match import.original_item {
+                ItemInNs::Macros(mac) => return mac.is_fn_like(ctx.db),
+                _ => return true,
+            },
         };
         match (path_kind, import.original_item) {
             // Aren't handled in flyimport
diff --git a/crates/ide_completion/src/tests/flyimport.rs b/crates/ide_completion/src/tests/flyimport.rs
index c996a5f01f8..4a0fcf34429 100644
--- a/crates/ide_completion/src/tests/flyimport.rs
+++ b/crates/ide_completion/src/tests/flyimport.rs
@@ -1030,15 +1030,18 @@ fn flyimport_pattern() {
     check(
         r#"
 mod module {
-    pub struct Struct;
+    pub struct FooStruct {}
+    pub const FooConst: () = ();
+    pub fn foo_fun() {}
 }
 fn function() {
-    let Str$0
+    let foo$0
 }
 "#,
         expect![[r#"
-                st Struct (use module::Struct)
-            "#]],
+            ct FooConst (use module::FooConst)
+            st FooStruct (use module::FooStruct)
+        "#]],
     );
 }
 
diff --git a/crates/ide_db/src/imports/import_assets.rs b/crates/ide_db/src/imports/import_assets.rs
index 9a09c40ee64..3963d4d79a8 100644
--- a/crates/ide_db/src/imports/import_assets.rs
+++ b/crates/ide_db/src/imports/import_assets.rs
@@ -66,7 +66,7 @@ pub struct FirstSegmentUnresolved {
 /// A name that will be used during item lookups.
 #[derive(Debug, Clone)]
 pub enum NameToImport {
-    /// Requires items with names that exactly match the given string, bool indicatse case-sensitivity.
+    /// Requires items with names that exactly match the given string, bool indicates case-sensitivity.
     Exact(String, bool),
     /// Requires items with names that case-insensitively contain all letters from the string,
     /// in the same order, but not necessary adjacent.