diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 81b11956a1a..6a22b0af54f 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 8b1079648ab..6043f402831 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -78,7 +78,7 @@ pub fn pats(&self) -> impl Iterator { 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 cf6a6a38850..94c66be318f 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 573953bdaf0..6bef9624ee0 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 9957a539311..1f284af56c7 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 cceec91b99f..a2d203b4f92 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