aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/crate_def_map
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres/crate_def_map')
-rw-r--r--crates/ra_hir/src/nameres/crate_def_map/collector.rs9
-rw-r--r--crates/ra_hir/src/nameres/crate_def_map/raw.rs16
2 files changed, 23 insertions, 2 deletions
diff --git a/crates/ra_hir/src/nameres/crate_def_map/collector.rs b/crates/ra_hir/src/nameres/crate_def_map/collector.rs
index 8b727e2c9..0f500ce42 100644
--- a/crates/ra_hir/src/nameres/crate_def_map/collector.rs
+++ b/crates/ra_hir/src/nameres/crate_def_map/collector.rs
@@ -224,7 +224,7 @@ where
224 } 224 }
225 } 225 }
226 let resolution = Resolution { def, import: Some(import_id) }; 226 let resolution = Resolution { def, import: Some(import_id) };
227 self.update(module_id, None, &[(name, resolution)]); 227 self.update(module_id, Some(import_id), &[(name, resolution)]);
228 } 228 }
229 } 229 }
230 230
@@ -262,6 +262,13 @@ where
262 existing.import = import.or(res.import); 262 existing.import = import.or(res.import);
263 changed = true; 263 changed = true;
264 } 264 }
265 if existing.def.is_none()
266 && res.def.is_none()
267 && existing.import.is_none()
268 && res.import.is_some()
269 {
270 existing.import = res.import;
271 }
265 } 272 }
266 if !changed { 273 if !changed {
267 return; 274 return;
diff --git a/crates/ra_hir/src/nameres/crate_def_map/raw.rs b/crates/ra_hir/src/nameres/crate_def_map/raw.rs
index f064f722c..dca86e394 100644
--- a/crates/ra_hir/src/nameres/crate_def_map/raw.rs
+++ b/crates/ra_hir/src/nameres/crate_def_map/raw.rs
@@ -14,6 +14,7 @@ use ra_syntax::{
14use crate::{ 14use crate::{
15 PersistentHirDatabase, Name, AsName, Path, HirFileId, 15 PersistentHirDatabase, Name, AsName, Path, HirFileId,
16 ids::{SourceFileItemId, SourceFileItems}, 16 ids::{SourceFileItemId, SourceFileItems},
17 nameres::lower::ImportSourceMap,
17}; 18};
18 19
19#[derive(Debug, Default, PartialEq, Eq)] 20#[derive(Debug, Default, PartialEq, Eq)]
@@ -31,13 +32,21 @@ impl RawItems {
31 db: &impl PersistentHirDatabase, 32 db: &impl PersistentHirDatabase,
32 file_id: FileId, 33 file_id: FileId,
33 ) -> Arc<RawItems> { 34 ) -> Arc<RawItems> {
35 db.raw_items_with_source_map(file_id).0
36 }
37
38 pub(crate) fn raw_items_with_source_map_query(
39 db: &impl PersistentHirDatabase,
40 file_id: FileId,
41 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
34 let mut collector = RawItemsCollector { 42 let mut collector = RawItemsCollector {
35 raw_items: RawItems::default(), 43 raw_items: RawItems::default(),
36 source_file_items: db.file_items(file_id.into()), 44 source_file_items: db.file_items(file_id.into()),
45 source_map: ImportSourceMap::default(),
37 }; 46 };
38 let source_file = db.parse(file_id); 47 let source_file = db.parse(file_id);
39 collector.process_module(None, &*source_file); 48 collector.process_module(None, &*source_file);
40 Arc::new(collector.raw_items) 49 (Arc::new(collector.raw_items), Arc::new(collector.source_map))
41 } 50 }
42 51
43 pub(crate) fn items(&self) -> &[RawItem] { 52 pub(crate) fn items(&self) -> &[RawItem] {
@@ -51,6 +60,7 @@ impl RawItems {
51 let mut collector = RawItemsCollector { 60 let mut collector = RawItemsCollector {
52 raw_items: RawItems::default(), 61 raw_items: RawItems::default(),
53 source_file_items: Arc::new(source_file_items), 62 source_file_items: Arc::new(source_file_items),
63 source_map: ImportSourceMap::default(),
54 }; 64 };
55 collector.process_module(None, &*source_file); 65 collector.process_module(None, &*source_file);
56 collector.raw_items 66 collector.raw_items
@@ -144,6 +154,7 @@ pub(crate) struct MacroData {
144struct RawItemsCollector { 154struct RawItemsCollector {
145 raw_items: RawItems, 155 raw_items: RawItems,
146 source_file_items: Arc<SourceFileItems>, 156 source_file_items: Arc<SourceFileItems>,
157 source_map: ImportSourceMap,
147} 158}
148 159
149impl RawItemsCollector { 160impl RawItemsCollector {
@@ -227,6 +238,9 @@ impl RawItemsCollector {
227 is_prelude, 238 is_prelude,
228 is_extern_crate: false, 239 is_extern_crate: false,
229 }); 240 });
241 if let Some(segment) = segment {
242 self.source_map.insert(import, segment)
243 }
230 self.push_item(current_module, RawItem::Import(import)) 244 self.push_item(current_module, RawItem::Import(import))
231 }) 245 })
232 } 246 }