From 7370a6b5b84d6378eb6808430635e881c2369b8a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 21 Mar 2022 19:41:39 +0100 Subject: [PATCH] fix: Fix flyimport showing functions in pattern position --- .../src/completions/flyimport.rs | 19 +++++++++++-------- crates/ide_completion/src/tests/flyimport.rs | 11 +++++++---- crates/ide_db/src/imports/import_assets.rs | 2 +- 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 6c8878a7bb..ee751f9f77 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 c996a5f01f..4a0fcf3442 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 9a09c40ee6..3963d4d79a 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.