diff options
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 5a0e5a19c..dd07a16b4 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -9,11 +9,15 @@ pub mod ast_id_map; | |||
9 | pub mod either; | 9 | pub mod either; |
10 | pub mod name; | 10 | pub mod name; |
11 | pub mod hygiene; | 11 | pub mod hygiene; |
12 | pub mod diagnostics; | ||
12 | 13 | ||
13 | use std::hash::{Hash, Hasher}; | 14 | use std::hash::{Hash, Hasher}; |
14 | 15 | ||
15 | use ra_db::{salsa, CrateId, FileId}; | 16 | use ra_db::{salsa, CrateId, FileId}; |
16 | use ra_syntax::ast::{self, AstNode}; | 17 | use ra_syntax::{ |
18 | ast::{self, AstNode}, | ||
19 | SyntaxNode, | ||
20 | }; | ||
17 | 21 | ||
18 | use crate::ast_id_map::FileAstId; | 22 | use crate::ast_id_map::FileAstId; |
19 | 23 | ||
@@ -151,3 +155,18 @@ impl<N: AstNode> AstId<N> { | |||
151 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) | 155 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) |
152 | } | 156 | } |
153 | } | 157 | } |
158 | |||
159 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
160 | pub struct Source<T> { | ||
161 | pub file_id: HirFileId, | ||
162 | pub ast: T, | ||
163 | } | ||
164 | |||
165 | impl<T> Source<T> { | ||
166 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { | ||
167 | Source { file_id: self.file_id, ast: f(self.ast) } | ||
168 | } | ||
169 | pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { | ||
170 | db.parse_or_expand(self.file_id).expect("source created from invalid file") | ||
171 | } | ||
172 | } | ||