aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/lib.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 437d73e94..26531cb05 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -223,9 +223,12 @@ impl<N: AstNode> AstId<N> {
223 } 223 }
224} 224}
225 225
226/// FIXME: https://github.com/matklad/with ?
226#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] 227#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
227pub struct Source<T> { 228pub struct Source<T> {
228 pub file_id: HirFileId, 229 pub file_id: HirFileId,
230 // FIXME: this stores all kind of things, not only `ast`.
231 // There should be a better name...
229 pub ast: T, 232 pub ast: T,
230} 233}
231 234
@@ -234,11 +237,16 @@ impl<T> Source<T> {
234 Source { file_id, ast } 237 Source { file_id, ast }
235 } 238 }
236 239
240 // Similarly, naming here is stupid...
241 pub fn with_ast<U>(&self, ast: U) -> Source<U> {
242 Source::new(self.file_id, ast)
243 }
244
237 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { 245 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
238 Source { file_id: self.file_id, ast: f(self.ast) } 246 Source::new(self.file_id, f(self.ast))
239 } 247 }
240 pub fn as_ref(&self) -> Source<&T> { 248 pub fn as_ref(&self) -> Source<&T> {
241 Source { file_id: self.file_id, ast: &self.ast } 249 self.with_ast(&self.ast)
242 } 250 }
243 pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { 251 pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode {
244 db.parse_or_expand(self.file_id).expect("source created from invalid file") 252 db.parse_or_expand(self.file_id).expect("source created from invalid file")