aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/src.rs
blob: 46e90da7009194dd1a92c4306c0616a7e7ff081d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Utilities for mapping between hir IDs and the surface syntax.

use hir_expand::InFile;
use ra_arena::map::ArenaMap;
use ra_syntax::AstNode;

use crate::{db::DefDatabase, AssocItemLoc, ItemLoc};

pub trait HasSource {
    type Value;
    fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>;
}

impl<N: AstNode> HasSource for AssocItemLoc<N> {
    type Value = N;

    fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
        let node = self.ast_id.to_node(db.upcast());
        InFile::new(self.ast_id.file_id, node)
    }
}

impl<N: AstNode> HasSource for ItemLoc<N> {
    type Value = N;

    fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
        let node = self.ast_id.to_node(db.upcast());
        InFile::new(self.ast_id.file_id, node)
    }
}

pub trait HasChildSource {
    type ChildId;
    type Value;
    fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
}