fix: Fix flyimport showing functions in pattern position

This commit is contained in:
Lukas Wirth 2022-03-21 19:41:39 +01:00
parent 6a0b199c82
commit 7370a6b5b8
3 changed files with 19 additions and 13 deletions

View file

@ -141,15 +141,18 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
&ctx.sema, &ctx.sema,
)?; )?;
let ns_filter = |import: &LocatedImport| {
let path_kind = match ctx.path_kind() { let path_kind = match ctx.path_kind() {
Some(kind) => kind, Some(kind) => Some(kind),
None => { None if ctx.pattern_ctx.is_some() => Some(PathKind::Pat),
return match import.original_item { None => None,
ItemInNs::Macros(mac) => mac.is_fn_like(ctx.db), };
_ => true, let ns_filter = |import: &LocatedImport| {
} 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) { match (path_kind, import.original_item) {
// Aren't handled in flyimport // Aren't handled in flyimport

View file

@ -1030,14 +1030,17 @@ fn flyimport_pattern() {
check( check(
r#" r#"
mod module { mod module {
pub struct Struct; pub struct FooStruct {}
pub const FooConst: () = ();
pub fn foo_fun() {}
} }
fn function() { fn function() {
let Str$0 let foo$0
} }
"#, "#,
expect![[r#" expect![[r#"
st Struct (use module::Struct) ct FooConst (use module::FooConst)
st FooStruct (use module::FooStruct)
"#]], "#]],
); );
} }

View file

@ -66,7 +66,7 @@ pub struct FirstSegmentUnresolved {
/// A name that will be used during item lookups. /// A name that will be used during item lookups.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum NameToImport { 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), Exact(String, bool),
/// Requires items with names that case-insensitively contain all letters from the string, /// Requires items with names that case-insensitively contain all letters from the string,
/// in the same order, but not necessary adjacent. /// in the same order, but not necessary adjacent.