@@ -8,8 +8,10 @@ use itertools::Itertools;
88use syntax:: { AstNode , SyntaxNode , T } ;
99
1010use crate :: {
11- context:: { CompletionContext , NameRefContext , PathCompletionCtx , PathKind , PatternContext } ,
12- patterns:: ImmediateLocation ,
11+ context:: {
12+ CompletionContext , NameRefContext , NameRefKind , PathCompletionCtx , PathKind ,
13+ PatternContext , TypeLocation ,
14+ } ,
1315 render:: { render_resolution_with_import, RenderContext } ,
1416} ;
1517
@@ -111,19 +113,20 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
111113 return None ;
112114 }
113115 let path_kind = match ctx. nameref_ctx ( ) {
114- Some ( NameRefContext { path_ctx : Some ( PathCompletionCtx { kind, .. } ) , .. } )
115- if matches ! (
116- kind,
117- PathKind :: Expr { .. }
118- | PathKind :: Type { .. }
119- | PathKind :: Attr { .. }
120- | PathKind :: Derive
121- | PathKind :: Pat
122- ) =>
123- {
124- Some ( kind)
125- }
126- Some ( NameRefContext { dot_access : Some ( _) , .. } ) => None ,
116+ Some ( NameRefContext {
117+ kind :
118+ Some ( NameRefKind :: Path ( PathCompletionCtx {
119+ kind :
120+ kind @ ( PathKind :: Expr { .. }
121+ | PathKind :: Type { .. }
122+ | PathKind :: Attr { .. }
123+ | PathKind :: Derive
124+ | PathKind :: Pat ) ,
125+ ..
126+ } ) ) ,
127+ ..
128+ } ) => Some ( kind) ,
129+ Some ( NameRefContext { kind : Some ( NameRefKind :: DotAccess ( _) ) , .. } ) => None ,
127130 None if matches ! ( ctx. pattern_ctx, Some ( PatternContext { record_pat: None , .. } ) ) => {
128131 Some ( & PathKind :: Pat )
129132 }
@@ -173,8 +176,8 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
173176 ( PathKind :: Pat , ItemInNs :: Types ( _) ) => true ,
174177 ( PathKind :: Pat , ItemInNs :: Values ( def) ) => matches ! ( def, hir:: ModuleDef :: Const ( _) ) ,
175178
176- ( PathKind :: Type { .. } , ItemInNs :: Types ( ty) ) => {
177- if matches ! ( ctx . completion_location , Some ( ImmediateLocation :: TypeBound ) ) {
179+ ( PathKind :: Type { location } , ItemInNs :: Types ( ty) ) => {
180+ if matches ! ( location , TypeLocation :: TypeBound ) {
178181 matches ! ( ty, ModuleDef :: Trait ( _) )
179182 } else {
180183 true
0 commit comments