aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model/src.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model/src.rs')
-rw-r--r--crates/ra_hir/src/code_model/src.rs37
1 files changed, 9 insertions, 28 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index b9d21bdd7..a4e317c20 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -2,12 +2,11 @@
2 2
3use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId}; 3use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId};
4use hir_expand::either::Either; 4use hir_expand::either::Either;
5use ra_syntax::ast::{self, AstNode}; 5use ra_syntax::ast;
6 6
7use crate::{ 7use crate::{
8 db::{DefDatabase, HirDatabase}, 8 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef,
9 Const, Enum, EnumVariant, FieldSource, Function, HasBody, Import, MacroDef, Module, 9 Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
10 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
11}; 10};
12 11
13pub use hir_expand::Source; 12pub use hir_expand::Source;
@@ -109,6 +108,12 @@ impl HasSource for MacroDef {
109 Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } 108 Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) }
110 } 109 }
111} 110}
111impl HasSource for ImplBlock {
112 type Ast = ast::ImplBlock;
113 fn source(self, db: &impl DefDatabase) -> Source<ast::ImplBlock> {
114 self.id.source(db)
115 }
116}
112impl HasSource for Import { 117impl HasSource for Import {
113 type Ast = Either<ast::UseTree, ast::ExternCrateItem>; 118 type Ast = Either<ast::UseTree, ast::ExternCrateItem>;
114 119
@@ -121,27 +126,3 @@ impl HasSource for Import {
121 src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root))) 126 src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root)))
122 } 127 }
123} 128}
124
125pub trait HasBodySource: HasBody + HasSource
126where
127 Self::Ast: AstNode,
128{
129 fn expr_source(
130 self,
131 db: &impl HirDatabase,
132 expr_id: crate::expr::ExprId,
133 ) -> Option<Source<Either<ast::Expr, ast::RecordField>>> {
134 let source_map = self.body_source_map(db);
135 let source_ptr = source_map.expr_syntax(expr_id)?;
136 let root = source_ptr.file_syntax(db);
137 let source = source_ptr.map(|ast| ast.map(|it| it.to_node(&root), |it| it.to_node(&root)));
138 Some(source)
139 }
140}
141
142impl<T> HasBodySource for T
143where
144 T: HasBody + HasSource,
145 T::Ast: AstNode,
146{
147}