From bd8af6a413bb2f762bb696d20727e21cb2d4cb62 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Nov 2019 00:05:10 +0300 Subject: Sourcify some more --- crates/ra_hir_expand/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) (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 437d73e94..6c2cc3af3 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -226,6 +226,8 @@ impl AstId { #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub struct Source { pub file_id: HirFileId, + // FIXME: this stores all kind of things, not only `ast`. + // There should be a better name... pub ast: T, } -- cgit v1.2.3 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