diff options
Diffstat (limited to 'crates/ra_ide/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 110 |
1 files changed, 90 insertions, 20 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 184555792..79d332e8c 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,44 @@ mod tests { | |||
425 | } | 425 | } |
426 | 426 | ||
427 | #[test] | 427 | #[test] |
428 | fn goto_definition_works_for_methods() { | 428 | fn goto_definition_works_for_macro_inside_pattern() { |
429 | covers!(goto_definition_works_for_methods); | 429 | check_goto( |
430 | " | ||
431 | //- /lib.rs | ||
432 | macro_rules! foo {() => {0}} | ||
433 | |||
434 | fn bar() { | ||
435 | match (0,1) { | ||
436 | (<|>foo!(), _) => {} | ||
437 | } | ||
438 | } | ||
439 | ", | ||
440 | "foo MACRO_CALL FileId(1) [0; 28) [13; 16)", | ||
441 | "macro_rules! foo {() => {0}}|foo", | ||
442 | ); | ||
443 | } | ||
444 | |||
445 | #[test] | ||
446 | fn goto_definition_works_for_macro_inside_match_arm_lhs() { | ||
447 | check_goto( | ||
448 | " | ||
449 | //- /lib.rs | ||
450 | macro_rules! foo {() => {0}} | ||
451 | |||
452 | fn bar() { | ||
453 | match 0 { | ||
454 | <|>foo!() => {} | ||
455 | } | ||
456 | } | ||
457 | ", | ||
458 | "foo MACRO_CALL FileId(1) [0; 28) [13; 16)", | ||
459 | "macro_rules! foo {() => {0}}|foo", | ||
460 | ); | ||
461 | } | ||
462 | |||
463 | #[test] | ||
464 | fn goto_def_for_methods() { | ||
465 | covers!(goto_def_for_methods); | ||
430 | check_goto( | 466 | check_goto( |
431 | " | 467 | " |
432 | //- /lib.rs | 468 | //- /lib.rs |
@@ -445,8 +481,8 @@ mod tests { | |||
445 | } | 481 | } |
446 | 482 | ||
447 | #[test] | 483 | #[test] |
448 | fn goto_definition_works_for_fields() { | 484 | fn goto_def_for_fields() { |
449 | covers!(goto_definition_works_for_fields); | 485 | covers!(goto_def_for_fields); |
450 | check_goto( | 486 | check_goto( |
451 | " | 487 | " |
452 | //- /lib.rs | 488 | //- /lib.rs |
@@ -464,8 +500,8 @@ mod tests { | |||
464 | } | 500 | } |
465 | 501 | ||
466 | #[test] | 502 | #[test] |
467 | fn goto_definition_works_for_record_fields() { | 503 | fn goto_def_for_record_fields() { |
468 | covers!(goto_definition_works_for_record_fields); | 504 | covers!(goto_def_for_record_fields); |
469 | check_goto( | 505 | check_goto( |
470 | " | 506 | " |
471 | //- /lib.rs | 507 | //- /lib.rs |
@@ -502,7 +538,7 @@ mod tests { | |||
502 | } | 538 | } |
503 | 539 | ||
504 | #[test] | 540 | #[test] |
505 | fn goto_definition_works_for_ufcs_inherent_methods() { | 541 | fn goto_def_for_ufcs_inherent_methods() { |
506 | check_goto( | 542 | check_goto( |
507 | " | 543 | " |
508 | //- /lib.rs | 544 | //- /lib.rs |
@@ -521,7 +557,7 @@ mod tests { | |||
521 | } | 557 | } |
522 | 558 | ||
523 | #[test] | 559 | #[test] |
524 | fn goto_definition_works_for_ufcs_trait_methods_through_traits() { | 560 | fn goto_def_for_ufcs_trait_methods_through_traits() { |
525 | check_goto( | 561 | check_goto( |
526 | " | 562 | " |
527 | //- /lib.rs | 563 | //- /lib.rs |
@@ -539,7 +575,7 @@ mod tests { | |||
539 | } | 575 | } |
540 | 576 | ||
541 | #[test] | 577 | #[test] |
542 | fn goto_definition_works_for_ufcs_trait_methods_through_self() { | 578 | fn goto_def_for_ufcs_trait_methods_through_self() { |
543 | check_goto( | 579 | check_goto( |
544 | " | 580 | " |
545 | //- /lib.rs | 581 | //- /lib.rs |
@@ -654,7 +690,7 @@ mod tests { | |||
654 | } | 690 | } |
655 | 691 | ||
656 | #[test] | 692 | #[test] |
657 | fn goto_definition_works_when_used_on_definition_name_itself() { | 693 | fn goto_def_when_used_on_definition_name_itself() { |
658 | check_goto( | 694 | check_goto( |
659 | " | 695 | " |
660 | //- /lib.rs | 696 | //- /lib.rs |
@@ -858,4 +894,38 @@ mod tests { | |||
858 | "y", | 894 | "y", |
859 | ); | 895 | ); |
860 | } | 896 | } |
897 | |||
898 | #[test] | ||
899 | fn goto_def_in_local_fn() { | ||
900 | check_goto( | ||
901 | " | ||
902 | //- /lib.rs | ||
903 | fn main() { | ||
904 | fn foo() { | ||
905 | let x = 92; | ||
906 | <|>x; | ||
907 | } | ||
908 | } | ||
909 | ", | ||
910 | "x BIND_PAT FileId(1) [39; 40)", | ||
911 | "x", | ||
912 | ); | ||
913 | } | ||
914 | |||
915 | #[test] | ||
916 | fn goto_def_for_field_init_shorthand() { | ||
917 | covers!(goto_def_for_field_init_shorthand); | ||
918 | check_goto( | ||
919 | " | ||
920 | //- /lib.rs | ||
921 | struct Foo { x: i32 } | ||
922 | fn main() { | ||
923 | let x = 92; | ||
924 | Foo { x<|> }; | ||
925 | } | ||
926 | ", | ||
927 | "x RECORD_FIELD_DEF FileId(1) [13; 19) [13; 14)", | ||
928 | "x: i32|x", | ||
929 | ) | ||
930 | } | ||
861 | } | 931 | } |