diff options
Diffstat (limited to 'crates/ra_hir/src/module')
-rw-r--r-- | crates/ra_hir/src/module/imp.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/module/nameres.rs | 31 |
2 files changed, 20 insertions, 17 deletions
diff --git a/crates/ra_hir/src/module/imp.rs b/crates/ra_hir/src/module/imp.rs index eded85a63..d1498a646 100644 --- a/crates/ra_hir/src/module/imp.rs +++ b/crates/ra_hir/src/module/imp.rs | |||
@@ -64,7 +64,7 @@ fn create_module_tree<'a>( | |||
64 | 64 | ||
65 | let source_root = db.source_root(source_root); | 65 | let source_root = db.source_root(source_root); |
66 | for &file_id in source_root.files.values() { | 66 | for &file_id in source_root.files.values() { |
67 | let source = ModuleSource::new_file(file_id); | 67 | let source = ModuleSource::new_file(file_id.into()); |
68 | if visited.contains(&source) { | 68 | if visited.contains(&source) { |
69 | continue; // TODO: use explicit crate_roots here | 69 | continue; // TODO: use explicit crate_roots here |
70 | } | 70 | } |
@@ -123,7 +123,7 @@ fn build_subtree( | |||
123 | visited, | 123 | visited, |
124 | roots, | 124 | roots, |
125 | Some(link), | 125 | Some(link), |
126 | ModuleSource::new_file(file_id), | 126 | ModuleSource::new_file(file_id.into()), |
127 | ), | 127 | ), |
128 | }) | 128 | }) |
129 | .collect::<Cancelable<Vec<_>>>()?; | 129 | .collect::<Cancelable<Vec<_>>>()?; |
@@ -155,7 +155,7 @@ fn resolve_submodule( | |||
155 | name: &Name, | 155 | name: &Name, |
156 | ) -> (Vec<FileId>, Option<Problem>) { | 156 | ) -> (Vec<FileId>, Option<Problem>) { |
157 | // FIXME: handle submodules of inline modules properly | 157 | // FIXME: handle submodules of inline modules properly |
158 | let file_id = source.file_id(); | 158 | let file_id = source.file_id().original_file_id(db); |
159 | let source_root_id = db.file_source_root(file_id); | 159 | let source_root_id = db.file_source_root(file_id); |
160 | let path = db.file_relative_path(file_id); | 160 | let path = db.file_relative_path(file_id); |
161 | let root = RelativePathBuf::default(); | 161 | let root = RelativePathBuf::default(); |
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index 27a76a293..cc60ba077 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs | |||
@@ -25,7 +25,7 @@ use ra_syntax::{ | |||
25 | use ra_db::SourceRootId; | 25 | use ra_db::SourceRootId; |
26 | 26 | ||
27 | use crate::{ | 27 | use crate::{ |
28 | Cancelable, MFileId, FileId, | 28 | Cancelable, HirFileId, FileId, |
29 | DefId, DefLoc, DefKind, | 29 | DefId, DefLoc, DefKind, |
30 | SourceItemId, SourceFileItemId, SourceFileItems, | 30 | SourceItemId, SourceFileItemId, SourceFileItems, |
31 | Path, PathKind, | 31 | Path, PathKind, |
@@ -95,9 +95,11 @@ pub struct NamedImport { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | impl NamedImport { | 97 | impl NamedImport { |
98 | // FIXME: this is only here for one use-case in completion. Seems like a | ||
99 | // pretty gross special case. | ||
98 | pub fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange { | 100 | pub fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange { |
99 | let source_item_id = SourceItemId { | 101 | let source_item_id = SourceItemId { |
100 | mfile_id: file_id.into(), | 102 | file_id: file_id.into(), |
101 | item_id: Some(self.file_item_id), | 103 | item_id: Some(self.file_item_id), |
102 | }; | 104 | }; |
103 | let syntax = db.file_item(source_item_id); | 105 | let syntax = db.file_item(source_item_id); |
@@ -211,25 +213,25 @@ impl<T> PerNs<T> { | |||
211 | impl InputModuleItems { | 213 | impl InputModuleItems { |
212 | pub(crate) fn add_item( | 214 | pub(crate) fn add_item( |
213 | &mut self, | 215 | &mut self, |
214 | mfile_id: MFileId, | 216 | file_id: HirFileId, |
215 | file_items: &SourceFileItems, | 217 | file_items: &SourceFileItems, |
216 | item: ast::ModuleItem, | 218 | item: ast::ModuleItem, |
217 | ) -> Option<()> { | 219 | ) -> Option<()> { |
218 | match item { | 220 | match item { |
219 | ast::ModuleItem::StructDef(it) => { | 221 | ast::ModuleItem::StructDef(it) => { |
220 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 222 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
221 | } | 223 | } |
222 | ast::ModuleItem::EnumDef(it) => { | 224 | ast::ModuleItem::EnumDef(it) => { |
223 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 225 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
224 | } | 226 | } |
225 | ast::ModuleItem::FnDef(it) => { | 227 | ast::ModuleItem::FnDef(it) => { |
226 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 228 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
227 | } | 229 | } |
228 | ast::ModuleItem::TraitDef(it) => { | 230 | ast::ModuleItem::TraitDef(it) => { |
229 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 231 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
230 | } | 232 | } |
231 | ast::ModuleItem::TypeDef(it) => { | 233 | ast::ModuleItem::TypeDef(it) => { |
232 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 234 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
233 | } | 235 | } |
234 | ast::ModuleItem::ImplItem(_) => { | 236 | ast::ModuleItem::ImplItem(_) => { |
235 | // impls don't define items | 237 | // impls don't define items |
@@ -239,13 +241,13 @@ impl InputModuleItems { | |||
239 | // TODO | 241 | // TODO |
240 | } | 242 | } |
241 | ast::ModuleItem::ConstDef(it) => { | 243 | ast::ModuleItem::ConstDef(it) => { |
242 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 244 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
243 | } | 245 | } |
244 | ast::ModuleItem::StaticDef(it) => { | 246 | ast::ModuleItem::StaticDef(it) => { |
245 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 247 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
246 | } | 248 | } |
247 | ast::ModuleItem::Module(it) => { | 249 | ast::ModuleItem::Module(it) => { |
248 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 250 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
249 | } | 251 | } |
250 | } | 252 | } |
251 | Some(()) | 253 | Some(()) |
@@ -269,7 +271,7 @@ impl InputModuleItems { | |||
269 | 271 | ||
270 | impl ModuleItem { | 272 | impl ModuleItem { |
271 | fn new<'a>( | 273 | fn new<'a>( |
272 | mfile_id: MFileId, | 274 | file_id: HirFileId, |
273 | file_items: &SourceFileItems, | 275 | file_items: &SourceFileItems, |
274 | item: impl ast::NameOwner<'a>, | 276 | item: impl ast::NameOwner<'a>, |
275 | ) -> Option<ModuleItem> { | 277 | ) -> Option<ModuleItem> { |
@@ -277,7 +279,7 @@ impl ModuleItem { | |||
277 | let kind = item.syntax().kind(); | 279 | let kind = item.syntax().kind(); |
278 | let vis = Vis::Other; | 280 | let vis = Vis::Other; |
279 | let item_id = Some(file_items.id_of_unchecked(item.syntax())); | 281 | let item_id = Some(file_items.id_of_unchecked(item.syntax())); |
280 | let id = SourceItemId { mfile_id, item_id }; | 282 | let id = SourceItemId { file_id, item_id }; |
281 | let res = ModuleItem { | 283 | let res = ModuleItem { |
282 | id, | 284 | id, |
283 | name, | 285 | name, |
@@ -339,7 +341,8 @@ where | |||
339 | let root_id = module_id.crate_root(&self.module_tree); | 341 | let root_id = module_id.crate_root(&self.module_tree); |
340 | let file_id = root_id.source(&self.module_tree).file_id(); | 342 | let file_id = root_id.source(&self.module_tree).file_id(); |
341 | let crate_graph = self.db.crate_graph(); | 343 | let crate_graph = self.db.crate_graph(); |
342 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id) { | 344 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file()) |
345 | { | ||
343 | let krate = Crate::new(crate_id); | 346 | let krate = Crate::new(crate_id); |
344 | for dep in krate.dependencies(self.db) { | 347 | for dep in krate.dependencies(self.db) { |
345 | if let Some(module) = dep.krate.root_module(self.db)? { | 348 | if let Some(module) = dep.krate.root_module(self.db)? { |