diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 8ee6f54cd..552cbe544 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -12,7 +12,7 @@ use hir_expand::{ | |||
12 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 12 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
13 | use ra_syntax::{ | 13 | use ra_syntax::{ |
14 | ast::{self, AttrsOwner, NameOwner}, | 14 | ast::{self, AttrsOwner, NameOwner}, |
15 | AstNode, AstPtr, SourceFile, | 15 | AstNode, AstPtr, |
16 | }; | 16 | }; |
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
18 | 18 | ||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | attr::{Attr, Attrs}, | 20 | attr::{Attr, Attrs}, |
21 | db::DefDatabase, | 21 | db::DefDatabase, |
22 | path::Path, | 22 | path::Path, |
23 | FileAstId, HirFileId, LocalImportId, ModuleSource, Source, | 23 | FileAstId, HirFileId, LocalImportId, Source, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | /// `RawItems` is a set of top-level items in a file (except for impls). | 26 | /// `RawItems` is a set of top-level items in a file (except for impls). |
@@ -44,24 +44,14 @@ pub struct ImportSourceMap { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | 46 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
47 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; | ||
48 | |||
49 | fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource { | ||
50 | ptr.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) | ||
51 | } | ||
52 | 47 | ||
53 | impl ImportSourceMap { | 48 | impl ImportSourceMap { |
54 | fn insert(&mut self, import: LocalImportId, ptr: ImportSourcePtr) { | 49 | fn insert(&mut self, import: LocalImportId, ptr: ImportSourcePtr) { |
55 | self.map.insert(import, ptr) | 50 | self.map.insert(import, ptr) |
56 | } | 51 | } |
57 | 52 | ||
58 | pub fn get(&self, source: &ModuleSource, import: LocalImportId) -> ImportSource { | 53 | pub fn get(&self, import: LocalImportId) -> ImportSourcePtr { |
59 | let file = match source { | 54 | self.map[import].clone() |
60 | ModuleSource::SourceFile(file) => file.clone(), | ||
61 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), | ||
62 | }; | ||
63 | |||
64 | to_node(self.map[import], &file) | ||
65 | } | 55 | } |
66 | } | 56 | } |
67 | 57 | ||