From b28c54a2c239acd73f2eea80fda9ee3960d2c046 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:28:27 +0200 Subject: Rename ra_hir_def -> hir_def --- crates/hir_def/src/src.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 crates/hir_def/src/src.rs (limited to 'crates/hir_def/src/src.rs') diff --git a/crates/hir_def/src/src.rs b/crates/hir_def/src/src.rs new file mode 100644 index 000000000..7a79b0314 --- /dev/null +++ b/crates/hir_def/src/src.rs @@ -0,0 +1,43 @@ +//! Utilities for mapping between hir IDs and the surface syntax. + +use arena::map::ArenaMap; +use hir_expand::InFile; + +use crate::{db::DefDatabase, item_tree::ItemTreeNode, AssocItemLoc, ItemLoc}; + +pub trait HasSource { + type Value; + fn source(&self, db: &dyn DefDatabase) -> InFile; +} + +impl HasSource for AssocItemLoc { + type Value = N::Source; + + fn source(&self, db: &dyn DefDatabase) -> InFile { + let tree = db.item_tree(self.id.file_id); + let ast_id_map = db.ast_id_map(self.id.file_id); + let root = db.parse_or_expand(self.id.file_id).unwrap(); + let node = &tree[self.id.value]; + + InFile::new(self.id.file_id, ast_id_map.get(node.ast_id()).to_node(&root)) + } +} + +impl HasSource for ItemLoc { + type Value = N::Source; + + fn source(&self, db: &dyn DefDatabase) -> InFile { + let tree = db.item_tree(self.id.file_id); + let ast_id_map = db.ast_id_map(self.id.file_id); + let root = db.parse_or_expand(self.id.file_id).unwrap(); + let node = &tree[self.id.value]; + + InFile::new(self.id.file_id, ast_id_map.get(node.ast_id()).to_node(&root)) + } +} + +pub trait HasChildSource { + type ChildId; + type Value; + fn child_source(&self, db: &dyn DefDatabase) -> InFile>; +} -- cgit v1.2.3