diff options
Diffstat (limited to 'crates/ra_analysis/src/hir/module')
-rw-r--r-- | crates/ra_analysis/src/hir/module/mod.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/hir/module/mod.rs b/crates/ra_analysis/src/hir/module/mod.rs index 4213bc39f..a6b7a5466 100644 --- a/crates/ra_analysis/src/hir/module/mod.rs +++ b/crates/ra_analysis/src/hir/module/mod.rs | |||
@@ -13,8 +13,8 @@ use ra_syntax::{ | |||
13 | use relative_path::RelativePathBuf; | 13 | use relative_path::RelativePathBuf; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | db::SyntaxDatabase, syntax_ptr::SyntaxPtr, FileId, FilePosition, Cancelable, | 16 | FileId, FilePosition, Cancelable, |
17 | hir::{Path, PathKind, HirDatabase}, | 17 | hir::{Path, PathKind, HirDatabase, SourceItemId}, |
18 | input::SourceRootId, | 18 | input::SourceRootId, |
19 | arena::{Arena, Id}, | 19 | arena::{Arena, Id}, |
20 | loc2id::{DefLoc, DefId}, | 20 | loc2id::{DefLoc, DefId}, |
@@ -52,7 +52,7 @@ impl Module { | |||
52 | let file = db.file_syntax(position.file_id); | 52 | let file = db.file_syntax(position.file_id); |
53 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) | 53 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) |
54 | { | 54 | { |
55 | Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), | 55 | Some(m) if !m.has_semi() => ModuleSource::new_inline(db, position.file_id, m), |
56 | _ => ModuleSource::SourceFile(position.file_id), | 56 | _ => ModuleSource::SourceFile(position.file_id), |
57 | }; | 57 | }; |
58 | Module::guess_from_source(db, position.file_id, module_source) | 58 | Module::guess_from_source(db, position.file_id, module_source) |
@@ -218,7 +218,7 @@ impl ModuleTree { | |||
218 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 218 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
219 | pub(crate) enum ModuleSource { | 219 | pub(crate) enum ModuleSource { |
220 | SourceFile(FileId), | 220 | SourceFile(FileId), |
221 | Module(SyntaxPtr), | 221 | Module(SourceItemId), |
222 | } | 222 | } |
223 | 223 | ||
224 | /// An owned syntax node for a module. Unlike `ModuleSource`, | 224 | /// An owned syntax node for a module. Unlike `ModuleSource`, |
@@ -273,7 +273,7 @@ impl ModuleId { | |||
273 | Some((link.name.clone(), module)) | 273 | Some((link.name.clone(), module)) |
274 | }) | 274 | }) |
275 | } | 275 | } |
276 | fn problems(self, tree: &ModuleTree, db: &impl SyntaxDatabase) -> Vec<(SyntaxNode, Problem)> { | 276 | fn problems(self, tree: &ModuleTree, db: &impl HirDatabase) -> Vec<(SyntaxNode, Problem)> { |
277 | tree.mods[self] | 277 | tree.mods[self] |
278 | .children | 278 | .children |
279 | .iter() | 279 | .iter() |
@@ -294,7 +294,7 @@ impl LinkId { | |||
294 | fn name(self, tree: &ModuleTree) -> SmolStr { | 294 | fn name(self, tree: &ModuleTree) -> SmolStr { |
295 | tree.links[self].name.clone() | 295 | tree.links[self].name.clone() |
296 | } | 296 | } |
297 | fn bind_source<'a>(self, tree: &ModuleTree, db: &impl SyntaxDatabase) -> ast::ModuleNode { | 297 | fn bind_source<'a>(self, tree: &ModuleTree, db: &impl HirDatabase) -> ast::ModuleNode { |
298 | let owner = self.owner(tree); | 298 | let owner = self.owner(tree); |
299 | match owner.source(tree).resolve(db) { | 299 | match owner.source(tree).resolve(db) { |
300 | ModuleSourceNode::SourceFile(root) => { | 300 | ModuleSourceNode::SourceFile(root) => { |
@@ -317,10 +317,16 @@ pub(crate) struct ModuleData { | |||
317 | } | 317 | } |
318 | 318 | ||
319 | impl ModuleSource { | 319 | impl ModuleSource { |
320 | pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource { | 320 | pub(crate) fn new_inline( |
321 | db: &impl HirDatabase, | ||
322 | file_id: FileId, | ||
323 | module: ast::Module, | ||
324 | ) -> ModuleSource { | ||
321 | assert!(!module.has_semi()); | 325 | assert!(!module.has_semi()); |
322 | let ptr = SyntaxPtr::new(file_id, module.syntax()); | 326 | let items = db.file_items(file_id); |
323 | ModuleSource::Module(ptr) | 327 | let item_id = items.id_of(module.syntax()); |
328 | let id = SourceItemId { file_id, item_id }; | ||
329 | ModuleSource::Module(id) | ||
324 | } | 330 | } |
325 | 331 | ||
326 | pub(crate) fn as_file(self) -> Option<FileId> { | 332 | pub(crate) fn as_file(self) -> Option<FileId> { |
@@ -333,18 +339,18 @@ impl ModuleSource { | |||
333 | pub(crate) fn file_id(self) -> FileId { | 339 | pub(crate) fn file_id(self) -> FileId { |
334 | match self { | 340 | match self { |
335 | ModuleSource::SourceFile(f) => f, | 341 | ModuleSource::SourceFile(f) => f, |
336 | ModuleSource::Module(ptr) => ptr.file_id(), | 342 | ModuleSource::Module(source_item_id) => source_item_id.file_id, |
337 | } | 343 | } |
338 | } | 344 | } |
339 | 345 | ||
340 | pub(crate) fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode { | 346 | pub(crate) fn resolve(self, db: &impl HirDatabase) -> ModuleSourceNode { |
341 | match self { | 347 | match self { |
342 | ModuleSource::SourceFile(file_id) => { | 348 | ModuleSource::SourceFile(file_id) => { |
343 | let syntax = db.file_syntax(file_id); | 349 | let syntax = db.file_syntax(file_id); |
344 | ModuleSourceNode::SourceFile(syntax.ast().owned()) | 350 | ModuleSourceNode::SourceFile(syntax.ast().owned()) |
345 | } | 351 | } |
346 | ModuleSource::Module(ptr) => { | 352 | ModuleSource::Module(item_id) => { |
347 | let syntax = db.resolve_syntax_ptr(ptr); | 353 | let syntax = db.file_item(item_id); |
348 | let syntax = syntax.borrowed(); | 354 | let syntax = syntax.borrowed(); |
349 | let module = ast::Module::cast(syntax).unwrap(); | 355 | let module = ast::Module::cast(syntax).unwrap(); |
350 | ModuleSourceNode::Module(module.owned()) | 356 | ModuleSourceNode::Module(module.owned()) |