Auto merge of #12678 - Veykril:flyimport, r=Veykril

fix: Trigger flyimport completions in item lists again

Fixes https://github.com/rust-lang/rust-analyzer/issues/12656
This commit is contained in:
bors 2022-07-02 14:20:36 +00:00
commit d4b79ad77b
2 changed files with 28 additions and 4 deletions

View file

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

View file

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