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