aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/goto_definition.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/goto_definition.rs')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 6fa430754..9ec179593 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(
54 if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { 54 if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) {
55 tested_by!(goto_definition_works_for_methods); 55 tested_by!(goto_definition_works_for_methods);
56 let infer_result = function.infer(db); 56 let infer_result = function.infer(db);
57 let syntax_mapping = function.body_syntax_mapping(db); 57 let source_map = function.body_source_map(db);
58 let expr = ast::Expr::cast(method_call.syntax()).unwrap(); 58 let expr = ast::Expr::cast(method_call.syntax()).unwrap();
59 if let Some(func) = 59 if let Some(func) =
60 syntax_mapping.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) 60 source_map.node_expr(expr).and_then(|it| infer_result.method_resolution(it))
61 { 61 {
62 return Exact(NavigationTarget::from_function(db, func)); 62 return Exact(NavigationTarget::from_function(db, func));
63 }; 63 };
@@ -66,10 +66,10 @@ pub(crate) fn reference_definition(
66 if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) { 66 if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) {
67 tested_by!(goto_definition_works_for_fields); 67 tested_by!(goto_definition_works_for_fields);
68 let infer_result = function.infer(db); 68 let infer_result = function.infer(db);
69 let syntax_mapping = function.body_syntax_mapping(db); 69 let source_map = function.body_source_map(db);
70 let expr = ast::Expr::cast(field_expr.syntax()).unwrap(); 70 let expr = ast::Expr::cast(field_expr.syntax()).unwrap();
71 if let Some(field) = 71 if let Some(field) =
72 syntax_mapping.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) 72 source_map.node_expr(expr).and_then(|it| infer_result.field_resolution(it))
73 { 73 {
74 return Exact(NavigationTarget::from_field(db, field)); 74 return Exact(NavigationTarget::from_field(db, field));
75 }; 75 };
@@ -80,11 +80,11 @@ pub(crate) fn reference_definition(
80 tested_by!(goto_definition_works_for_named_fields); 80 tested_by!(goto_definition_works_for_named_fields);
81 81
82 let infer_result = function.infer(db); 82 let infer_result = function.infer(db);
83 let syntax_mapping = function.body_syntax_mapping(db); 83 let source_map = function.body_source_map(db);
84 84
85 let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); 85 let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast);
86 86
87 if let Some(expr) = struct_lit.and_then(|lit| syntax_mapping.node_expr(lit.into())) { 87 if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) {
88 let ty = infer_result[expr].clone(); 88 let ty = infer_result[expr].clone();
89 if let hir::Ty::Adt { def_id, .. } = ty { 89 if let hir::Ty::Adt { def_id, .. } = ty {
90 if let hir::AdtDef::Struct(s) = def_id { 90 if let hir::AdtDef::Struct(s) = def_id {
@@ -109,9 +109,8 @@ pub(crate) fn reference_definition(
109 Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), 109 Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)),
110 Some(Resolution::LocalBinding(pat)) => { 110 Some(Resolution::LocalBinding(pat)) => {
111 let body = resolver.body().expect("no body for local binding"); 111 let body = resolver.body().expect("no body for local binding");
112 let syntax_mapping = body.syntax_mapping(db); 112 let source_map = body.owner().body_source_map(db);
113 let ptr = 113 let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping");
114 syntax_mapping.pat_syntax(pat).expect("pattern not found in syntax mapping");
115 let name = 114 let name =
116 path.as_ident().cloned().expect("local binding from a multi-segment path"); 115 path.as_ident().cloned().expect("local binding from a multi-segment path");
117 let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); 116 let nav = NavigationTarget::from_scope_entry(file_id, name, ptr);