maybe this is better??

This commit is contained in:
Jake Heinz 2021-11-17 07:00:24 +00:00
parent 4fbc4b9356
commit 312eafe916
4 changed files with 30 additions and 18 deletions

View file

@ -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());