aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl.rs
blob: 0cea9f7b6ff767ef48684c1c1a3309d0c3cd5380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
}