From 0404e647e69f758ac84c742b06dddefb01cc4ad6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Nov 2019 00:40:54 +0300 Subject: Prepare SourceAnalyzer for macros --- crates/ra_hir_expand/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 6c2cc3af3..26531cb05 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -223,6 +223,7 @@ impl AstId { } } +/// FIXME: https://github.com/matklad/with ? #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub struct Source { pub file_id: HirFileId, @@ -236,11 +237,16 @@ impl Source { Source { file_id, ast } } + // Similarly, naming here is stupid... + pub fn with_ast(&self, ast: U) -> Source { + Source::new(self.file_id, ast) + } + pub fn map U, U>(self, f: F) -> Source { - Source { file_id: self.file_id, ast: f(self.ast) } + Source::new(self.file_id, f(self.ast)) } pub fn as_ref(&self) -> Source<&T> { - Source { file_id: self.file_id, ast: &self.ast } + self.with_ast(&self.ast) } pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { db.parse_or_expand(self.file_id).expect("source created from invalid file") -- cgit v1.2.3