uncopypaste def sources

This commit is contained in:
Aleksey Kladov
2019-01-11 20:43:10 +03:00
parent 0f9c350812
commit 19136cde00
3 changed files with 26 additions and 40 deletions

View File

@@ -1,3 +1,18 @@
mod krate; // `crate` is invalid ident :(
mod module;
pub(crate) mod function;
use ra_syntax::{AstNode, TreeArc};
use crate::{HirDatabase, DefId, HirFileId};
pub(crate) fn def_id_to_ast<N: AstNode>(
db: &impl HirDatabase,
def_id: DefId,
) -> (HirFileId, TreeArc<N>) {
let (file_id, syntax) = def_id.source(db);
let ast = N::cast(&syntax)
.unwrap_or_else(|| panic!("def points to wrong source {:?} {:?}", def_id, syntax))
.to_owned();
(file_id, ast)
}