aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/query_definitions.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-01 17:59:00 +0000
committerAleksey Kladov <[email protected]>2019-01-01 19:15:35 +0000
commit289391e1635987d6a1ccbb9b40bce242590d461d (patch)
tree2567207cde92e5ef77a2378ef6726eaa548a0dea /crates/ra_hir/src/query_definitions.rs
parent4161466918baedaeef995040888471a65ca997a4 (diff)
use MFile
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r--crates/ra_hir/src/query_definitions.rs28
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
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use ra_syntax::{ 7use ra_syntax::{
8 AstNode, SyntaxNode, 8 AstNode, SyntaxNode, SourceFileNode,
9 ast::{self, NameOwner, ModuleItemOwner} 9 ast::{self, NameOwner, ModuleItemOwner}
10}; 10};
11use ra_db::{SourceRootId, FileId, Cancelable,}; 11use ra_db::{SourceRootId, FileId, Cancelable,};
12 12
13use crate::{ 13use 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
50pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { 50pub(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
62pub(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
57pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { 69pub(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();