aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/db.rs1
-rw-r--r--crates/ra_hir/src/query_definitions.rs48
-rw-r--r--crates/ra_syntax/src/ast.rs30
3 files changed, 67 insertions, 12 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 86c15f4ee..adfec56d8 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -91,6 +91,7 @@ salsa::database_storage! {
91 fn library_symbols() for symbol_index::LibrarySymbolsQuery; 91 fn library_symbols() for symbol_index::LibrarySymbolsQuery;
92 } 92 }
93 impl hir::db::HirDatabase { 93 impl hir::db::HirDatabase {
94 fn m_source_file() for hir::db::MSourceFileQuery;
94 fn expand_macro_invocation() for hir::db::ExpandMacroCallQuery; 95 fn expand_macro_invocation() for hir::db::ExpandMacroCallQuery;
95 fn module_tree() for hir::db::ModuleTreeQuery; 96 fn module_tree() for hir::db::ModuleTreeQuery;
96 fn fn_scopes() for hir::db::FnScopesQuery; 97 fn fn_scopes() for hir::db::FnScopesQuery;
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 3c90e29fe..3b73208e6 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -12,6 +12,7 @@ use ra_db::{SourceRootId, FileId, Cancelable,};
12 12
13use crate::{ 13use crate::{
14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId, 14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId,
15 macros::MacroCallLoc,
15 db::HirDatabase, 16 db::HirDatabase,
16 function::FnScopes, 17 function::FnScopes,
17 module::{ 18 module::{
@@ -123,25 +124,48 @@ pub(crate) fn modules<'a>(
123 124
124pub(super) fn input_module_items( 125pub(super) fn input_module_items(
125 db: &impl HirDatabase, 126 db: &impl HirDatabase,
126 source_root: SourceRootId, 127 source_root_id: SourceRootId,
127 module_id: ModuleId, 128 module_id: ModuleId,
128) -> Cancelable<Arc<InputModuleItems>> { 129) -> Cancelable<Arc<InputModuleItems>> {
129 let module_tree = db.module_tree(source_root)?; 130 let module_tree = db.module_tree(source_root_id)?;
130 let source = module_id.source(&module_tree); 131 let source = module_id.source(&module_tree);
131 let mfile_id = source.file_id().into(); 132 let mfile_id = source.file_id().into();
132 let file_items = db.file_items(mfile_id); 133 let file_items = db.file_items(mfile_id);
133 let res = match source.resolve(db) { 134 let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| {
134 ModuleSourceNode::SourceFile(it) => { 135 for item in items {
135 let items = it.borrowed().items(); 136 match item {
136 InputModuleItems::new(mfile_id, &file_items, items) 137 ast::ItemOrMacro::Item(it) => {
138 acc.add_item(mfile_id, &file_items, it);
139 }
140 ast::ItemOrMacro::Macro(macro_call) => {
141 let item_id = file_items.id_of_unchecked(macro_call.syntax());
142 let loc = MacroCallLoc {
143 source_root_id,
144 module_id,
145 source_item_id: SourceItemId {
146 mfile_id,
147 item_id: Some(item_id),
148 },
149 };
150 let id = loc.id(db);
151 let mfile_id = MFileId::Macro(id);
152 let file_items = db.file_items(mfile_id);
153 //FIXME: expand recursively
154 for item in db.m_source_file(mfile_id).borrowed().items() {
155 acc.add_item(mfile_id, &file_items, item);
156 }
157 }
158 }
137 } 159 }
160 };
161
162 let mut res = InputModuleItems::default();
163 match source.resolve(db) {
164 ModuleSourceNode::SourceFile(it) => fill(&mut res, &mut it.borrowed().items_with_macros()),
138 ModuleSourceNode::Module(it) => { 165 ModuleSourceNode::Module(it) => {
139 let items = it 166 if let Some(item_list) = it.borrowed().item_list() {
140 .borrowed() 167 fill(&mut res, &mut item_list.items_with_macros())
141 .item_list() 168 }
142 .into_iter()
143 .flat_map(|it| it.items());
144 InputModuleItems::new(mfile_id, &file_items, items)
145 } 169 }
146 }; 170 };
147 Ok(Arc::new(res)) 171 Ok(Arc::new(res))
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 8fb6b6408..3e948800e 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -48,10 +48,40 @@ pub trait FnDefOwner<'a>: AstNode<'a> {
48 } 48 }
49} 49}
50 50
51// ModuleItem
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53pub enum ItemOrMacro<'a> {
54 Item(ModuleItem<'a>),
55 Macro(MacroCall<'a>),
56}
57
58impl<'a> AstNode<'a> for ItemOrMacro<'a> {
59 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
60 let res = if let Some(item) = ModuleItem::cast(syntax) {
61 ItemOrMacro::Item(item)
62 } else if let Some(macro_call) = MacroCall::cast(syntax) {
63 ItemOrMacro::Macro(macro_call)
64 } else {
65 return None;
66 };
67 Some(res)
68 }
69 fn syntax(self) -> SyntaxNodeRef<'a> {
70 match self {
71 ItemOrMacro::Item(it) => it.syntax(),
72 ItemOrMacro::Macro(it) => it.syntax(),
73 }
74 }
75}
76
51pub trait ModuleItemOwner<'a>: AstNode<'a> { 77pub trait ModuleItemOwner<'a>: AstNode<'a> {
52 fn items(self) -> AstChildren<'a, ModuleItem<'a>> { 78 fn items(self) -> AstChildren<'a, ModuleItem<'a>> {
53 children(self) 79 children(self)
54 } 80 }
81
82 fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> {
83 children(self)
84 }
55} 85}
56 86
57pub trait TypeParamsOwner<'a>: AstNode<'a> { 87pub trait TypeParamsOwner<'a>: AstNode<'a> {