diff options
Diffstat (limited to 'crates/ra_hir_def/src/src.rs')
-rw-r--r-- | crates/ra_hir_def/src/src.rs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs index 46e90da70..043b93fad 100644 --- a/crates/ra_hir_def/src/src.rs +++ b/crates/ra_hir_def/src/src.rs | |||
@@ -2,30 +2,37 @@ | |||
2 | 2 | ||
3 | use hir_expand::InFile; | 3 | use hir_expand::InFile; |
4 | use ra_arena::map::ArenaMap; | 4 | use ra_arena::map::ArenaMap; |
5 | use ra_syntax::AstNode; | ||
6 | 5 | ||
7 | use crate::{db::DefDatabase, AssocItemLoc, ItemLoc}; | 6 | use crate::{db::DefDatabase, item_tree::ItemTreeNode, AssocItemLoc, ItemLoc}; |
8 | 7 | ||
9 | pub trait HasSource { | 8 | pub trait HasSource { |
10 | type Value; | 9 | type Value; |
11 | fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>; | 10 | fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>; |
12 | } | 11 | } |
13 | 12 | ||
14 | impl<N: AstNode> HasSource for AssocItemLoc<N> { | 13 | impl<N: ItemTreeNode> HasSource for AssocItemLoc<N> { |
15 | type Value = N; | 14 | type Value = N::Source; |
16 | 15 | ||
17 | fn source(&self, db: &dyn DefDatabase) -> InFile<N> { | 16 | fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { |
18 | let node = self.ast_id.to_node(db.upcast()); | 17 | let tree = db.item_tree(self.id.file_id); |
19 | InFile::new(self.ast_id.file_id, node) | 18 | let ast_id_map = db.ast_id_map(self.id.file_id); |
19 | let root = db.parse_or_expand(self.id.file_id).unwrap(); | ||
20 | let node = &tree[self.id.value]; | ||
21 | |||
22 | InFile::new(self.id.file_id, ast_id_map.get(node.ast_id()).to_node(&root)) | ||
20 | } | 23 | } |
21 | } | 24 | } |
22 | 25 | ||
23 | impl<N: AstNode> HasSource for ItemLoc<N> { | 26 | impl<N: ItemTreeNode> HasSource for ItemLoc<N> { |
24 | type Value = N; | 27 | type Value = N::Source; |
28 | |||
29 | fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { | ||
30 | let tree = db.item_tree(self.id.file_id); | ||
31 | let ast_id_map = db.ast_id_map(self.id.file_id); | ||
32 | let root = db.parse_or_expand(self.id.file_id).unwrap(); | ||
33 | let node = &tree[self.id.value]; | ||
25 | 34 | ||
26 | fn source(&self, db: &dyn DefDatabase) -> InFile<N> { | 35 | InFile::new(self.id.file_id, ast_id_map.get(node.ast_id()).to_node(&root)) |
27 | let node = self.ast_id.to_node(db.upcast()); | ||
28 | InFile::new(self.ast_id.file_id, node) | ||
29 | } | 36 | } |
30 | } | 37 | } |
31 | 38 | ||