aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-01 16:51:11 +0000
committerAleksey Kladov <[email protected]>2019-01-01 19:15:35 +0000
commit7dc45745a378c6feb6af524e8bd40e89bab7a822 (patch)
tree1d223d721a0fb94f5d024dfee52503275f203537
parente5b2fd67711eeab6146021542937028dff3bf8a7 (diff)
save top-level macros in module items
-rw-r--r--crates/ra_hir/src/lib.rs20
-rw-r--r--crates/ra_hir/src/query_definitions.rs10
-rw-r--r--crates/ra_syntax/src/lib.rs2
3 files changed, 18 insertions, 14 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 4422ac45b..2f9684e33 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -33,7 +33,7 @@ mod ty;
33 33
34use std::ops::Index; 34use std::ops::Index;
35 35
36use ra_syntax::{SyntaxNodeRef, SyntaxNode, SyntaxKind}; 36use ra_syntax::{SyntaxNodeRef, SyntaxNode, SyntaxKind, SourceFile, AstNode, ast};
37use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable}; 37use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable};
38 38
39use crate::{ 39use crate::{
@@ -169,11 +169,23 @@ pub struct SourceFileItems {
169} 169}
170 170
171impl SourceFileItems { 171impl SourceFileItems {
172 fn new(file_id: FileId) -> SourceFileItems { 172 fn new(file_id: FileId, source_file: SourceFile) -> SourceFileItems {
173 SourceFileItems { 173 let mut res = SourceFileItems {
174 file_id, 174 file_id,
175 arena: Arena::default(), 175 arena: Arena::default(),
176 } 176 };
177 res.init(source_file);
178 res
179 }
180
181 fn init(&mut self, source_file: SourceFile) {
182 source_file.syntax().descendants().for_each(|it| {
183 if let Some(module_item) = ast::ModuleItem::cast(it) {
184 self.alloc(module_item.syntax().owned());
185 } else if let Some(macro_call) = ast::MacroCall::cast(it) {
186 self.alloc(macro_call.syntax().owned());
187 }
188 });
177 } 189 }
178 190
179 fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { 191 fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId {
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 721bd4195..f66231222 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -48,17 +48,9 @@ pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<
48} 48}
49 49
50pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { 50pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> {
51 let mut res = SourceFileItems::new(file_id);
52 let source_file = db.source_file(file_id); 51 let source_file = db.source_file(file_id);
53 let source_file = source_file.borrowed(); 52 let source_file = source_file.borrowed();
54 source_file 53 let res = SourceFileItems::new(file_id, source_file);
55 .syntax()
56 .descendants()
57 .filter_map(ast::ModuleItem::cast)
58 .map(|it| it.syntax().owned())
59 .for_each(|it| {
60 res.alloc(it);
61 });
62 Arc::new(res) 54 Arc::new(res)
63} 55}
64 56
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 34a3aabef..6753c513f 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -51,7 +51,7 @@ use ra_text_edit::AtomTextEdit;
51use crate::yellow::GreenNode; 51use crate::yellow::GreenNode;
52 52
53/// `SourceFileNode` represents a parse tree for a single Rust file. 53/// `SourceFileNode` represents a parse tree for a single Rust file.
54pub use crate::ast::SourceFileNode; 54pub use crate::ast::{SourceFile, SourceFileNode};
55 55
56impl SourceFileNode { 56impl SourceFileNode {
57 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { 57 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode {