@@ -11,6 +11,10 @@ use hir_expand::name::Name;
11
11
12
12
const MAX_PATH_LEN : usize = 15 ;
13
13
14
+ // FIXME: handle local items
15
+
16
+ /// Find a path that can be used to refer to a certain item. This can depend on
17
+ /// *from where* you're referring to the item, hence the `from` parameter.
14
18
pub fn find_path ( db : & impl DefDatabase , item : ItemInNs , from : ModuleId ) -> Option < ModPath > {
15
19
find_path_inner ( db, item, from, MAX_PATH_LEN )
16
20
}
@@ -44,6 +48,11 @@ fn find_path_inner(
44
48
return Some ( ModPath :: from_simple_segments ( PathKind :: Crate , Vec :: new ( ) ) ) ;
45
49
}
46
50
51
+ // - if the item is the module we're in, use `self`
52
+ if item == ItemInNs :: Types ( from. into ( ) ) {
53
+ return Some ( ModPath :: from_simple_segments ( PathKind :: Super ( 0 ) , Vec :: new ( ) ) ) ;
54
+ }
55
+
47
56
// - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
48
57
if let Some ( parent_id) = def_map. modules [ from. local_id ] . parent {
49
58
if item
@@ -271,6 +280,17 @@ mod tests {
271
280
check_found_path ( code, "super::S" ) ;
272
281
}
273
282
283
+ #[ test]
284
+ fn self_module ( ) {
285
+ let code = r#"
286
+ //- /main.rs
287
+ mod foo;
288
+ //- /foo.rs
289
+ <|>
290
+ "# ;
291
+ check_found_path ( code, "self" ) ;
292
+ }
293
+
274
294
#[ test]
275
295
fn crate_root ( ) {
276
296
let code = r#"
0 commit comments