Unnamed repository; edit this file 'description' to name the repository.
Merge #11782
11782: fix: Fix flyimport showing functions in pattern position r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
bors[bot] 2022-03-22
parent 6a0b199 · parent 7370a6b · commit d61e02d
-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 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.