@@ -4,6 +4,8 @@ mod analysis;
44#[ cfg( test) ]
55mod tests;
66
7+ use std:: iter;
8+
79use base_db:: SourceDatabaseExt ;
810use hir:: {
911 HasAttrs , Local , Name , PathResolution , ScopeDef , Semantics , SemanticsScope , Type , TypeInfo ,
@@ -174,8 +176,17 @@ pub(super) enum Qualified {
174176 With {
175177 path : ast:: Path ,
176178 resolution : Option < PathResolution > ,
177- /// Whether this path consists solely of `super` segments
178- is_super_chain : bool ,
179+ /// How many `super` segments are present in the path
180+ ///
181+ /// This would be None, if path is not solely made of
182+ /// `super` segments, e.g.
183+ ///
184+ /// ```rust
185+ /// use super::foo;
186+ /// ```
187+ ///
188+ /// Otherwise it should be Some(count of `super`)
189+ super_chain_len : Option < usize > ,
179190 } ,
180191 /// <_>::
181192 Infer ,
@@ -343,6 +354,12 @@ pub(crate) struct CompletionContext<'a> {
343354 pub ( super ) qualifier_ctx : QualifierCtx ,
344355
345356 pub ( super ) locals : FxHashMap < Name , Local > ,
357+
358+ /// - crate-root
359+ /// - mod foo
360+ /// - mod bar
361+ /// Here depth will be 2: {[bar<->foo], [foo<->crate-root]}
362+ pub ( super ) depth_from_crate_root : usize ,
346363}
347364
348365impl < ' a > CompletionContext < ' a > {
@@ -521,6 +538,8 @@ impl<'a> CompletionContext<'a> {
521538 }
522539 } ) ;
523540
541+ let depth_from_crate_root = iter:: successors ( module. parent ( db) , |m| m. parent ( db) ) . count ( ) ;
542+
524543 let mut ctx = CompletionContext {
525544 sema,
526545 scope,
@@ -535,6 +554,7 @@ impl<'a> CompletionContext<'a> {
535554 expected_type : None ,
536555 qualifier_ctx : Default :: default ( ) ,
537556 locals,
557+ depth_from_crate_root,
538558 } ;
539559 let ident_ctx = ctx. expand_and_analyze (
540560 original_file. syntax ( ) . clone ( ) ,
0 commit comments