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,
)?;
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

View File

@ -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)
"#]],
);
}

View File

@ -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.