From eaf1df26e9903772d40df30dd70c75c38d8cb887 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 15:14:37 +0300 Subject: rename syntax-mapping -> source-map --- crates/ra_assists/src/fill_match_arms.rs | 2 +- crates/ra_hir/src/code_model_api.rs | 8 ++++---- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/expr.rs | 22 +++++++++++----------- crates/ra_hir/src/expr/scope.rs | 4 ++-- crates/ra_hir/src/ty/tests.rs | 10 +++++----- crates/ra_ide_api/src/change.rs | 2 +- crates/ra_ide_api/src/completion/complete_dot.rs | 2 +- .../src/completion/complete_struct_literal.rs | 2 +- crates/ra_ide_api/src/goto_definition.rs | 6 +++--- crates/ra_ide_api/src/hover.rs | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 30020b56e..81b11956a 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs @@ -23,7 +23,7 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx) -> Option Arc { - db.body_syntax_mapping(*self) + pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc { + db.body_source_map(*self) } pub fn body(&self, db: &impl HirDatabase) -> Arc { @@ -497,7 +497,7 @@ impl Function { pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { let scopes = db.expr_scopes(*self); - let syntax_mapping = db.body_syntax_mapping(*self); + let syntax_mapping = db.body_source_map(*self); ScopesWithSyntaxMapping { scopes, syntax_mapping } } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index ec848f1b2..cb1c24561 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -108,8 +108,8 @@ pub trait HirDatabase: PersistentHirDatabase { #[salsa::invoke(crate::expr::body_hir)] fn body_hir(&self, func: Function) -> Arc; - #[salsa::invoke(crate::expr::body_syntax_mapping)] - fn body_syntax_mapping(&self, func: Function) -> Arc; + #[salsa::invoke(crate::expr::body_source_map)] + fn body_source_map(&self, func: Function) -> Arc; #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] fn impls_in_crate(&self, krate: Crate) -> Arc; diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index aa39d28ed..b1398411b 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -49,7 +49,7 @@ pub struct Body { /// a structure that is agnostic to the actual positions of expressions in the /// file, so that we don't recompute types whenever some whitespace is typed. #[derive(Debug, Eq, PartialEq)] -pub struct BodySyntaxMapping { +pub struct BodySourceMap { body: Arc, expr_syntax_mapping: FxHashMap, expr_syntax_mapping_back: ArenaMap, @@ -78,8 +78,8 @@ impl Body { self.pats.iter() } - pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc { - db.body_syntax_mapping(self.owner) + pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc { + db.body_source_map(self.owner) } } @@ -119,7 +119,7 @@ impl Index for Body { } } -impl BodySyntaxMapping { +impl BodySourceMap { pub fn expr_syntax(&self, expr: ExprId) -> Option { self.expr_syntax_mapping_back.get(expr).cloned() } @@ -468,7 +468,7 @@ impl Pat { // Queries pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc { - Arc::clone(&body_syntax_mapping(db, func).body) + Arc::clone(&body_source_map(db, func).body) } struct ExprCollector { @@ -910,7 +910,7 @@ impl ExprCollector { self.body_expr = Some(body); } - fn into_body_syntax_mapping(self) -> BodySyntaxMapping { + fn into_body_source_map(self) -> BodySourceMap { let body = Body { owner: self.owner, exprs: self.exprs, @@ -918,7 +918,7 @@ impl ExprCollector { params: self.params, body_expr: self.body_expr.expect("A body should have been collected"), }; - BodySyntaxMapping { + BodySourceMap { body: Arc::new(body), expr_syntax_mapping: self.expr_syntax_mapping, expr_syntax_mapping_back: self.expr_syntax_mapping_back, @@ -928,18 +928,18 @@ impl ExprCollector { } } -pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, func: Function) -> Arc { +pub(crate) fn body_source_map(db: &impl HirDatabase, func: Function) -> Arc { let mut collector = ExprCollector::new(func); // TODO: consts, etc. collector.collect_fn_body(&func.source(db).1); - Arc::new(collector.into_body_syntax_mapping()) + Arc::new(collector.into_body_source_map()) } #[cfg(test)] -pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySyntaxMapping { +pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySourceMap { let mut collector = ExprCollector::new(function); collector.collect_fn_body(node); - collector.into_body_syntax_mapping() + collector.into_body_source_map() } diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index bb8d50db8..bb919dcfa 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -11,7 +11,7 @@ use ra_arena::{Arena, RawId, impl_arena_id}; use crate::{ Name, AsName, Function, - expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}, + expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap}, HirDatabase, }; @@ -109,7 +109,7 @@ impl ExprScopes { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ScopesWithSyntaxMapping { - pub syntax_mapping: Arc, + pub syntax_mapping: Arc, pub scopes: Arc, } diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 8de46a29e..2fdfb54f4 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -1045,11 +1045,11 @@ fn test() { fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { let func = source_binder::function_from_position(db, pos).unwrap(); - let body_syntax_mapping = func.body_syntax_mapping(db); + let body_source_map = func.body_source_map(db); let inference_result = func.infer(db); let (_, syntax) = func.source(db); let node = algo::find_node_at_offset::(syntax.syntax(), pos.offset).unwrap(); - let expr = body_syntax_mapping.node_expr(node).unwrap(); + let expr = body_source_map.node_expr(node).unwrap(); let ty = &inference_result[expr]; ty.to_string() } @@ -1061,17 +1061,17 @@ fn infer(content: &str) -> String { for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); let inference_result = func.infer(&db); - let body_syntax_mapping = func.body_syntax_mapping(&db); + let body_source_map = func.body_source_map(&db); let mut types = Vec::new(); for (pat, ty) in inference_result.type_of_pat.iter() { - let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { + let syntax_ptr = match body_source_map.pat_syntax(pat) { Some(sp) => sp, None => continue, }; types.push((syntax_ptr, ty)); } for (expr, ty) in inference_result.type_of_expr.iter() { - let syntax_ptr = match body_syntax_mapping.expr_syntax(expr) { + let syntax_ptr = match body_source_map.expr_syntax(expr) { Some(sp) => sp, None => continue, }; diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 3f041f9c3..3fe54d47b 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -225,6 +225,6 @@ impl RootDatabase { self.query(hir::db::LowerModuleQuery).sweep(sweep); self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep); - self.query(hir::db::BodySyntaxMappingQuery).sweep(sweep); + self.query(hir::db::BodySourceMapQuery).sweep(sweep); } } diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index d5ad2e79f..cf6a6a388 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -9,7 +9,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { _ => return, }; let infer_result = function.infer(ctx.db); - let syntax_mapping = function.body_syntax_mapping(ctx.db); + let syntax_mapping = function.body_source_map(ctx.db); let expr = match syntax_mapping.node_expr(receiver) { Some(expr) => expr, None => return, diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index afb092f59..573953bda 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs @@ -9,7 +9,7 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon _ => return, }; let infer_result = function.infer(ctx.db); - let syntax_mapping = function.body_syntax_mapping(ctx.db); + let syntax_mapping = function.body_source_map(ctx.db); let expr = match syntax_mapping.node_expr(struct_lit.into()) { Some(expr) => expr, None => return, diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 6fa430754..9957a5393 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -54,7 +54,7 @@ pub(crate) fn reference_definition( if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { tested_by!(goto_definition_works_for_methods); let infer_result = function.infer(db); - let syntax_mapping = function.body_syntax_mapping(db); + let syntax_mapping = function.body_source_map(db); let expr = ast::Expr::cast(method_call.syntax()).unwrap(); if let Some(func) = syntax_mapping.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) @@ -66,7 +66,7 @@ pub(crate) fn reference_definition( if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) { tested_by!(goto_definition_works_for_fields); let infer_result = function.infer(db); - let syntax_mapping = function.body_syntax_mapping(db); + let syntax_mapping = function.body_source_map(db); let expr = ast::Expr::cast(field_expr.syntax()).unwrap(); if let Some(field) = syntax_mapping.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) @@ -80,7 +80,7 @@ pub(crate) fn reference_definition( tested_by!(goto_definition_works_for_named_fields); let infer_result = function.infer(db); - let syntax_mapping = function.body_syntax_mapping(db); + let syntax_mapping = function.body_source_map(db); let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 1a1853df3..cceec91b9 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -132,7 +132,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option { let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; let infer = function.infer(db); - let syntax_mapping = function.body_syntax_mapping(db); + let syntax_mapping = function.body_source_map(db); if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { Some(infer[expr].to_string()) } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { -- cgit v1.2.3 From f4c5383103e2b79b05e2669889d44e51988932a6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 16:18:40 +0300 Subject: dont store body inside source map --- crates/ra_hir/src/code_model_api.rs | 4 +- crates/ra_hir/src/db.rs | 11 +++-- crates/ra_hir/src/expr.rs | 86 ++++++++++++++++--------------------- crates/ra_hir/src/expr/scope.rs | 12 +++--- crates/ra_ide_api/src/change.rs | 2 +- 5 files changed, 54 insertions(+), 61 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index f8521e895..c77b8acc7 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -484,7 +484,7 @@ impl Function { } pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc { - db.body_source_map(*self) + db.body_with_source_map(*self).1 } pub fn body(&self, db: &impl HirDatabase) -> Arc { @@ -497,7 +497,7 @@ impl Function { pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { let scopes = db.expr_scopes(*self); - let syntax_mapping = db.body_source_map(*self); + let syntax_mapping = db.body_with_source_map(*self).1; ScopesWithSyntaxMapping { scopes, syntax_mapping } } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index cb1c24561..a669dc9b0 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -105,11 +105,14 @@ pub trait HirDatabase: PersistentHirDatabase { #[salsa::invoke(crate::ty::type_for_field)] fn type_for_field(&self, field: StructField) -> Ty; - #[salsa::invoke(crate::expr::body_hir)] - fn body_hir(&self, func: Function) -> Arc; + #[salsa::invoke(crate::expr::body_with_source_map_query)] + fn body_with_source_map( + &self, + func: Function, + ) -> (Arc, Arc); - #[salsa::invoke(crate::expr::body_source_map)] - fn body_source_map(&self, func: Function) -> Arc; + #[salsa::invoke(crate::expr::body_hir_query)] + fn body_hir(&self, func: Function) -> Arc; #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] fn impls_in_crate(&self, krate: Crate) -> Arc; diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index b1398411b..4e399ec6d 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -48,13 +48,13 @@ pub struct Body { /// expression containing it; but for type inference etc., we want to operate on /// a structure that is agnostic to the actual positions of expressions in the /// file, so that we don't recompute types whenever some whitespace is typed. -#[derive(Debug, Eq, PartialEq)] +#[derive(Default, Debug, Eq, PartialEq)] pub struct BodySourceMap { - body: Arc, - expr_syntax_mapping: FxHashMap, - expr_syntax_mapping_back: ArenaMap, - pat_syntax_mapping: FxHashMap, - pat_syntax_mapping_back: ArenaMap, + // body: Arc, + expr_map: FxHashMap, + expr_map_back: ArenaMap, + pat_map: FxHashMap, + pat_map_back: ArenaMap, } impl Body { @@ -79,7 +79,7 @@ impl Body { } pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc { - db.body_source_map(self.owner) + db.body_with_source_map(self.owner).1 } } @@ -121,31 +121,27 @@ impl Index for Body { impl BodySourceMap { pub fn expr_syntax(&self, expr: ExprId) -> Option { - self.expr_syntax_mapping_back.get(expr).cloned() + self.expr_map_back.get(expr).cloned() } pub fn syntax_expr(&self, ptr: SyntaxNodePtr) -> Option { - self.expr_syntax_mapping.get(&ptr).cloned() + self.expr_map.get(&ptr).cloned() } pub fn node_expr(&self, node: &ast::Expr) -> Option { - self.expr_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned() + self.expr_map.get(&SyntaxNodePtr::new(node.syntax())).cloned() } pub fn pat_syntax(&self, pat: PatId) -> Option { - self.pat_syntax_mapping_back.get(pat).cloned() + self.pat_map_back.get(pat).cloned() } pub fn syntax_pat(&self, ptr: SyntaxNodePtr) -> Option { - self.pat_syntax_mapping.get(&ptr).cloned() + self.pat_map.get(&ptr).cloned() } pub fn node_pat(&self, node: &ast::Pat) -> Option { - self.pat_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned() - } - - pub fn body(&self) -> &Arc { - &self.body + self.pat_map.get(&SyntaxNodePtr::new(node.syntax())).cloned() } } @@ -467,18 +463,11 @@ impl Pat { // Queries -pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc { - Arc::clone(&body_source_map(db, func).body) -} - struct ExprCollector { owner: Function, exprs: Arena, pats: Arena, - expr_syntax_mapping: FxHashMap, - expr_syntax_mapping_back: ArenaMap, - pat_syntax_mapping: FxHashMap, - pat_syntax_mapping_back: ArenaMap, + source_map: BodySourceMap, params: Vec, body_expr: Option, } @@ -489,10 +478,7 @@ impl ExprCollector { owner, exprs: Arena::default(), pats: Arena::default(), - expr_syntax_mapping: FxHashMap::default(), - expr_syntax_mapping_back: ArenaMap::default(), - pat_syntax_mapping: FxHashMap::default(), - pat_syntax_mapping_back: ArenaMap::default(), + source_map: BodySourceMap::default(), params: Vec::new(), body_expr: None, } @@ -500,15 +486,15 @@ impl ExprCollector { fn alloc_expr(&mut self, expr: Expr, syntax_ptr: SyntaxNodePtr) -> ExprId { let id = self.exprs.alloc(expr); - self.expr_syntax_mapping.insert(syntax_ptr, id); - self.expr_syntax_mapping_back.insert(id, syntax_ptr); + self.source_map.expr_map.insert(syntax_ptr, id); + self.source_map.expr_map_back.insert(id, syntax_ptr); id } fn alloc_pat(&mut self, pat: Pat, syntax_ptr: SyntaxNodePtr) -> PatId { let id = self.pats.alloc(pat); - self.pat_syntax_mapping.insert(syntax_ptr, id); - self.pat_syntax_mapping_back.insert(id, syntax_ptr); + self.source_map.pat_map.insert(syntax_ptr, id); + self.source_map.pat_map_back.insert(id, syntax_ptr); id } @@ -639,7 +625,7 @@ impl ExprCollector { ast::ExprKind::ParenExpr(e) => { let inner = self.collect_expr_opt(e.expr()); // make the paren expr point to the inner expression as well - self.expr_syntax_mapping.insert(syntax_ptr, inner); + self.source_map.expr_map.insert(syntax_ptr, inner); inner } ast::ExprKind::ReturnExpr(e) => { @@ -660,9 +646,11 @@ impl ExprCollector { } else if let Some(nr) = field.name_ref() { // field shorthand let id = self.exprs.alloc(Expr::Path(Path::from_name_ref(nr))); - self.expr_syntax_mapping + self.source_map + .expr_map .insert(SyntaxNodePtr::new(nr.syntax()), id); - self.expr_syntax_mapping_back + self.source_map + .expr_map_back .insert(id, SyntaxNodePtr::new(nr.syntax())); id } else { @@ -910,7 +898,7 @@ impl ExprCollector { self.body_expr = Some(body); } - fn into_body_source_map(self) -> BodySourceMap { + fn finish(self) -> (Body, BodySourceMap) { let body = Body { owner: self.owner, exprs: self.exprs, @@ -918,28 +906,30 @@ impl ExprCollector { params: self.params, body_expr: self.body_expr.expect("A body should have been collected"), }; - BodySourceMap { - body: Arc::new(body), - expr_syntax_mapping: self.expr_syntax_mapping, - expr_syntax_mapping_back: self.expr_syntax_mapping_back, - pat_syntax_mapping: self.pat_syntax_mapping, - pat_syntax_mapping_back: self.pat_syntax_mapping_back, - } + (body, self.source_map) } } -pub(crate) fn body_source_map(db: &impl HirDatabase, func: Function) -> Arc { +pub(crate) fn body_with_source_map_query( + db: &impl HirDatabase, + func: Function, +) -> (Arc, Arc) { let mut collector = ExprCollector::new(func); // TODO: consts, etc. collector.collect_fn_body(&func.source(db).1); - Arc::new(collector.into_body_source_map()) + let (body, source_map) = collector.finish(); + (Arc::new(body), Arc::new(source_map)) +} + +pub(crate) fn body_hir_query(db: &impl HirDatabase, func: Function) -> Arc { + db.body_with_source_map(func).0 } #[cfg(test)] -pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySourceMap { +fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> (Body, BodySourceMap) { let mut collector = ExprCollector::new(function); collector.collect_fn_body(node); - collector.into_body_source_map() + collector.finish() } diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index bb919dcfa..d5824eb81 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -316,11 +316,11 @@ mod tests { let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; - let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def); - let scopes = ExprScopes::new(Arc::clone(body_hir.body())); + let (body, syntax_mapping) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); + let scopes = ExprScopes::new(Arc::new(body)); let scopes = ScopesWithSyntaxMapping { scopes: Arc::new(scopes), - syntax_mapping: Arc::new(body_hir), + syntax_mapping: Arc::new(syntax_mapping), }; let actual = scopes .scope_chain(marker.syntax()) @@ -417,11 +417,11 @@ mod tests { let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; - let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def); - let scopes = ExprScopes::new(Arc::clone(body_hir.body())); + let (body, syntax_mapping) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); + let scopes = ExprScopes::new(Arc::new(body)); let scopes = ScopesWithSyntaxMapping { scopes: Arc::new(scopes), - syntax_mapping: Arc::new(body_hir), + syntax_mapping: Arc::new(syntax_mapping), }; let local_name_entry = scopes.resolve_local_name(name_ref).unwrap(); let local_name = local_name_entry.ptr(); diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 3fe54d47b..4c35ce050 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -225,6 +225,6 @@ impl RootDatabase { self.query(hir::db::LowerModuleQuery).sweep(sweep); self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep); - self.query(hir::db::BodySourceMapQuery).sweep(sweep); + self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); } } -- cgit v1.2.3 From ca957edf96199c61496254f8534fe09221e03c26 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 16:36:25 +0300 Subject: rename to source_map --- crates/ra_hir/src/code_model_api.rs | 4 ++-- crates/ra_hir/src/expr/scope.rs | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index c77b8acc7..7fc14634b 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -497,8 +497,8 @@ impl Function { pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { let scopes = db.expr_scopes(*self); - let syntax_mapping = db.body_with_source_map(*self).1; - ScopesWithSyntaxMapping { scopes, syntax_mapping } + let source_map = db.body_with_source_map(*self).1; + ScopesWithSyntaxMapping { scopes, source_map } } pub fn signature(&self, db: &impl HirDatabase) -> Arc { diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index d5824eb81..578b10c65 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -109,7 +109,7 @@ impl ExprScopes { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ScopesWithSyntaxMapping { - pub syntax_mapping: Arc, + pub source_map: Arc, pub scopes: Arc, } @@ -138,7 +138,7 @@ impl ScopesWithSyntaxMapping { self.scopes .scope_for .iter() - .filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope))) + .filter_map(|(id, scope)| Some((self.source_map.expr_syntax(*id)?, scope))) // find containing scope .min_by_key(|(ptr, _scope)| { (!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len()) @@ -155,7 +155,7 @@ impl ScopesWithSyntaxMapping { .scopes .scope_for .iter() - .filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope))) + .filter_map(|(id, scope)| Some((self.source_map.expr_syntax(*id)?, scope))) .map(|(ptr, scope)| (ptr.range(), scope)) .filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r); @@ -185,7 +185,7 @@ impl ScopesWithSyntaxMapping { ret.and_then(|entry| { Some(ScopeEntryWithSyntax { name: entry.name().clone(), - ptr: self.syntax_mapping.pat_syntax(entry.pat())?, + ptr: self.source_map.pat_syntax(entry.pat())?, }) }) } @@ -211,7 +211,7 @@ impl ScopesWithSyntaxMapping { pub fn scope_for(&self, node: &SyntaxNode) -> Option { node.ancestors() .map(SyntaxNodePtr::new) - .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) + .filter_map(|ptr| self.source_map.syntax_expr(ptr)) .find_map(|it| self.scopes.scope_for(it)) } } @@ -316,12 +316,10 @@ mod tests { let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; - let (body, syntax_mapping) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); + let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); let scopes = ExprScopes::new(Arc::new(body)); - let scopes = ScopesWithSyntaxMapping { - scopes: Arc::new(scopes), - syntax_mapping: Arc::new(syntax_mapping), - }; + let scopes = + ScopesWithSyntaxMapping { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; let actual = scopes .scope_chain(marker.syntax()) .flat_map(|scope| scopes.scopes.entries(scope)) @@ -417,12 +415,10 @@ mod tests { let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; - let (body, syntax_mapping) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); + let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); let scopes = ExprScopes::new(Arc::new(body)); - let scopes = ScopesWithSyntaxMapping { - scopes: Arc::new(scopes), - syntax_mapping: Arc::new(syntax_mapping), - }; + let scopes = + ScopesWithSyntaxMapping { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; let local_name_entry = scopes.resolve_local_name(name_ref).unwrap(); let local_name = local_name_entry.ptr(); assert_eq!(local_name.range(), expected_name.syntax().range()); -- cgit v1.2.3 From fe5574b05a006671fb7dec44d8d6edc92c90b002 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 16:38:28 +0300 Subject: rename scopes --- crates/ra_hir/src/code_model_api.rs | 6 +++--- crates/ra_hir/src/expr.rs | 2 +- crates/ra_hir/src/expr/scope.rs | 8 ++++---- crates/ra_hir/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 7fc14634b..e362cc05f 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -5,7 +5,7 @@ use ra_db::{CrateId, SourceRootId, Edition}; use ra_syntax::{ast::self, TreeArc, SyntaxNode}; use crate::{ - Name, ScopesWithSyntaxMapping, Ty, HirFileId, + Name, ScopesWithSourceMap, Ty, HirFileId, HirDatabase, PersistentHirDatabase, type_ref::TypeRef, nameres::{ModuleScope, Namespace, lower::ImportId}, @@ -495,10 +495,10 @@ impl Function { db.type_for_def((*self).into(), Namespace::Values) } - pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { + pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSourceMap { let scopes = db.expr_scopes(*self); let source_map = db.body_with_source_map(*self).1; - ScopesWithSyntaxMapping { scopes, source_map } + ScopesWithSourceMap { scopes, source_map } } pub fn signature(&self, db: &impl HirDatabase) -> Arc { diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 4e399ec6d..8b1079648 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -16,7 +16,7 @@ use crate::{ }; use crate::{ path::GenericArgs, ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}}; -pub use self::scope::{ExprScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; +pub use self::scope::{ExprScopes, ScopesWithSourceMap, ScopeEntryWithSyntax}; pub(crate) mod scope; diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 578b10c65..81fbc509e 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -108,7 +108,7 @@ impl ExprScopes { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct ScopesWithSyntaxMapping { +pub struct ScopesWithSourceMap { pub source_map: Arc, pub scopes: Arc, } @@ -129,7 +129,7 @@ impl ScopeEntryWithSyntax { } } -impl ScopesWithSyntaxMapping { +impl ScopesWithSourceMap { fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator + 'a { generate(self.scope_for(node), move |&scope| self.scopes.scopes[scope].parent) } @@ -319,7 +319,7 @@ mod tests { let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); let scopes = ExprScopes::new(Arc::new(body)); let scopes = - ScopesWithSyntaxMapping { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; + ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; let actual = scopes .scope_chain(marker.syntax()) .flat_map(|scope| scopes.scopes.entries(scope)) @@ -418,7 +418,7 @@ mod tests { let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); let scopes = ExprScopes::new(Arc::new(body)); let scopes = - ScopesWithSyntaxMapping { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; + ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; let local_name_entry = scopes.resolve_local_name(name_ref).unwrap(); let local_name = local_name_entry.ptr(); assert_eq!(local_name.range(), expected_name.syntax().range()); diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index edc1b4f57..a6e744ea7 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -60,7 +60,7 @@ pub use self::{ impl_block::{ImplBlock, ImplItem}, docs::{Docs, Documentation}, adt::AdtDef, - expr::{ExprScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}, + expr::{ExprScopes, ScopesWithSourceMap, ScopeEntryWithSyntax}, resolve::{Resolver, Resolution}, }; -- cgit v1.2.3 From 80bb7d86ec6e7560ec6880a20eb8c5b984b2af52 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 16:49:06 +0300 Subject: align lower module query names --- crates/ra_hir/src/code_model_api.rs | 2 +- crates/ra_hir/src/code_model_impl/module.rs | 2 +- crates/ra_hir/src/db.rs | 14 +++++++------- crates/ra_hir/src/nameres.rs | 2 +- crates/ra_hir/src/nameres/lower.rs | 13 +++---------- crates/ra_hir/src/source_binder.rs | 2 +- crates/ra_ide_api/src/change.rs | 3 +-- 7 files changed, 15 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index e362cc05f..3ac146950 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -191,7 +191,7 @@ impl Module { } pub fn declarations(self, db: &impl HirDatabase) -> Vec { - let (lowered_module, _) = db.lower_module(self); + let lowered_module = db.lower_module(self); lowered_module .declarations .values() diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 2d3058afd..437f96942 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -47,7 +47,7 @@ impl Module { db: &impl HirDatabase, import: ImportId, ) -> TreeArc { - let source_map = db.lower_module_source_map(*self); + let (_, source_map) = db.lower_module_with_source_map(*self); let (_, source) = self.definition_source(db); source_map.get(&source, import) } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index a669dc9b0..21d22aa7f 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -48,14 +48,14 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef { delc_id: Option, ) -> Arc>; - #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_query)] - fn lower_module(&self, module: Module) -> (Arc, Arc); - - #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_module_query)] - fn lower_module_module(&self, module: Module) -> Arc; + #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_with_source_map_query)] + fn lower_module_with_source_map( + &self, + module: Module, + ) -> (Arc, Arc); - #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_source_map_query)] - fn lower_module_source_map(&self, module: Module) -> Arc; + #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_query)] + fn lower_module(&self, module: Module) -> Arc; #[salsa::invoke(crate::nameres::ItemMap::item_map_query)] fn item_map(&self, krate: Crate) -> Arc; diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index ac390c5db..73919ee37 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -481,7 +481,7 @@ impl ItemMap { let module_tree = db.module_tree(krate); let input = module_tree .modules() - .map(|module_id| (module_id, db.lower_module_module(Module { krate, module_id }))) + .map(|module_id| (module_id, db.lower_module(Module { krate, module_id }))) .collect::>(); let resolver = Resolver::new(db, &input, krate); diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 2bc3eb60c..56262ad6d 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs @@ -60,21 +60,14 @@ impl ImportSourceMap { } impl LoweredModule { - pub(crate) fn lower_module_module_query( + pub(crate) fn lower_module_query( db: &impl PersistentHirDatabase, module: Module, ) -> Arc { - db.lower_module(module).0 - } - - pub(crate) fn lower_module_source_map_query( - db: &impl PersistentHirDatabase, - module: Module, - ) -> Arc { - db.lower_module(module).1 + db.lower_module_with_source_map(module).0 } - pub(crate) fn lower_module_query( + pub(crate) fn lower_module_with_source_map_query( db: &impl PersistentHirDatabase, module: Module, ) -> (Arc, Arc) { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 625a2ce45..ea20cd15a 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -157,7 +157,7 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te Some(it) => it, None => return Vec::new(), }; - let items = db.lower_module_module(module); + let items = db.lower_module(module); let mut res = Vec::new(); for macro_call_id in items diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 4c35ce050..0c90ed5b5 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -223,8 +223,7 @@ impl RootDatabase { self.query(hir::db::FileItemsQuery).sweep(sweep); self.query(hir::db::FileItemQuery).sweep(sweep); - self.query(hir::db::LowerModuleQuery).sweep(sweep); - self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep); + self.query(hir::db::LowerModuleWithSourceMapQuery).sweep(sweep); self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); } } -- cgit v1.2.3 From 03b2ab8e1f11f0e05234da9162ef57f7a30a64af Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 16:56:09 +0300 Subject: rename syntax_mapping as well --- crates/ra_assists/src/fill_match_arms.rs | 4 ++-- crates/ra_hir/src/expr.rs | 2 +- crates/ra_ide_api/src/completion/complete_dot.rs | 4 ++-- .../src/completion/complete_struct_literal.rs | 4 ++-- crates/ra_ide_api/src/goto_definition.rs | 17 ++++++++--------- crates/ra_ide_api/src/hover.rs | 6 +++--- 6 files changed, 18 insertions(+), 19 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 81b11956a..6a22b0af5 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs @@ -23,8 +23,8 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx) -> Option e, diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 8b1079648..6043f4028 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -78,7 +78,7 @@ impl Body { self.pats.iter() } - pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc { + pub fn source_map(&self, db: &impl HirDatabase) -> Arc { db.body_with_source_map(self.owner).1 } } diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index cf6a6a388..94c66be31 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -9,8 +9,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { _ => return, }; let infer_result = function.infer(ctx.db); - let syntax_mapping = function.body_source_map(ctx.db); - let expr = match syntax_mapping.node_expr(receiver) { + let source_map = function.body_source_map(ctx.db); + let expr = match source_map.node_expr(receiver) { Some(expr) => expr, None => return, }; diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index 573953bda..6bef9624e 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs @@ -9,8 +9,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon _ => return, }; let infer_result = function.infer(ctx.db); - let syntax_mapping = function.body_source_map(ctx.db); - let expr = match syntax_mapping.node_expr(struct_lit.into()) { + let source_map = function.body_source_map(ctx.db); + let expr = match source_map.node_expr(struct_lit.into()) { Some(expr) => expr, None => return, }; diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 9957a5393..1f284af56 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -54,10 +54,10 @@ pub(crate) fn reference_definition( if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { tested_by!(goto_definition_works_for_methods); let infer_result = function.infer(db); - let syntax_mapping = function.body_source_map(db); + let source_map = function.body_source_map(db); let expr = ast::Expr::cast(method_call.syntax()).unwrap(); if let Some(func) = - syntax_mapping.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) + source_map.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) { return Exact(NavigationTarget::from_function(db, func)); }; @@ -66,10 +66,10 @@ pub(crate) fn reference_definition( if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) { tested_by!(goto_definition_works_for_fields); let infer_result = function.infer(db); - let syntax_mapping = function.body_source_map(db); + let source_map = function.body_source_map(db); let expr = ast::Expr::cast(field_expr.syntax()).unwrap(); if let Some(field) = - syntax_mapping.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) + source_map.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) { return Exact(NavigationTarget::from_field(db, field)); }; @@ -80,11 +80,11 @@ pub(crate) fn reference_definition( tested_by!(goto_definition_works_for_named_fields); let infer_result = function.infer(db); - let syntax_mapping = function.body_source_map(db); + let source_map = function.body_source_map(db); let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); - if let Some(expr) = struct_lit.and_then(|lit| syntax_mapping.node_expr(lit.into())) { + if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) { let ty = infer_result[expr].clone(); if let hir::Ty::Adt { def_id, .. } = ty { if let hir::AdtDef::Struct(s) = def_id { @@ -109,9 +109,8 @@ pub(crate) fn reference_definition( Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), Some(Resolution::LocalBinding(pat)) => { let body = resolver.body().expect("no body for local binding"); - let syntax_mapping = body.syntax_mapping(db); - let ptr = - syntax_mapping.pat_syntax(pat).expect("pattern not found in syntax mapping"); + let source_map = body.source_map(db); + let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping"); let name = path.as_ident().cloned().expect("local binding from a multi-segment path"); let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index cceec91b9..a2d203b4f 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -132,10 +132,10 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option { let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; let infer = function.infer(db); - let syntax_mapping = function.body_source_map(db); - if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { + let source_map = function.body_source_map(db); + if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) { Some(infer[expr].to_string()) - } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { + } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) { Some(infer[pat].to_string()) } else { None -- cgit v1.2.3 From 8fc08d36e33ad95d70d262cef7d2e694f7f8f502 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 16:59:18 +0300 Subject: remove second way to get the body --- crates/ra_hir/src/expr.rs | 4 ---- crates/ra_ide_api/src/goto_definition.rs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 6043f4028..d6c551fb2 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -77,10 +77,6 @@ impl Body { pub fn pats(&self) -> impl Iterator { self.pats.iter() } - - pub fn source_map(&self, db: &impl HirDatabase) -> Arc { - db.body_with_source_map(self.owner).1 - } } // needs arbitrary_self_types to be a method... or maybe move to the def? diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 1f284af56..9ec179593 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -109,7 +109,7 @@ pub(crate) fn reference_definition( Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), Some(Resolution::LocalBinding(pat)) => { let body = resolver.body().expect("no body for local binding"); - let source_map = body.source_map(db); + let source_map = body.owner().body_source_map(db); let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping"); let name = path.as_ident().cloned().expect("local binding from a multi-segment path"); -- cgit v1.2.3 From f0a9d026fcd8bea1944287b1fe7c6573ca62ca9d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Mar 2019 17:01:20 +0300 Subject: remove comment --- crates/ra_hir/src/expr.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index d6c551fb2..6c7489e63 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -50,7 +50,6 @@ pub struct Body { /// file, so that we don't recompute types whenever some whitespace is typed. #[derive(Default, Debug, Eq, PartialEq)] pub struct BodySourceMap { - // body: Arc, expr_map: FxHashMap, expr_map_back: ArenaMap, pat_map: FxHashMap, -- cgit v1.2.3