diff options
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index f66231222..0c07f1444 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -5,13 +5,13 @@ use std::{ | |||
5 | 5 | ||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | AstNode, SyntaxNode, | 8 | AstNode, SyntaxNode, SourceFileNode, |
9 | ast::{self, NameOwner, ModuleItemOwner} | 9 | ast::{self, NameOwner, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, FileId, Cancelable,}; | 11 | use ra_db::{SourceRootId, FileId, Cancelable,}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, | 14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId, |
15 | db::HirDatabase, | 15 | db::HirDatabase, |
16 | function::FnScopes, | 16 | function::FnScopes, |
17 | module::{ | 17 | module::{ |
@@ -47,17 +47,29 @@ pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc< | |||
47 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) | 47 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) |
48 | } | 48 | } |
49 | 49 | ||
50 | pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { | 50 | pub(super) fn m_source_file(db: &impl HirDatabase, mfile_id: MFileId) -> SourceFileNode { |
51 | let source_file = db.source_file(file_id); | 51 | match mfile_id { |
52 | MFileId::File(file_id) => db.source_file(file_id), | ||
53 | MFileId::Macro(m) => { | ||
54 | if let Some(exp) = db.expand_macro_invocation(m) { | ||
55 | return exp.file(); | ||
56 | } | ||
57 | SourceFileNode::parse("") | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | pub(super) fn file_items(db: &impl HirDatabase, mfile_id: MFileId) -> Arc<SourceFileItems> { | ||
63 | let source_file = db.m_source_file(mfile_id); | ||
52 | let source_file = source_file.borrowed(); | 64 | let source_file = source_file.borrowed(); |
53 | let res = SourceFileItems::new(file_id, source_file); | 65 | let res = SourceFileItems::new(mfile_id, source_file); |
54 | Arc::new(res) | 66 | Arc::new(res) |
55 | } | 67 | } |
56 | 68 | ||
57 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { | 69 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { |
58 | match source_item_id.item_id { | 70 | match source_item_id.item_id { |
59 | Some(id) => db.file_items(source_item_id.file_id)[id].clone(), | 71 | Some(id) => db.file_items(source_item_id.mfile_id)[id].clone(), |
60 | None => db.source_file(source_item_id.file_id).syntax().owned(), | 72 | None => db.m_source_file(source_item_id.mfile_id).syntax().owned(), |
61 | } | 73 | } |
62 | } | 74 | } |
63 | 75 | ||
@@ -116,7 +128,7 @@ pub(super) fn input_module_items( | |||
116 | ) -> Cancelable<Arc<InputModuleItems>> { | 128 | ) -> Cancelable<Arc<InputModuleItems>> { |
117 | let module_tree = db.module_tree(source_root)?; | 129 | let module_tree = db.module_tree(source_root)?; |
118 | let source = module_id.source(&module_tree); | 130 | let source = module_id.source(&module_tree); |
119 | let file_items = db.file_items(source.file_id()); | 131 | let file_items = db.file_items(source.file_id().into()); |
120 | let res = match source.resolve(db) { | 132 | let res = match source.resolve(db) { |
121 | ModuleSourceNode::SourceFile(it) => { | 133 | ModuleSourceNode::SourceFile(it) => { |
122 | let items = it.borrowed().items(); | 134 | let items = it.borrowed().items(); |