aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/src.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/src.rs')
-rw-r--r--crates/ra_hir_def/src/src.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
new file mode 100644
index 000000000..27caa02cc
--- /dev/null
+++ b/crates/ra_hir_def/src/src.rs
@@ -0,0 +1,54 @@
1//! Utilities for mapping between hir IDs and the surface syntax.
2
3use hir_expand::InFile;
4use ra_arena::map::ArenaMap;
5use ra_syntax::ast;
6
7use crate::{db::DefDatabase, ConstLoc, FunctionLoc, StaticLoc, TypeAliasLoc};
8
9pub trait HasSource {
10 type Value;
11 fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
12}
13
14impl HasSource for FunctionLoc {
15 type Value = ast::FnDef;
16
17 fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
18 let node = self.ast_id.to_node(db);
19 InFile::new(self.ast_id.file_id, node)
20 }
21}
22
23impl HasSource for TypeAliasLoc {
24 type Value = ast::TypeAliasDef;
25
26 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
27 let node = self.ast_id.to_node(db);
28 InFile::new(self.ast_id.file_id, node)
29 }
30}
31
32impl HasSource for ConstLoc {
33 type Value = ast::ConstDef;
34
35 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
36 let node = self.ast_id.to_node(db);
37 InFile::new(self.ast_id.file_id, node)
38 }
39}
40
41impl HasSource for StaticLoc {
42 type Value = ast::StaticDef;
43
44 fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
45 let node = self.ast_id.to_node(db);
46 InFile::new(self.ast_id.file_id, node)
47 }
48}
49
50pub trait HasChildSource {
51 type ChildId;
52 type Value;
53 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
54}