diff options
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 3b73208e6..bc1f91938 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, SourceFileNode, | 8 | AstNode, SyntaxNode, |
9 | ast::{self, NameOwner, ModuleItemOwner} | 9 | ast::{self, NameOwner, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, FileId, Cancelable,}; | 11 | use ra_db::{SourceRootId, Cancelable,}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId, | 14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, HirFileId, |
15 | macros::MacroCallLoc, | 15 | macros::MacroCallLoc, |
16 | db::HirDatabase, | 16 | db::HirDatabase, |
17 | function::FnScopes, | 17 | function::FnScopes, |
@@ -48,29 +48,17 @@ pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc< | |||
48 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) | 48 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) |
49 | } | 49 | } |
50 | 50 | ||
51 | pub(super) fn m_source_file(db: &impl HirDatabase, mfile_id: MFileId) -> SourceFileNode { | 51 | pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { |
52 | match mfile_id { | 52 | let source_file = db.hir_source_file(file_id); |
53 | MFileId::File(file_id) => db.source_file(file_id), | ||
54 | MFileId::Macro(m) => { | ||
55 | if let Some(exp) = db.expand_macro_invocation(m) { | ||
56 | return exp.file(); | ||
57 | } | ||
58 | SourceFileNode::parse("") | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | pub(super) fn file_items(db: &impl HirDatabase, mfile_id: MFileId) -> Arc<SourceFileItems> { | ||
64 | let source_file = db.m_source_file(mfile_id); | ||
65 | let source_file = source_file.borrowed(); | 53 | let source_file = source_file.borrowed(); |
66 | let res = SourceFileItems::new(mfile_id, source_file); | 54 | let res = SourceFileItems::new(file_id, source_file); |
67 | Arc::new(res) | 55 | Arc::new(res) |
68 | } | 56 | } |
69 | 57 | ||
70 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { | 58 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { |
71 | match source_item_id.item_id { | 59 | match source_item_id.item_id { |
72 | Some(id) => db.file_items(source_item_id.mfile_id)[id].clone(), | 60 | Some(id) => db.file_items(source_item_id.file_id)[id].clone(), |
73 | None => db.m_source_file(source_item_id.mfile_id).syntax().owned(), | 61 | None => db.hir_source_file(source_item_id.file_id).syntax().owned(), |
74 | } | 62 | } |
75 | } | 63 | } |
76 | 64 | ||
@@ -92,7 +80,7 @@ pub(crate) fn submodules( | |||
92 | 80 | ||
93 | fn collect_submodules<'a>( | 81 | fn collect_submodules<'a>( |
94 | db: &impl HirDatabase, | 82 | db: &impl HirDatabase, |
95 | file_id: FileId, | 83 | file_id: HirFileId, |
96 | root: impl ast::ModuleItemOwner<'a>, | 84 | root: impl ast::ModuleItemOwner<'a>, |
97 | ) -> Vec<Submodule> { | 85 | ) -> Vec<Submodule> { |
98 | modules(root) | 86 | modules(root) |
@@ -129,13 +117,13 @@ pub(super) fn input_module_items( | |||
129 | ) -> Cancelable<Arc<InputModuleItems>> { | 117 | ) -> Cancelable<Arc<InputModuleItems>> { |
130 | let module_tree = db.module_tree(source_root_id)?; | 118 | let module_tree = db.module_tree(source_root_id)?; |
131 | let source = module_id.source(&module_tree); | 119 | let source = module_id.source(&module_tree); |
132 | let mfile_id = source.file_id().into(); | 120 | let file_id = source.file_id(); |
133 | let file_items = db.file_items(mfile_id); | 121 | let file_items = db.file_items(file_id); |
134 | let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| { | 122 | let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| { |
135 | for item in items { | 123 | for item in items { |
136 | match item { | 124 | match item { |
137 | ast::ItemOrMacro::Item(it) => { | 125 | ast::ItemOrMacro::Item(it) => { |
138 | acc.add_item(mfile_id, &file_items, it); | 126 | acc.add_item(file_id, &file_items, it); |
139 | } | 127 | } |
140 | ast::ItemOrMacro::Macro(macro_call) => { | 128 | ast::ItemOrMacro::Macro(macro_call) => { |
141 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); | 129 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); |
@@ -143,16 +131,16 @@ pub(super) fn input_module_items( | |||
143 | source_root_id, | 131 | source_root_id, |
144 | module_id, | 132 | module_id, |
145 | source_item_id: SourceItemId { | 133 | source_item_id: SourceItemId { |
146 | mfile_id, | 134 | file_id, |
147 | item_id: Some(item_id), | 135 | item_id: Some(item_id), |
148 | }, | 136 | }, |
149 | }; | 137 | }; |
150 | let id = loc.id(db); | 138 | let id = loc.id(db); |
151 | let mfile_id = MFileId::Macro(id); | 139 | let file_id = HirFileId::from(id); |
152 | let file_items = db.file_items(mfile_id); | 140 | let file_items = db.file_items(file_id); |
153 | //FIXME: expand recursively | 141 | //FIXME: expand recursively |
154 | for item in db.m_source_file(mfile_id).borrowed().items() { | 142 | for item in db.hir_source_file(file_id).borrowed().items() { |
155 | acc.add_item(mfile_id, &file_items, item); | 143 | acc.add_item(file_id, &file_items, item); |
156 | } | 144 | } |
157 | } | 145 | } |
158 | } | 146 | } |