diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-15 21:57:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-15 21:57:48 +0000 |
commit | d843455de2d619bf4f2577bd004044fa88c56533 (patch) | |
tree | c0fb90f2bfa0cec5eb62e80bfe5cf7c009a3fc18 /crates/ra_hir_expand/src | |
parent | 920848940ae7b79b1655ac48a9e2c1694b9e06c8 (diff) | |
parent | 0404e647e69f758ac84c742b06dddefb01cc4ad6 (diff) |
Merge #2269
2269: Prepare SourceAnalyzer for macros r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 12 |
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)] |
227 | pub struct Source<T> { | 228 | pub 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") |