diff options
Diffstat (limited to 'crates/ra_hir/src/lib.rs')
-rw-r--r-- | crates/ra_hir/src/lib.rs | 20 |
1 files changed, 16 insertions, 4 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 | ||
34 | use std::ops::Index; | 34 | use std::ops::Index; |
35 | 35 | ||
36 | use ra_syntax::{SyntaxNodeRef, SyntaxNode, SyntaxKind}; | 36 | use ra_syntax::{SyntaxNodeRef, SyntaxNode, SyntaxKind, SourceFile, AstNode, ast}; |
37 | use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable}; | 37 | use ra_db::{LocationIntener, SourceRootId, FileId, Cancelable}; |
38 | 38 | ||
39 | use crate::{ | 39 | use crate::{ |
@@ -169,11 +169,23 @@ pub struct SourceFileItems { | |||
169 | } | 169 | } |
170 | 170 | ||
171 | impl SourceFileItems { | 171 | impl 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 { |