diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs index fa8c0eb77a..1c62347fb5 100644 --- a/crates/ide-completion/src/completions/flyimport.rs +++ b/crates/ide-completion/src/completions/flyimport.rs @@ -5,7 +5,10 @@ use ide_db::imports::{ insert_use::ImportScope, }; use itertools::Itertools; -use syntax::{ast, AstNode, SyntaxNode, T}; +use syntax::{ + ast::{self}, + AstNode, SyntaxNode, T, +}; use crate::{ context::{ @@ -123,6 +126,7 @@ pub(crate) fn import_on_the_fly_path( | PathKind::Type { .. } | PathKind::Attr { .. } | PathKind::Derive { .. } + | PathKind::Item { .. } | PathKind::Pat { .. }, qualified, .. @@ -161,7 +165,7 @@ pub(crate) fn import_on_the_fly_pat( let potential_import_name = import_name(ctx); let import_assets = import_assets_for_path(ctx, &potential_import_name, None)?; - import_on_the_fly_pat2( + import_on_the_fly_pat_( acc, ctx, pattern_ctx, @@ -227,7 +231,7 @@ fn import_on_the_fly( | PathKind::Pat { .. }, ItemInNs::Macros(mac), ) => mac.is_fn_like(ctx.db), - (PathKind::Item { .. }, _) => true, + (PathKind::Item { .. }, ..) => false, (PathKind::Expr { .. }, ItemInNs::Types(_) | ItemInNs::Values(_)) => true, @@ -279,7 +283,7 @@ fn import_on_the_fly( Some(()) } -fn import_on_the_fly_pat2( +fn import_on_the_fly_pat_( acc: &mut Completions, ctx: &CompletionContext, pattern_ctx: &PatternContext, diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs index c393e16e7a..0bba7f2459 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -1210,3 +1210,23 @@ fn f() where T: Comp$0 "#]], ); } + +#[test] +fn flyimport_source_file() { + check( + r#" +//- /main.rs crate:main deps:dep +def$0 +//- /lib.rs crate:dep +#[macro_export] +macro_rules! define_struct { + () => { + pub struct Foo; + }; +} +"#, + expect![[r#" + ma define_struct!(…) (use dep::define_struct) macro_rules! define_struct + "#]], + ); +}