Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d61e02d

Browse files
bors[bot]Veykril
andauthored
11782: fix: Fix flyimport showing functions in pattern position r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 6a0b199 + 7370a6b commit d61e02d

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,18 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
141141
&ctx.sema,
142142
)?;
143143

144+
let path_kind = match ctx.path_kind() {
145+
Some(kind) => Some(kind),
146+
None if ctx.pattern_ctx.is_some() => Some(PathKind::Pat),
147+
None => None,
148+
};
144149
let ns_filter = |import: &LocatedImport| {
145-
let path_kind = match ctx.path_kind() {
146-
Some(kind) => kind,
147-
None => {
148-
return match import.original_item {
149-
ItemInNs::Macros(mac) => mac.is_fn_like(ctx.db),
150-
_ => true,
151-
}
152-
}
150+
let path_kind = match path_kind {
151+
Some(path_kind) => path_kind,
152+
None => match import.original_item {
153+
ItemInNs::Macros(mac) => return mac.is_fn_like(ctx.db),
154+
_ => return true,
155+
},
153156
};
154157
match (path_kind, import.original_item) {
155158
// Aren't handled in flyimport

crates/ide_completion/src/tests/flyimport.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,15 +1030,18 @@ fn flyimport_pattern() {
10301030
check(
10311031
r#"
10321032
mod module {
1033-
pub struct Struct;
1033+
pub struct FooStruct {}
1034+
pub const FooConst: () = ();
1035+
pub fn foo_fun() {}
10341036
}
10351037
fn function() {
1036-
let Str$0
1038+
let foo$0
10371039
}
10381040
"#,
10391041
expect![[r#"
1040-
st Struct (use module::Struct)
1041-
"#]],
1042+
ct FooConst (use module::FooConst)
1043+
st FooStruct (use module::FooStruct)
1044+
"#]],
10421045
);
10431046
}
10441047

crates/ide_db/src/imports/import_assets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct FirstSegmentUnresolved {
6666
/// A name that will be used during item lookups.
6767
#[derive(Debug, Clone)]
6868
pub enum NameToImport {
69-
/// Requires items with names that exactly match the given string, bool indicatse case-sensitivity.
69+
/// Requires items with names that exactly match the given string, bool indicates case-sensitivity.
7070
Exact(String, bool),
7171
/// Requires items with names that case-insensitively contain all letters from the string,
7272
/// in the same order, but not necessary adjacent.

0 commit comments

Comments
 (0)