@@ -4,6 +4,8 @@ mod analysis;
4
4
#[ cfg( test) ]
5
5
mod tests;
6
6
7
+ use std:: iter;
8
+
7
9
use base_db:: SourceDatabaseExt ;
8
10
use hir:: {
9
11
HasAttrs , Local , Name , PathResolution , ScopeDef , Semantics , SemanticsScope , Type , TypeInfo ,
@@ -174,8 +176,17 @@ pub(super) enum Qualified {
174
176
With {
175
177
path : ast:: Path ,
176
178
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 > ,
179
190
} ,
180
191
/// <_>::
181
192
Infer ,
@@ -343,6 +354,12 @@ pub(crate) struct CompletionContext<'a> {
343
354
pub ( super ) qualifier_ctx : QualifierCtx ,
344
355
345
356
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 ,
346
363
}
347
364
348
365
impl < ' a > CompletionContext < ' a > {
@@ -521,6 +538,8 @@ impl<'a> CompletionContext<'a> {
521
538
}
522
539
} ) ;
523
540
541
+ let depth_from_crate_root = iter:: successors ( module. parent ( db) , |m| m. parent ( db) ) . count ( ) ;
542
+
524
543
let mut ctx = CompletionContext {
525
544
sema,
526
545
scope,
@@ -535,6 +554,7 @@ impl<'a> CompletionContext<'a> {
535
554
expected_type : None ,
536
555
qualifier_ctx : Default :: default ( ) ,
537
556
locals,
557
+ depth_from_crate_root,
538
558
} ;
539
559
let ident_ctx = ctx. expand_and_analyze (
540
560
original_file. syntax ( ) . clone ( ) ,
0 commit comments