Move Source to hir_expand

This commit is contained in:
Aleksey Kladov 2019-11-02 23:11:05 +03:00
parent 2d142a17ef
commit b8533413cf
4 changed files with 23 additions and 20 deletions

View file

@ -13,7 +13,10 @@ pub mod hygiene;
use std::hash::{Hash, Hasher};
use ra_db::{salsa, CrateId, FileId};
use ra_syntax::ast::{self, AstNode};
use ra_syntax::{
ast::{self, AstNode},
SyntaxNode,
};
use crate::ast_id_map::FileAstId;
@ -151,3 +154,18 @@ impl<N: AstNode> AstId<N> {
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Source<T> {
pub file_id: HirFileId,
pub ast: T,
}
impl<T> Source<T> {
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
Source { file_id: self.file_id, ast: f(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")
}
}