Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_completion/src/completions/flyimport.rs')
| -rw-r--r-- | crates/ide_completion/src/completions/flyimport.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 446a808de8..3a9c1b3beb 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -110,7 +110,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) if !ctx.config.enable_imports_on_the_fly { return None; } - if ctx.in_use_tree() + if matches!(ctx.path_kind(), Some(PathKind::Vis { .. } | PathKind::Use)) || ctx.is_path_disallowed() || ctx.expects_item() || ctx.expects_assoc_item() @@ -118,6 +118,11 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) { return None; } + // FIXME: This should be encoded in a different way + if ctx.pattern_ctx.is_none() && ctx.path_context.is_none() && !ctx.has_dot_receiver() { + // completion inside `ast::Name` of a item declaration + return None; + } let potential_import_name = { let token_kind = ctx.token.kind(); if matches!(token_kind, T![.] | T![::]) { @@ -147,14 +152,25 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) } }; match (kind, import.original_item) { + // Aren't handled in flyimport + (PathKind::Vis { .. } | PathKind::Use, _) => false, + // modules are always fair game + (_, ItemInNs::Types(hir::ModuleDef::Module(_))) => true, + // and so are macros(except for attributes) + ( + PathKind::Expr | PathKind::Type | PathKind::Mac | PathKind::Pat, + ItemInNs::Macros(mac), + ) => mac.is_fn_like(), + (PathKind::Mac, _) => true, + (PathKind::Expr, ItemInNs::Types(_) | ItemInNs::Values(_)) => true, + (PathKind::Pat, ItemInNs::Types(_)) => true, + (PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)), + (PathKind::Type, ItemInNs::Types(_)) => true, (PathKind::Type, ItemInNs::Values(_)) => false, - (PathKind::Expr | PathKind::Type, ItemInNs::Macros(mac)) => mac.is_fn_like(), - - (PathKind::Attr, ItemInNs::Types(hir::ModuleDef::Module(_))) => true, (PathKind::Attr, ItemInNs::Macros(mac)) => mac.is_attr(), (PathKind::Attr, _) => false, } |