aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/goto_definition.rs57
-rw-r--r--crates/ra_ide/src/marks.rs9
-rw-r--r--crates/ra_ide/src/references/classify.rs9
3 files changed, 47 insertions, 28 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index ee4ae3e03..9b5744789 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -258,7 +258,7 @@ mod tests {
258 } 258 }
259 259
260 #[test] 260 #[test]
261 fn goto_definition_works_in_items() { 261 fn goto_def_in_items() {
262 check_goto( 262 check_goto(
263 " 263 "
264 //- /lib.rs 264 //- /lib.rs
@@ -271,7 +271,7 @@ mod tests {
271 } 271 }
272 272
273 #[test] 273 #[test]
274 fn goto_definition_works_at_start_of_item() { 274 fn goto_def_at_start_of_item() {
275 check_goto( 275 check_goto(
276 " 276 "
277 //- /lib.rs 277 //- /lib.rs
@@ -305,7 +305,7 @@ mod tests {
305 } 305 }
306 306
307 #[test] 307 #[test]
308 fn goto_definition_works_for_module_declaration() { 308 fn goto_def_for_module_declaration() {
309 check_goto( 309 check_goto(
310 " 310 "
311 //- /lib.rs 311 //- /lib.rs
@@ -332,8 +332,8 @@ mod tests {
332 } 332 }
333 333
334 #[test] 334 #[test]
335 fn goto_definition_works_for_macros() { 335 fn goto_def_for_macros() {
336 covers!(goto_definition_works_for_macros); 336 covers!(goto_def_for_macros);
337 check_goto( 337 check_goto(
338 " 338 "
339 //- /lib.rs 339 //- /lib.rs
@@ -349,8 +349,8 @@ mod tests {
349 } 349 }
350 350
351 #[test] 351 #[test]
352 fn goto_definition_works_for_macros_from_other_crates() { 352 fn goto_def_for_macros_from_other_crates() {
353 covers!(goto_definition_works_for_macros); 353 covers!(goto_def_for_macros);
354 check_goto( 354 check_goto(
355 " 355 "
356 //- /lib.rs 356 //- /lib.rs
@@ -369,7 +369,7 @@ mod tests {
369 } 369 }
370 370
371 #[test] 371 #[test]
372 fn goto_definition_works_for_macros_in_use_tree() { 372 fn goto_def_for_macros_in_use_tree() {
373 check_goto( 373 check_goto(
374 " 374 "
375 //- /lib.rs 375 //- /lib.rs
@@ -385,7 +385,7 @@ mod tests {
385 } 385 }
386 386
387 #[test] 387 #[test]
388 fn goto_definition_works_for_macro_defined_fn_with_arg() { 388 fn goto_def_for_macro_defined_fn_with_arg() {
389 check_goto( 389 check_goto(
390 " 390 "
391 //- /lib.rs 391 //- /lib.rs
@@ -405,7 +405,7 @@ mod tests {
405 } 405 }
406 406
407 #[test] 407 #[test]
408 fn goto_definition_works_for_macro_defined_fn_no_arg() { 408 fn goto_def_for_macro_defined_fn_no_arg() {
409 check_goto( 409 check_goto(
410 " 410 "
411 //- /lib.rs 411 //- /lib.rs
@@ -425,8 +425,8 @@ mod tests {
425 } 425 }
426 426
427 #[test] 427 #[test]
428 fn goto_definition_works_for_methods() { 428 fn goto_def_for_methods() {
429 covers!(goto_definition_works_for_methods); 429 covers!(goto_def_for_methods);
430 check_goto( 430 check_goto(
431 " 431 "
432 //- /lib.rs 432 //- /lib.rs
@@ -445,8 +445,8 @@ mod tests {
445 } 445 }
446 446
447 #[test] 447 #[test]
448 fn goto_definition_works_for_fields() { 448 fn goto_def_for_fields() {
449 covers!(goto_definition_works_for_fields); 449 covers!(goto_def_for_fields);
450 check_goto( 450 check_goto(
451 " 451 "
452 //- /lib.rs 452 //- /lib.rs
@@ -464,8 +464,8 @@ mod tests {
464 } 464 }
465 465
466 #[test] 466 #[test]
467 fn goto_definition_works_for_record_fields() { 467 fn goto_def_for_record_fields() {
468 covers!(goto_definition_works_for_record_fields); 468 covers!(goto_def_for_record_fields);
469 check_goto( 469 check_goto(
470 " 470 "
471 //- /lib.rs 471 //- /lib.rs
@@ -502,7 +502,7 @@ mod tests {
502 } 502 }
503 503
504 #[test] 504 #[test]
505 fn goto_definition_works_for_ufcs_inherent_methods() { 505 fn goto_def_for_ufcs_inherent_methods() {
506 check_goto( 506 check_goto(
507 " 507 "
508 //- /lib.rs 508 //- /lib.rs
@@ -521,7 +521,7 @@ mod tests {
521 } 521 }
522 522
523 #[test] 523 #[test]
524 fn goto_definition_works_for_ufcs_trait_methods_through_traits() { 524 fn goto_def_for_ufcs_trait_methods_through_traits() {
525 check_goto( 525 check_goto(
526 " 526 "
527 //- /lib.rs 527 //- /lib.rs
@@ -539,7 +539,7 @@ mod tests {
539 } 539 }
540 540
541 #[test] 541 #[test]
542 fn goto_definition_works_for_ufcs_trait_methods_through_self() { 542 fn goto_def_for_ufcs_trait_methods_through_self() {
543 check_goto( 543 check_goto(
544 " 544 "
545 //- /lib.rs 545 //- /lib.rs
@@ -654,7 +654,7 @@ mod tests {
654 } 654 }
655 655
656 #[test] 656 #[test]
657 fn goto_definition_works_when_used_on_definition_name_itself() { 657 fn goto_def_when_used_on_definition_name_itself() {
658 check_goto( 658 check_goto(
659 " 659 "
660 //- /lib.rs 660 //- /lib.rs
@@ -875,4 +875,21 @@ mod tests {
875 "x", 875 "x",
876 ); 876 );
877 } 877 }
878
879 #[test]
880 fn goto_def_for_field_init_shorthand() {
881 covers!(goto_def_for_field_init_shorthand);
882 check_goto(
883 "
884 //- /lib.rs
885 struct Foo { x: i32 }
886 fn main() {
887 let x = 92;
888 Foo { x<|> };
889 }
890 ",
891 "x RECORD_FIELD_DEF FileId(1) [13; 19) [13; 14)",
892 "x: i32|x",
893 )
894 }
878} 895}
diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs
index 848ae4dc7..077a44473 100644
--- a/crates/ra_ide/src/marks.rs
+++ b/crates/ra_ide/src/marks.rs
@@ -3,10 +3,11 @@
3test_utils::marks!( 3test_utils::marks!(
4 inserts_angle_brackets_for_generics 4 inserts_angle_brackets_for_generics
5 inserts_parens_for_function_calls 5 inserts_parens_for_function_calls
6 goto_definition_works_for_macros 6 goto_def_for_macros
7 goto_definition_works_for_methods 7 goto_def_for_methods
8 goto_definition_works_for_fields 8 goto_def_for_fields
9 goto_definition_works_for_record_fields 9 goto_def_for_record_fields
10 goto_def_for_field_init_shorthand
10 call_info_bad_offset 11 call_info_bad_offset
11 dont_complete_current_use 12 dont_complete_current_use
12 dont_complete_primitive_in_use 13 dont_complete_primitive_in_use
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index c1f091ec0..3483a7176 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -134,21 +134,22 @@ pub(crate) fn classify_name_ref(
134 let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None); 134 let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None);
135 135
136 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 136 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
137 tested_by!(goto_definition_works_for_methods); 137 tested_by!(goto_def_for_methods);
138 if let Some(func) = analyzer.resolve_method_call(&method_call) { 138 if let Some(func) = analyzer.resolve_method_call(&method_call) {
139 return Some(from_assoc_item(db, func.into())); 139 return Some(from_assoc_item(db, func.into()));
140 } 140 }
141 } 141 }
142 142
143 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { 143 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
144 tested_by!(goto_definition_works_for_fields); 144 tested_by!(goto_def_for_fields);
145 if let Some(field) = analyzer.resolve_field(&field_expr) { 145 if let Some(field) = analyzer.resolve_field(&field_expr) {
146 return Some(from_struct_field(db, field)); 146 return Some(from_struct_field(db, field));
147 } 147 }
148 } 148 }
149 149
150 if let Some(record_field) = ast::RecordField::cast(parent.clone()) { 150 if let Some(record_field) = ast::RecordField::cast(parent.clone()) {
151 tested_by!(goto_definition_works_for_record_fields); 151 tested_by!(goto_def_for_record_fields);
152 tested_by!(goto_def_for_field_init_shorthand);
152 if let Some(field_def) = analyzer.resolve_record_field(&record_field) { 153 if let Some(field_def) = analyzer.resolve_record_field(&record_field) {
153 return Some(from_struct_field(db, field_def)); 154 return Some(from_struct_field(db, field_def));
154 } 155 }
@@ -160,7 +161,7 @@ pub(crate) fn classify_name_ref(
160 let visibility = None; 161 let visibility = None;
161 162
162 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 163 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
163 tested_by!(goto_definition_works_for_macros); 164 tested_by!(goto_def_for_macros);
164 if let Some(macro_def) = analyzer.resolve_macro_call(db, name_ref.with_value(&macro_call)) { 165 if let Some(macro_def) = analyzer.resolve_macro_call(db, name_ref.with_value(&macro_call)) {
165 let kind = NameKind::Macro(macro_def); 166 let kind = NameKind::Macro(macro_def);
166 return Some(NameDefinition { kind, container, visibility }); 167 return Some(NameDefinition { kind, container, visibility });