diff options
Diffstat (limited to 'crates/ra_hir/src/code_model')
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 37 |
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 | ||
3 | use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId}; | 3 | use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId}; |
4 | use hir_expand::either::Either; | 4 | use hir_expand::either::Either; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::ast; |
6 | 6 | ||
7 | use crate::{ | 7 | use 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 | ||
13 | pub use hir_expand::Source; | 12 | pub 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 | } |
111 | impl 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 | } | ||
112 | impl HasSource for Import { | 117 | impl 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 | |||
125 | pub trait HasBodySource: HasBody + HasSource | ||
126 | where | ||
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 | |||
142 | impl<T> HasBodySource for T | ||
143 | where | ||
144 | T: HasBody + HasSource, | ||
145 | T::Ast: AstNode, | ||
146 | { | ||
147 | } | ||