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.rs37
1 files changed, 20 insertions, 17 deletions
diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs
index 901f7519d2..6266bcef34 100644
--- a/crates/ide-completion/src/completions/flyimport.rs
+++ b/crates/ide-completion/src/completions/flyimport.rs
@@ -8,8 +8,10 @@ use itertools::Itertools;
use syntax::{AstNode, SyntaxNode, T};
use crate::{
- context::{CompletionContext, NameRefContext, PathCompletionCtx, PathKind, PatternContext},
- patterns::ImmediateLocation,
+ context::{
+ CompletionContext, NameRefContext, NameRefKind, PathCompletionCtx, PathKind,
+ PatternContext, TypeLocation,
+ },
render::{render_resolution_with_import, RenderContext},
};
@@ -111,19 +113,20 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
return None;
}
let path_kind = match ctx.nameref_ctx() {
- Some(NameRefContext { path_ctx: Some(PathCompletionCtx { kind, .. }), .. })
- if matches!(
- kind,
- PathKind::Expr { .. }
- | PathKind::Type { .. }
- | PathKind::Attr { .. }
- | PathKind::Derive
- | PathKind::Pat
- ) =>
- {
- Some(kind)
- }
- Some(NameRefContext { dot_access: Some(_), .. }) => None,
+ Some(NameRefContext {
+ kind:
+ Some(NameRefKind::Path(PathCompletionCtx {
+ kind:
+ kind @ (PathKind::Expr { .. }
+ | PathKind::Type { .. }
+ | PathKind::Attr { .. }
+ | PathKind::Derive
+ | PathKind::Pat),
+ ..
+ })),
+ ..
+ }) => Some(kind),
+ Some(NameRefContext { kind: Some(NameRefKind::DotAccess(_)), .. }) => None,
None if matches!(ctx.pattern_ctx, Some(PatternContext { record_pat: None, .. })) => {
Some(&PathKind::Pat)
}
@@ -173,8 +176,8 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
(PathKind::Pat, ItemInNs::Types(_)) => true,
(PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
- (PathKind::Type { .. }, ItemInNs::Types(ty)) => {
- if matches!(ctx.completion_location, Some(ImmediateLocation::TypeBound)) {
+ (PathKind::Type { location }, ItemInNs::Types(ty)) => {
+ if matches!(location, TypeLocation::TypeBound) {
matches!(ty, ModuleDef::Trait(_))
} else {
true