diff options
Diffstat (limited to 'crates/ide/src/goto_definition.rs')
-rw-r--r-- | crates/ide/src/goto_definition.rs | 237 |
1 files changed, 161 insertions, 76 deletions
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 912144f8b..cd4afc804 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -1,14 +1,18 @@ | |||
1 | use either::Either; | 1 | use either::Either; |
2 | use hir::Semantics; | 2 | use hir::{HasAttrs, ModuleDef, Semantics}; |
3 | use ide_db::{ | 3 | use ide_db::{ |
4 | base_db::FileId, | 4 | base_db::FileId, |
5 | defs::{NameClass, NameRefClass}, | 5 | defs::{Definition, NameClass, NameRefClass}, |
6 | symbol_index, RootDatabase, | 6 | symbol_index, RootDatabase, |
7 | }; | 7 | }; |
8 | use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; | 8 | use syntax::{ |
9 | ast, match_ast, AstNode, AstToken, SyntaxKind::*, SyntaxToken, TextSize, TokenAtOffset, T, | ||
10 | }; | ||
9 | 11 | ||
10 | use crate::{ | 12 | use crate::{ |
11 | display::{ToNav, TryToNav}, | 13 | display::{ToNav, TryToNav}, |
14 | doc_links::extract_definitions_from_markdown, | ||
15 | runnables::doc_owner_to_def, | ||
12 | FilePosition, NavigationTarget, RangeInfo, SymbolKind, | 16 | FilePosition, NavigationTarget, RangeInfo, SymbolKind, |
13 | }; | 17 | }; |
14 | 18 | ||
@@ -30,6 +34,10 @@ pub(crate) fn goto_definition( | |||
30 | let original_token = pick_best(file.token_at_offset(position.offset))?; | 34 | let original_token = pick_best(file.token_at_offset(position.offset))?; |
31 | let token = sema.descend_into_macros(original_token.clone()); | 35 | let token = sema.descend_into_macros(original_token.clone()); |
32 | let parent = token.parent(); | 36 | let parent = token.parent(); |
37 | if let Some(comment) = ast::Comment::cast(token.clone()) { | ||
38 | let nav = def_for_doc_comment(&sema, position, &comment)?.try_to_nav(db)?; | ||
39 | return Some(RangeInfo::new(original_token.text_range(), vec![nav])); | ||
40 | } | ||
33 | 41 | ||
34 | let nav_targets = match_ast! { | 42 | let nav_targets = match_ast! { |
35 | match parent { | 43 | match parent { |
@@ -68,11 +76,58 @@ pub(crate) fn goto_definition( | |||
68 | Some(RangeInfo::new(original_token.text_range(), nav_targets)) | 76 | Some(RangeInfo::new(original_token.text_range(), nav_targets)) |
69 | } | 77 | } |
70 | 78 | ||
79 | fn def_for_doc_comment( | ||
80 | sema: &Semantics<RootDatabase>, | ||
81 | position: FilePosition, | ||
82 | doc_comment: &ast::Comment, | ||
83 | ) -> Option<hir::ModuleDef> { | ||
84 | let parent = doc_comment.syntax().parent(); | ||
85 | let (link, ns) = extract_positioned_link_from_comment(position, doc_comment)?; | ||
86 | |||
87 | let def = doc_owner_to_def(sema, parent)?; | ||
88 | match def { | ||
89 | Definition::ModuleDef(def) => match def { | ||
90 | ModuleDef::Module(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
91 | ModuleDef::Function(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
92 | ModuleDef::Adt(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
93 | ModuleDef::Variant(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
94 | ModuleDef::Const(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
95 | ModuleDef::Static(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
96 | ModuleDef::Trait(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
97 | ModuleDef::TypeAlias(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
98 | ModuleDef::BuiltinType(_) => return None, | ||
99 | }, | ||
100 | Definition::Macro(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
101 | Definition::Field(it) => it.resolve_doc_path(sema.db, &link, ns), | ||
102 | Definition::SelfType(_) | ||
103 | | Definition::Local(_) | ||
104 | | Definition::GenericParam(_) | ||
105 | | Definition::Label(_) => return None, | ||
106 | } | ||
107 | } | ||
108 | |||
109 | fn extract_positioned_link_from_comment( | ||
110 | position: FilePosition, | ||
111 | comment: &ast::Comment, | ||
112 | ) -> Option<(String, Option<hir::Namespace>)> { | ||
113 | let comment_range = comment.syntax().text_range(); | ||
114 | let doc_comment = comment.doc_comment()?; | ||
115 | let def_links = extract_definitions_from_markdown(doc_comment); | ||
116 | let (def_link, ns, _) = def_links.iter().min_by_key(|(_, _, def_link_range)| { | ||
117 | let matched_position = comment_range.start() + TextSize::from(def_link_range.start as u32); | ||
118 | match position.offset.checked_sub(matched_position) { | ||
119 | Some(distance) => distance, | ||
120 | None => comment_range.end(), | ||
121 | } | ||
122 | })?; | ||
123 | Some((def_link.to_string(), ns.clone())) | ||
124 | } | ||
125 | |||
71 | fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | 126 | fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { |
72 | return tokens.max_by_key(priority); | 127 | return tokens.max_by_key(priority); |
73 | fn priority(n: &SyntaxToken) -> usize { | 128 | fn priority(n: &SyntaxToken) -> usize { |
74 | match n.kind() { | 129 | match n.kind() { |
75 | IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] => 2, | 130 | IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | COMMENT => 2, |
76 | kind if kind.is_trivia() => 0, | 131 | kind if kind.is_trivia() => 0, |
77 | _ => 1, | 132 | _ => 1, |
78 | } | 133 | } |
@@ -166,7 +221,7 @@ mod tests { | |||
166 | check( | 221 | check( |
167 | r#" | 222 | r#" |
168 | //- /main.rs crate:main deps:std | 223 | //- /main.rs crate:main deps:std |
169 | extern crate std<|>; | 224 | extern crate std$0; |
170 | //- /std/lib.rs crate:std | 225 | //- /std/lib.rs crate:std |
171 | // empty | 226 | // empty |
172 | //^ file | 227 | //^ file |
@@ -179,7 +234,7 @@ mod tests { | |||
179 | check( | 234 | check( |
180 | r#" | 235 | r#" |
181 | //- /main.rs crate:main deps:std | 236 | //- /main.rs crate:main deps:std |
182 | extern crate std as abc<|>; | 237 | extern crate std as abc$0; |
183 | //- /std/lib.rs crate:std | 238 | //- /std/lib.rs crate:std |
184 | // empty | 239 | // empty |
185 | //^ file | 240 | //^ file |
@@ -193,7 +248,7 @@ mod tests { | |||
193 | r#" | 248 | r#" |
194 | struct Foo; | 249 | struct Foo; |
195 | //^^^ | 250 | //^^^ |
196 | enum E { X(Foo<|>) } | 251 | enum E { X(Foo$0) } |
197 | "#, | 252 | "#, |
198 | ); | 253 | ); |
199 | } | 254 | } |
@@ -204,7 +259,7 @@ enum E { X(Foo<|>) } | |||
204 | r#" | 259 | r#" |
205 | struct Foo; | 260 | struct Foo; |
206 | //^^^ | 261 | //^^^ |
207 | enum E { X(<|>Foo) } | 262 | enum E { X($0Foo) } |
208 | "#, | 263 | "#, |
209 | ); | 264 | ); |
210 | } | 265 | } |
@@ -217,7 +272,7 @@ enum E { X(<|>Foo) } | |||
217 | use a::Foo; | 272 | use a::Foo; |
218 | mod a; | 273 | mod a; |
219 | mod b; | 274 | mod b; |
220 | enum E { X(Foo<|>) } | 275 | enum E { X(Foo$0) } |
221 | 276 | ||
222 | //- /a.rs | 277 | //- /a.rs |
223 | struct Foo; | 278 | struct Foo; |
@@ -233,7 +288,7 @@ struct Foo; | |||
233 | check( | 288 | check( |
234 | r#" | 289 | r#" |
235 | //- /lib.rs | 290 | //- /lib.rs |
236 | mod <|>foo; | 291 | mod $0foo; |
237 | 292 | ||
238 | //- /foo.rs | 293 | //- /foo.rs |
239 | // empty | 294 | // empty |
@@ -244,7 +299,7 @@ mod <|>foo; | |||
244 | check( | 299 | check( |
245 | r#" | 300 | r#" |
246 | //- /lib.rs | 301 | //- /lib.rs |
247 | mod <|>foo; | 302 | mod $0foo; |
248 | 303 | ||
249 | //- /foo/mod.rs | 304 | //- /foo/mod.rs |
250 | // empty | 305 | // empty |
@@ -260,7 +315,7 @@ mod <|>foo; | |||
260 | macro_rules! foo { () => { () } } | 315 | macro_rules! foo { () => { () } } |
261 | //^^^ | 316 | //^^^ |
262 | fn bar() { | 317 | fn bar() { |
263 | <|>foo!(); | 318 | $0foo!(); |
264 | } | 319 | } |
265 | "#, | 320 | "#, |
266 | ); | 321 | ); |
@@ -273,7 +328,7 @@ fn bar() { | |||
273 | //- /lib.rs | 328 | //- /lib.rs |
274 | use foo::foo; | 329 | use foo::foo; |
275 | fn bar() { | 330 | fn bar() { |
276 | <|>foo!(); | 331 | $0foo!(); |
277 | } | 332 | } |
278 | 333 | ||
279 | //- /foo/lib.rs | 334 | //- /foo/lib.rs |
@@ -289,7 +344,7 @@ macro_rules! foo { () => { () } } | |||
289 | check( | 344 | check( |
290 | r#" | 345 | r#" |
291 | //- /lib.rs | 346 | //- /lib.rs |
292 | use foo::foo<|>; | 347 | use foo::foo$0; |
293 | 348 | ||
294 | //- /foo/lib.rs | 349 | //- /foo/lib.rs |
295 | #[macro_export] | 350 | #[macro_export] |
@@ -312,7 +367,7 @@ define_fn!(foo); | |||
312 | //^^^ | 367 | //^^^ |
313 | 368 | ||
314 | fn bar() { | 369 | fn bar() { |
315 | <|>foo(); | 370 | $0foo(); |
316 | } | 371 | } |
317 | "#, | 372 | "#, |
318 | ); | 373 | ); |
@@ -331,7 +386,7 @@ macro_rules! define_fn { | |||
331 | //^^^^^^^^^^^^^ | 386 | //^^^^^^^^^^^^^ |
332 | 387 | ||
333 | fn bar() { | 388 | fn bar() { |
334 | <|>foo(); | 389 | $0foo(); |
335 | } | 390 | } |
336 | "#, | 391 | "#, |
337 | ); | 392 | ); |
@@ -347,7 +402,7 @@ macro_rules! foo {() => {0}} | |||
347 | 402 | ||
348 | fn bar() { | 403 | fn bar() { |
349 | match (0,1) { | 404 | match (0,1) { |
350 | (<|>foo!(), _) => {} | 405 | ($0foo!(), _) => {} |
351 | } | 406 | } |
352 | } | 407 | } |
353 | "#, | 408 | "#, |
@@ -363,7 +418,7 @@ macro_rules! foo {() => {0}} | |||
363 | //^^^ | 418 | //^^^ |
364 | fn bar() { | 419 | fn bar() { |
365 | match 0 { | 420 | match 0 { |
366 | <|>foo!() => {} | 421 | $0foo!() => {} |
367 | } | 422 | } |
368 | } | 423 | } |
369 | "#, | 424 | "#, |
@@ -375,7 +430,7 @@ fn bar() { | |||
375 | check( | 430 | check( |
376 | r#" | 431 | r#" |
377 | //- /lib.rs crate:main deps:foo | 432 | //- /lib.rs crate:main deps:foo |
378 | use foo as bar<|>; | 433 | use foo as bar$0; |
379 | 434 | ||
380 | //- /foo/lib.rs crate:foo | 435 | //- /foo/lib.rs crate:foo |
381 | // empty | 436 | // empty |
@@ -389,7 +444,7 @@ use foo as bar<|>; | |||
389 | check( | 444 | check( |
390 | r#" | 445 | r#" |
391 | //- /lib.rs crate:main deps:foo | 446 | //- /lib.rs crate:main deps:foo |
392 | use foo::foo as bar<|>; | 447 | use foo::foo as bar$0; |
393 | 448 | ||
394 | //- /foo/lib.rs crate:foo | 449 | //- /foo/lib.rs crate:foo |
395 | #[macro_export] | 450 | #[macro_export] |
@@ -410,7 +465,7 @@ impl Foo { | |||
410 | } | 465 | } |
411 | 466 | ||
412 | fn bar(foo: &Foo) { | 467 | fn bar(foo: &Foo) { |
413 | foo.frobnicate<|>(); | 468 | foo.frobnicate$0(); |
414 | } | 469 | } |
415 | "#, | 470 | "#, |
416 | ); | 471 | ); |
@@ -425,7 +480,7 @@ struct Foo { | |||
425 | } //^^^^ | 480 | } //^^^^ |
426 | 481 | ||
427 | fn bar(foo: &Foo) { | 482 | fn bar(foo: &Foo) { |
428 | foo.spam<|>; | 483 | foo.spam$0; |
429 | } | 484 | } |
430 | "#, | 485 | "#, |
431 | ); | 486 | ); |
@@ -442,7 +497,7 @@ struct Foo { | |||
442 | 497 | ||
443 | fn bar() -> Foo { | 498 | fn bar() -> Foo { |
444 | Foo { | 499 | Foo { |
445 | spam<|>: 0, | 500 | spam$0: 0, |
446 | } | 501 | } |
447 | } | 502 | } |
448 | "#, | 503 | "#, |
@@ -459,7 +514,7 @@ struct Foo { | |||
459 | } //^^^^ | 514 | } //^^^^ |
460 | 515 | ||
461 | fn bar(foo: Foo) -> Foo { | 516 | fn bar(foo: Foo) -> Foo { |
462 | let Foo { spam<|>: _, } = foo | 517 | let Foo { spam$0: _, } = foo |
463 | } | 518 | } |
464 | "#, | 519 | "#, |
465 | ); | 520 | ); |
@@ -474,7 +529,7 @@ struct Foo { spam: u32 } | |||
474 | //^^^^ | 529 | //^^^^ |
475 | 530 | ||
476 | fn bar() -> Foo { | 531 | fn bar() -> Foo { |
477 | Foo { spam<|>: m!() } | 532 | Foo { spam$0: m!() } |
478 | } | 533 | } |
479 | ", | 534 | ", |
480 | ); | 535 | ); |
@@ -489,7 +544,7 @@ struct Foo(u32); | |||
489 | 544 | ||
490 | fn bar() { | 545 | fn bar() { |
491 | let foo = Foo(0); | 546 | let foo = Foo(0); |
492 | foo.<|>0; | 547 | foo.$00; |
493 | } | 548 | } |
494 | "#, | 549 | "#, |
495 | ); | 550 | ); |
@@ -505,7 +560,7 @@ impl Foo { | |||
505 | } //^^^^^^^^^^ | 560 | } //^^^^^^^^^^ |
506 | 561 | ||
507 | fn bar(foo: &Foo) { | 562 | fn bar(foo: &Foo) { |
508 | Foo::frobnicate<|>(); | 563 | Foo::frobnicate$0(); |
509 | } | 564 | } |
510 | "#, | 565 | "#, |
511 | ); | 566 | ); |
@@ -520,7 +575,7 @@ trait Foo { | |||
520 | } //^^^^^^^^^^ | 575 | } //^^^^^^^^^^ |
521 | 576 | ||
522 | fn bar() { | 577 | fn bar() { |
523 | Foo::frobnicate<|>(); | 578 | Foo::frobnicate$0(); |
524 | } | 579 | } |
525 | "#, | 580 | "#, |
526 | ); | 581 | ); |
@@ -537,7 +592,7 @@ trait Trait { | |||
537 | impl Trait for Foo {} | 592 | impl Trait for Foo {} |
538 | 593 | ||
539 | fn bar() { | 594 | fn bar() { |
540 | Foo::frobnicate<|>(); | 595 | Foo::frobnicate$0(); |
541 | } | 596 | } |
542 | "#, | 597 | "#, |
543 | ); | 598 | ); |
@@ -551,7 +606,7 @@ struct Foo; | |||
551 | impl Foo { | 606 | impl Foo { |
552 | //^^^ | 607 | //^^^ |
553 | pub fn new() -> Self { | 608 | pub fn new() -> Self { |
554 | Self<|> {} | 609 | Self$0 {} |
555 | } | 610 | } |
556 | } | 611 | } |
557 | "#, | 612 | "#, |
@@ -561,7 +616,7 @@ impl Foo { | |||
561 | struct Foo; | 616 | struct Foo; |
562 | impl Foo { | 617 | impl Foo { |
563 | //^^^ | 618 | //^^^ |
564 | pub fn new() -> Self<|> { | 619 | pub fn new() -> Self$0 { |
565 | Self {} | 620 | Self {} |
566 | } | 621 | } |
567 | } | 622 | } |
@@ -573,7 +628,7 @@ impl Foo { | |||
573 | enum Foo { A } | 628 | enum Foo { A } |
574 | impl Foo { | 629 | impl Foo { |
575 | //^^^ | 630 | //^^^ |
576 | pub fn new() -> Self<|> { | 631 | pub fn new() -> Self$0 { |
577 | Foo::A | 632 | Foo::A |
578 | } | 633 | } |
579 | } | 634 | } |
@@ -585,7 +640,7 @@ impl Foo { | |||
585 | enum Foo { A } | 640 | enum Foo { A } |
586 | impl Foo { | 641 | impl Foo { |
587 | //^^^ | 642 | //^^^ |
588 | pub fn thing(a: &Self<|>) { | 643 | pub fn thing(a: &Self$0) { |
589 | } | 644 | } |
590 | } | 645 | } |
591 | "#, | 646 | "#, |
@@ -603,7 +658,7 @@ trait Make { | |||
603 | impl Make for Foo { | 658 | impl Make for Foo { |
604 | //^^^ | 659 | //^^^ |
605 | fn new() -> Self { | 660 | fn new() -> Self { |
606 | Self<|> {} | 661 | Self$0 {} |
607 | } | 662 | } |
608 | } | 663 | } |
609 | "#, | 664 | "#, |
@@ -617,7 +672,7 @@ trait Make { | |||
617 | } | 672 | } |
618 | impl Make for Foo { | 673 | impl Make for Foo { |
619 | //^^^ | 674 | //^^^ |
620 | fn new() -> Self<|> { | 675 | fn new() -> Self$0 { |
621 | Self {} | 676 | Self {} |
622 | } | 677 | } |
623 | } | 678 | } |
@@ -629,7 +684,7 @@ impl Make for Foo { | |||
629 | fn goto_def_when_used_on_definition_name_itself() { | 684 | fn goto_def_when_used_on_definition_name_itself() { |
630 | check( | 685 | check( |
631 | r#" | 686 | r#" |
632 | struct Foo<|> { value: u32 } | 687 | struct Foo$0 { value: u32 } |
633 | //^^^ | 688 | //^^^ |
634 | "#, | 689 | "#, |
635 | ); | 690 | ); |
@@ -637,21 +692,21 @@ struct Foo<|> { value: u32 } | |||
637 | check( | 692 | check( |
638 | r#" | 693 | r#" |
639 | struct Foo { | 694 | struct Foo { |
640 | field<|>: string, | 695 | field$0: string, |
641 | } //^^^^^ | 696 | } //^^^^^ |
642 | "#, | 697 | "#, |
643 | ); | 698 | ); |
644 | 699 | ||
645 | check( | 700 | check( |
646 | r#" | 701 | r#" |
647 | fn foo_test<|>() { } | 702 | fn foo_test$0() { } |
648 | //^^^^^^^^ | 703 | //^^^^^^^^ |
649 | "#, | 704 | "#, |
650 | ); | 705 | ); |
651 | 706 | ||
652 | check( | 707 | check( |
653 | r#" | 708 | r#" |
654 | enum Foo<|> { Variant } | 709 | enum Foo$0 { Variant } |
655 | //^^^ | 710 | //^^^ |
656 | "#, | 711 | "#, |
657 | ); | 712 | ); |
@@ -660,7 +715,7 @@ enum Foo<|> { Variant } | |||
660 | r#" | 715 | r#" |
661 | enum Foo { | 716 | enum Foo { |
662 | Variant1, | 717 | Variant1, |
663 | Variant2<|>, | 718 | Variant2$0, |
664 | //^^^^^^^^ | 719 | //^^^^^^^^ |
665 | Variant3, | 720 | Variant3, |
666 | } | 721 | } |
@@ -669,35 +724,35 @@ enum Foo { | |||
669 | 724 | ||
670 | check( | 725 | check( |
671 | r#" | 726 | r#" |
672 | static INNER<|>: &str = ""; | 727 | static INNER$0: &str = ""; |
673 | //^^^^^ | 728 | //^^^^^ |
674 | "#, | 729 | "#, |
675 | ); | 730 | ); |
676 | 731 | ||
677 | check( | 732 | check( |
678 | r#" | 733 | r#" |
679 | const INNER<|>: &str = ""; | 734 | const INNER$0: &str = ""; |
680 | //^^^^^ | 735 | //^^^^^ |
681 | "#, | 736 | "#, |
682 | ); | 737 | ); |
683 | 738 | ||
684 | check( | 739 | check( |
685 | r#" | 740 | r#" |
686 | type Thing<|> = Option<()>; | 741 | type Thing$0 = Option<()>; |
687 | //^^^^^ | 742 | //^^^^^ |
688 | "#, | 743 | "#, |
689 | ); | 744 | ); |
690 | 745 | ||
691 | check( | 746 | check( |
692 | r#" | 747 | r#" |
693 | trait Foo<|> { } | 748 | trait Foo$0 { } |
694 | //^^^ | 749 | //^^^ |
695 | "#, | 750 | "#, |
696 | ); | 751 | ); |
697 | 752 | ||
698 | check( | 753 | check( |
699 | r#" | 754 | r#" |
700 | mod bar<|> { } | 755 | mod bar$0 { } |
701 | //^^^ | 756 | //^^^ |
702 | "#, | 757 | "#, |
703 | ); | 758 | ); |
@@ -714,7 +769,7 @@ fn foo() {} | |||
714 | //^^^ | 769 | //^^^ |
715 | id! { | 770 | id! { |
716 | fn bar() { | 771 | fn bar() { |
717 | fo<|>o(); | 772 | fo$0o(); |
718 | } | 773 | } |
719 | } | 774 | } |
720 | mod confuse_index { fn foo(); } | 775 | mod confuse_index { fn foo(); } |
@@ -743,7 +798,7 @@ pub mod __export { | |||
743 | fn foo() -> i8 {} | 798 | fn foo() -> i8 {} |
744 | //^^^ | 799 | //^^^ |
745 | fn test() { | 800 | fn test() { |
746 | format!("{}", fo<|>o()) | 801 | format!("{}", fo$0o()) |
747 | } | 802 | } |
748 | "#, | 803 | "#, |
749 | ); | 804 | ); |
@@ -761,7 +816,7 @@ macro_rules! include {} | |||
761 | //^^^^^^^^^^^^^^^^^^^ | 816 | //^^^^^^^^^^^^^^^^^^^ |
762 | 817 | ||
763 | fn f() { | 818 | fn f() { |
764 | foo<|>(); | 819 | foo$0(); |
765 | } | 820 | } |
766 | 821 | ||
767 | mod confuse_index { | 822 | mod confuse_index { |
@@ -778,7 +833,7 @@ fn foo() {} | |||
778 | fn goto_for_type_param() { | 833 | fn goto_for_type_param() { |
779 | check( | 834 | check( |
780 | r#" | 835 | r#" |
781 | struct Foo<T: Clone> { t: <|>T } | 836 | struct Foo<T: Clone> { t: $0T } |
782 | //^ | 837 | //^ |
783 | "#, | 838 | "#, |
784 | ); | 839 | ); |
@@ -796,7 +851,7 @@ fn foo() { | |||
796 | let x = 1; | 851 | let x = 1; |
797 | //^ | 852 | //^ |
798 | id!({ | 853 | id!({ |
799 | let y = <|>x; | 854 | let y = $0x; |
800 | let z = y; | 855 | let z = y; |
801 | }); | 856 | }); |
802 | } | 857 | } |
@@ -814,7 +869,7 @@ fn foo() { | |||
814 | id!({ | 869 | id!({ |
815 | let y = x; | 870 | let y = x; |
816 | //^ | 871 | //^ |
817 | let z = <|>y; | 872 | let z = $0y; |
818 | }); | 873 | }); |
819 | } | 874 | } |
820 | "#, | 875 | "#, |
@@ -829,7 +884,7 @@ fn main() { | |||
829 | fn foo() { | 884 | fn foo() { |
830 | let x = 92; | 885 | let x = 92; |
831 | //^ | 886 | //^ |
832 | <|>x; | 887 | $0x; |
833 | } | 888 | } |
834 | } | 889 | } |
835 | "#, | 890 | "#, |
@@ -843,7 +898,7 @@ fn main() { | |||
843 | fn bar() { | 898 | fn bar() { |
844 | macro_rules! foo { () => { () } } | 899 | macro_rules! foo { () => { () } } |
845 | //^^^ | 900 | //^^^ |
846 | <|>foo!(); | 901 | $0foo!(); |
847 | } | 902 | } |
848 | "#, | 903 | "#, |
849 | ); | 904 | ); |
@@ -857,7 +912,7 @@ struct Foo { x: i32 } | |||
857 | fn main() { | 912 | fn main() { |
858 | let x = 92; | 913 | let x = 92; |
859 | //^ | 914 | //^ |
860 | Foo { x<|> }; | 915 | Foo { x$0 }; |
861 | } | 916 | } |
862 | "#, | 917 | "#, |
863 | ) | 918 | ) |
@@ -872,7 +927,7 @@ enum Foo { | |||
872 | } //^ | 927 | } //^ |
873 | fn baz(foo: Foo) { | 928 | fn baz(foo: Foo) { |
874 | match foo { | 929 | match foo { |
875 | Foo::Bar { x<|> } => x | 930 | Foo::Bar { x$0 } => x |
876 | }; | 931 | }; |
877 | } | 932 | } |
878 | "#, | 933 | "#, |
@@ -887,7 +942,7 @@ enum Foo { Bar } | |||
887 | //^^^ | 942 | //^^^ |
888 | impl Foo { | 943 | impl Foo { |
889 | fn baz(self) { | 944 | fn baz(self) { |
890 | match self { Self::Bar<|> => {} } | 945 | match self { Self::Bar$0 => {} } |
891 | } | 946 | } |
892 | } | 947 | } |
893 | "#, | 948 | "#, |
@@ -902,7 +957,7 @@ enum Foo { Bar { val: i32 } } | |||
902 | //^^^ | 957 | //^^^ |
903 | impl Foo { | 958 | impl Foo { |
904 | fn baz(self) -> i32 { | 959 | fn baz(self) -> i32 { |
905 | match self { Self::Bar<|> { val } => {} } | 960 | match self { Self::Bar$0 { val } => {} } |
906 | } | 961 | } |
907 | } | 962 | } |
908 | "#, | 963 | "#, |
@@ -916,7 +971,7 @@ impl Foo { | |||
916 | enum Foo { Bar } | 971 | enum Foo { Bar } |
917 | //^^^ | 972 | //^^^ |
918 | impl Foo { | 973 | impl Foo { |
919 | fn baz(self) { Self::Bar<|>; } | 974 | fn baz(self) { Self::Bar$0; } |
920 | } | 975 | } |
921 | "#, | 976 | "#, |
922 | ); | 977 | ); |
@@ -929,7 +984,7 @@ impl Foo { | |||
929 | enum Foo { Bar { val: i32 } } | 984 | enum Foo { Bar { val: i32 } } |
930 | //^^^ | 985 | //^^^ |
931 | impl Foo { | 986 | impl Foo { |
932 | fn baz(self) { Self::Bar<|> {val: 4}; } | 987 | fn baz(self) { Self::Bar$0 {val: 4}; } |
933 | } | 988 | } |
934 | "#, | 989 | "#, |
935 | ); | 990 | ); |
@@ -939,7 +994,7 @@ impl Foo { | |||
939 | fn goto_def_for_type_alias_generic_parameter() { | 994 | fn goto_def_for_type_alias_generic_parameter() { |
940 | check( | 995 | check( |
941 | r#" | 996 | r#" |
942 | type Alias<T> = T<|>; | 997 | type Alias<T> = T$0; |
943 | //^ | 998 | //^ |
944 | "#, | 999 | "#, |
945 | ) | 1000 | ) |
@@ -950,7 +1005,7 @@ type Alias<T> = T<|>; | |||
950 | check( | 1005 | check( |
951 | r#" | 1006 | r#" |
952 | //- /lib.rs | 1007 | //- /lib.rs |
953 | foo::module<|>::mac!(); | 1008 | foo::module$0::mac!(); |
954 | 1009 | ||
955 | //- /foo/lib.rs | 1010 | //- /foo/lib.rs |
956 | pub mod module { | 1011 | pub mod module { |
@@ -972,7 +1027,7 @@ trait Iterator { | |||
972 | //^^^^ | 1027 | //^^^^ |
973 | } | 1028 | } |
974 | 1029 | ||
975 | fn f() -> impl Iterator<Item<|> = u8> {} | 1030 | fn f() -> impl Iterator<Item$0 = u8> {} |
976 | "#, | 1031 | "#, |
977 | ); | 1032 | ); |
978 | } | 1033 | } |
@@ -987,7 +1042,7 @@ trait Iterator { | |||
987 | type B; | 1042 | type B; |
988 | } | 1043 | } |
989 | 1044 | ||
990 | fn f() -> impl Iterator<A<|> = u8, B = ()> {} | 1045 | fn f() -> impl Iterator<A$0 = u8, B = ()> {} |
991 | "#, | 1046 | "#, |
992 | ); | 1047 | ); |
993 | check( | 1048 | check( |
@@ -998,7 +1053,7 @@ trait Iterator { | |||
998 | //^ | 1053 | //^ |
999 | } | 1054 | } |
1000 | 1055 | ||
1001 | fn f() -> impl Iterator<A = u8, B<|> = ()> {} | 1056 | fn f() -> impl Iterator<A = u8, B$0 = ()> {} |
1002 | "#, | 1057 | "#, |
1003 | ); | 1058 | ); |
1004 | } | 1059 | } |
@@ -1012,7 +1067,7 @@ trait Iterator { | |||
1012 | //^^^^ | 1067 | //^^^^ |
1013 | } | 1068 | } |
1014 | 1069 | ||
1015 | fn g() -> <() as Iterator<Item<|> = ()>>::Item {} | 1070 | fn g() -> <() as Iterator<Item$0 = ()>>::Item {} |
1016 | "#, | 1071 | "#, |
1017 | ); | 1072 | ); |
1018 | } | 1073 | } |
@@ -1027,7 +1082,7 @@ trait Iterator { | |||
1027 | type B; | 1082 | type B; |
1028 | } | 1083 | } |
1029 | 1084 | ||
1030 | fn g() -> <() as Iterator<A<|> = (), B = u8>>::B {} | 1085 | fn g() -> <() as Iterator<A$0 = (), B = u8>>::B {} |
1031 | "#, | 1086 | "#, |
1032 | ); | 1087 | ); |
1033 | check( | 1088 | check( |
@@ -1038,7 +1093,7 @@ trait Iterator { | |||
1038 | //^ | 1093 | //^ |
1039 | } | 1094 | } |
1040 | 1095 | ||
1041 | fn g() -> <() as Iterator<A = (), B<|> = u8>>::A {} | 1096 | fn g() -> <() as Iterator<A = (), B$0 = u8>>::A {} |
1042 | "#, | 1097 | "#, |
1043 | ); | 1098 | ); |
1044 | } | 1099 | } |
@@ -1052,7 +1107,7 @@ struct Foo {} | |||
1052 | impl Foo { | 1107 | impl Foo { |
1053 | fn bar(self: &Foo) { | 1108 | fn bar(self: &Foo) { |
1054 | //^^^^ | 1109 | //^^^^ |
1055 | let foo = sel<|>f; | 1110 | let foo = sel$0f; |
1056 | } | 1111 | } |
1057 | }"#, | 1112 | }"#, |
1058 | ) | 1113 | ) |
@@ -1065,7 +1120,7 @@ impl Foo { | |||
1065 | struct Foo {} | 1120 | struct Foo {} |
1066 | 1121 | ||
1067 | impl Foo { | 1122 | impl Foo { |
1068 | fn bar(&self<|>) { | 1123 | fn bar(&self$0) { |
1069 | //^^^^ | 1124 | //^^^^ |
1070 | } | 1125 | } |
1071 | }"#, | 1126 | }"#, |
@@ -1076,7 +1131,7 @@ impl Foo { | |||
1076 | fn goto_lifetime_param_on_decl() { | 1131 | fn goto_lifetime_param_on_decl() { |
1077 | check( | 1132 | check( |
1078 | r#" | 1133 | r#" |
1079 | fn foo<'foobar<|>>(_: &'foobar ()) { | 1134 | fn foo<'foobar$0>(_: &'foobar ()) { |
1080 | //^^^^^^^ | 1135 | //^^^^^^^ |
1081 | }"#, | 1136 | }"#, |
1082 | ) | 1137 | ) |
@@ -1086,7 +1141,7 @@ fn foo<'foobar<|>>(_: &'foobar ()) { | |||
1086 | fn goto_lifetime_param_decl() { | 1141 | fn goto_lifetime_param_decl() { |
1087 | check( | 1142 | check( |
1088 | r#" | 1143 | r#" |
1089 | fn foo<'foobar>(_: &'foobar<|> ()) { | 1144 | fn foo<'foobar>(_: &'foobar$0 ()) { |
1090 | //^^^^^^^ | 1145 | //^^^^^^^ |
1091 | }"#, | 1146 | }"#, |
1092 | ) | 1147 | ) |
@@ -1097,7 +1152,7 @@ fn foo<'foobar>(_: &'foobar<|> ()) { | |||
1097 | check( | 1152 | check( |
1098 | r#" | 1153 | r#" |
1099 | fn foo<'foobar>(_: &'foobar ()) { | 1154 | fn foo<'foobar>(_: &'foobar ()) { |
1100 | fn foo<'foobar>(_: &'foobar<|> ()) {} | 1155 | fn foo<'foobar>(_: &'foobar$0 ()) {} |
1101 | //^^^^^^^ | 1156 | //^^^^^^^ |
1102 | }"#, | 1157 | }"#, |
1103 | ) | 1158 | ) |
@@ -1108,13 +1163,13 @@ fn foo<'foobar>(_: &'foobar ()) { | |||
1108 | fn goto_lifetime_hrtb() { | 1163 | fn goto_lifetime_hrtb() { |
1109 | check( | 1164 | check( |
1110 | r#"trait Foo<T> {} | 1165 | r#"trait Foo<T> {} |
1111 | fn foo<T>() where for<'a> T: Foo<&'a<|> (u8, u16)>, {} | 1166 | fn foo<T>() where for<'a> T: Foo<&'a$0 (u8, u16)>, {} |
1112 | //^^ | 1167 | //^^ |
1113 | "#, | 1168 | "#, |
1114 | ); | 1169 | ); |
1115 | check( | 1170 | check( |
1116 | r#"trait Foo<T> {} | 1171 | r#"trait Foo<T> {} |
1117 | fn foo<T>() where for<'a<|>> T: Foo<&'a (u8, u16)>, {} | 1172 | fn foo<T>() where for<'a$0> T: Foo<&'a (u8, u16)>, {} |
1118 | //^^ | 1173 | //^^ |
1119 | "#, | 1174 | "#, |
1120 | ); | 1175 | ); |
@@ -1125,7 +1180,7 @@ fn foo<T>() where for<'a<|>> T: Foo<&'a (u8, u16)>, {} | |||
1125 | fn goto_lifetime_hrtb_for_type() { | 1180 | fn goto_lifetime_hrtb_for_type() { |
1126 | check( | 1181 | check( |
1127 | r#"trait Foo<T> {} | 1182 | r#"trait Foo<T> {} |
1128 | fn foo<T>() where T: for<'a> Foo<&'a<|> (u8, u16)>, {} | 1183 | fn foo<T>() where T: for<'a> Foo<&'a$0 (u8, u16)>, {} |
1129 | //^^ | 1184 | //^^ |
1130 | "#, | 1185 | "#, |
1131 | ); | 1186 | ); |
@@ -1139,10 +1194,40 @@ fn foo<'foo>(_: &'foo ()) { | |||
1139 | 'foo: { | 1194 | 'foo: { |
1140 | //^^^^ | 1195 | //^^^^ |
1141 | 'bar: loop { | 1196 | 'bar: loop { |
1142 | break 'foo<|>; | 1197 | break 'foo$0; |
1143 | } | 1198 | } |
1144 | } | 1199 | } |
1145 | }"#, | 1200 | }"#, |
1146 | ) | 1201 | ) |
1147 | } | 1202 | } |
1203 | |||
1204 | #[test] | ||
1205 | fn goto_def_for_intra_doc_link_same_file() { | ||
1206 | check( | ||
1207 | r#" | ||
1208 | /// Blah, [`bar`](bar) .. [`foo`](foo)$0 has [`bar`](bar) | ||
1209 | pub fn bar() { } | ||
1210 | |||
1211 | /// You might want to see [`std::fs::read()`] too. | ||
1212 | pub fn foo() { } | ||
1213 | //^^^ | ||
1214 | |||
1215 | }"#, | ||
1216 | ) | ||
1217 | } | ||
1218 | |||
1219 | #[test] | ||
1220 | fn goto_def_for_intra_doc_link_inner() { | ||
1221 | check( | ||
1222 | r#" | ||
1223 | //- /main.rs | ||
1224 | mod m; | ||
1225 | struct S; | ||
1226 | //^ | ||
1227 | |||
1228 | //- /m.rs | ||
1229 | //! [`super::S$0`] | ||
1230 | "#, | ||
1231 | ) | ||
1232 | } | ||
1148 | } | 1233 | } |