aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/body.rs')
-rw-r--r--crates/ra_hir_def/src/body.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index c3e9d0c23..85dc4feb0 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -17,7 +17,7 @@ use crate::{
17 expr::{Expr, ExprId, Pat, PatId}, 17 expr::{Expr, ExprId, Pat, PatId},
18 nameres::CrateDefMap, 18 nameres::CrateDefMap,
19 path::Path, 19 path::Path,
20 ModuleId, 20 AstItemDef, DefWithBodyId, ModuleId,
21}; 21};
22 22
23pub struct Expander { 23pub struct Expander {
@@ -141,7 +141,37 @@ pub struct BodySourceMap {
141} 141}
142 142
143impl Body { 143impl Body {
144 pub fn new( 144 pub(crate) fn body_with_source_map_query(
145 db: &impl DefDatabase2,
146 def: DefWithBodyId,
147 ) -> (Arc<Body>, Arc<BodySourceMap>) {
148 let mut params = None;
149
150 let (file_id, module, body) = match def {
151 DefWithBodyId::FunctionId(f) => {
152 let src = f.source(db);
153 params = src.ast.param_list();
154 (src.file_id, f.module(db), src.ast.body().map(ast::Expr::from))
155 }
156 DefWithBodyId::ConstId(c) => {
157 let src = c.source(db);
158 (src.file_id, c.module(db), src.ast.body())
159 }
160 DefWithBodyId::StaticId(s) => {
161 let src = s.source(db);
162 (src.file_id, s.module(db), src.ast.body())
163 }
164 };
165 let expander = Expander::new(db, file_id, module);
166 let (body, source_map) = Body::new(db, expander, params, body);
167 (Arc::new(body), Arc::new(source_map))
168 }
169
170 pub(crate) fn body_query(db: &impl DefDatabase2, def: DefWithBodyId) -> Arc<Body> {
171 db.body_with_source_map(def).0
172 }
173
174 fn new(
145 db: &impl DefDatabase2, 175 db: &impl DefDatabase2,
146 expander: Expander, 176 expander: Expander,
147 params: Option<ast::ParamList>, 177 params: Option<ast::ParamList>,