diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_impl.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs index 1f28fab74..0cea9f7b6 100644 --- a/crates/ra_hir/src/code_model_impl.rs +++ b/crates/ra_hir/src/code_model_impl.rs | |||
@@ -1,3 +1,18 @@ | |||
1 | mod krate; // `crate` is invalid ident :( | 1 | mod krate; // `crate` is invalid ident :( |
2 | mod module; | 2 | mod module; |
3 | pub(crate) mod function; | 3 | pub(crate) mod function; |
4 | |||
5 | use ra_syntax::{AstNode, TreeArc}; | ||
6 | |||
7 | use crate::{HirDatabase, DefId, HirFileId}; | ||
8 | |||
9 | pub(crate) fn def_id_to_ast<N: AstNode>( | ||
10 | db: &impl HirDatabase, | ||
11 | def_id: DefId, | ||
12 | ) -> (HirFileId, TreeArc<N>) { | ||
13 | let (file_id, syntax) = def_id.source(db); | ||
14 | let ast = N::cast(&syntax) | ||
15 | .unwrap_or_else(|| panic!("def points to wrong source {:?} {:?}", def_id, syntax)) | ||
16 | .to_owned(); | ||
17 | (file_id, ast) | ||
18 | } | ||