1 //! Utilities for mapping between hir IDs and the surface syntax.
3 use hir_expand::InFile;
4 use ra_arena::map::ArenaMap;
8 db::DefDatabase, ConstLoc, EnumLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc,
9 TypeAliasLoc, UnionLoc,
14 fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
17 impl HasSource for FunctionLoc {
18 type Value = ast::FnDef;
20 fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
21 let node = self.ast_id.to_node(db);
22 InFile::new(self.ast_id.file_id, node)
26 impl HasSource for TypeAliasLoc {
27 type Value = ast::TypeAliasDef;
29 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
30 let node = self.ast_id.to_node(db);
31 InFile::new(self.ast_id.file_id, node)
35 impl HasSource for ConstLoc {
36 type Value = ast::ConstDef;
38 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
39 let node = self.ast_id.to_node(db);
40 InFile::new(self.ast_id.file_id, node)
44 impl HasSource for StaticLoc {
45 type Value = ast::StaticDef;
47 fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
48 let node = self.ast_id.to_node(db);
49 InFile::new(self.ast_id.file_id, node)
53 impl HasSource for ImplLoc {
54 type Value = ast::ImplBlock;
56 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
57 let node = self.ast_id.to_node(db);
58 InFile::new(self.ast_id.file_id, node)
62 impl HasSource for TraitLoc {
63 type Value = ast::TraitDef;
65 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
66 let node = self.ast_id.to_node(db);
67 InFile::new(self.ast_id.file_id, node)
71 impl HasSource for StructLoc {
72 type Value = ast::StructDef;
74 fn source(&self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
75 let node = self.ast_id.to_node(db);
76 InFile::new(self.ast_id.file_id, node)
80 impl HasSource for UnionLoc {
81 type Value = ast::UnionDef;
83 fn source(&self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
84 let node = self.ast_id.to_node(db);
85 InFile::new(self.ast_id.file_id, node)
89 impl HasSource for EnumLoc {
90 type Value = ast::EnumDef;
92 fn source(&self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
93 let node = self.ast_id.to_node(db);
94 InFile::new(self.ast_id.file_id, node)
98 pub trait HasChildSource {
101 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;