Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/lib.rs')
| -rw-r--r-- | crates/hir/src/lib.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d59c26438b..ee7270f295 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1457,6 +1457,17 @@ impl Const { db.const_data(self.id).name.clone() } + pub fn value(self, db: &dyn HirDatabase) -> Option<ast::Expr> { + let loc = self.id.lookup(db.upcast()); + let item_tree = loc.id.item_tree(db.upcast()); + let ast_id = item_tree[loc.id.value].ast_id; + let ast_id_map = db.ast_id_map(loc.id.file_id()); + let ast_ptr = ast_id_map.get(ast_id); + let syntax_node = db.parse_or_expand(loc.id.file_id())?; + let ast_node = ast_ptr.to_node(&syntax_node); + ast_node.body() + } + pub fn ty(self, db: &dyn HirDatabase) -> Type { let data = db.const_data(self.id); let resolver = self.id.resolver(db.upcast()); |