diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2022-07-02 16:15:13 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2022-07-02 16:20:26 +0200 |
| commit | cd42b20ce36adc8c2beda8d8e86a91b479cd182f (patch) | |
| tree | f31243850369ebb913ce5d82addbeda4ca5a2209 | |
| parent | ed44fe52e4a730e4f892cde094fbba8ae8621589 (diff) | |
| download | rust-cd42b20ce36adc8c2beda8d8e86a91b479cd182f.tar.gz rust-cd42b20ce36adc8c2beda8d8e86a91b479cd182f.zip | |
fix: Trigger flyimport completions in item lists again
| -rw-r--r-- | crates/ide-completion/src/completions/flyimport.rs | 12 | ||||
| -rw-r--r-- | crates/ide-completion/src/tests/flyimport.rs | 20 |
2 files changed, 28 insertions, 4 deletions
diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs index fa8c0eb77ac..1c62347fb5b 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 c393e16e7a5..0bba7f2459c 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -1210,3 +1210,23 @@ fn f<T>() 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 + "#]], + ); +} |
