@@ -492,7 +492,7 @@ mod tests {
492492
493493 #[ test]
494494 fn exclude_tests ( ) {
495- check (
495+ check_with_filters (
496496 r#"
497497fn test_func() {}
498498
@@ -505,6 +505,9 @@ fn test() {
505505 test_func();
506506}
507507"# ,
508+ false ,
509+ false ,
510+ false ,
508511 expect ! [ [ r#"
509512 test_func Function FileId(0) 0..17 3..12
510513
@@ -513,7 +516,7 @@ fn test() {
513516 "# ] ] ,
514517 ) ;
515518
516- check (
519+ check_with_filters (
517520 r#"
518521fn test_func() {}
519522
@@ -526,13 +529,113 @@ fn test() {
526529 test_func();
527530}
528531"# ,
532+ false ,
533+ false ,
534+ false ,
529535 expect ! [ [ r#"
530536 test_func Function FileId(0) 0..17 3..12
531537
532538 FileId(0) 35..44
533539 FileId(0) 96..105 test
534540 "# ] ] ,
535541 ) ;
542+
543+ check_with_filters (
544+ r#"
545+ fn test_func() {}
546+
547+ fn func() {
548+ test_func$0();
549+ }
550+
551+ #[test]
552+ fn test() {
553+ test_func();
554+ }
555+ "# ,
556+ false ,
557+ true ,
558+ false ,
559+ expect ! [ [ r#"
560+ test_func Function FileId(0) 0..17 3..12
561+
562+ FileId(0) 35..44
563+ "# ] ] ,
564+ ) ;
565+ }
566+
567+ #[ test]
568+ fn exclude_library_refs_filtering ( ) {
569+ // exclude refs in 3rd party lib
570+ check_with_filters (
571+ r#"
572+ //- /main.rs crate:main deps:dep
573+ use dep::foo;
574+
575+ fn main() {
576+ foo$0();
577+ }
578+
579+ //- /dep/lib.rs crate:dep new_source_root:library
580+ pub fn foo() {}
581+
582+ pub fn also_calls_foo() {
583+ foo();
584+ }
585+ "# ,
586+ false ,
587+ false ,
588+ true ,
589+ expect ! [ [ r#"
590+ FileId(0) 9..12 import
591+ FileId(0) 31..34
592+ "# ] ] ,
593+ ) ;
594+
595+ // exclude refs in stdlib
596+ check_with_filters (
597+ r#"
598+ //- minicore: option
599+ fn main() {
600+ let _ = core::option::Option::Some$0(0);
601+ }
602+ "# ,
603+ false ,
604+ false ,
605+ true ,
606+ expect ! [ [ r#"
607+ FileId(0) 46..50
608+ "# ] ] ,
609+ ) ;
610+
611+ // keep refs in local lib
612+ check_with_filters (
613+ r#"
614+ //- /main.rs crate:main deps:dep
615+ use dep::foo;
616+
617+ fn main() {
618+ foo$0();
619+ }
620+
621+ //- /dep/lib.rs crate:dep
622+ pub fn foo() {}
623+
624+ pub fn also_calls_foo() {
625+ foo();
626+ }
627+ "# ,
628+ false ,
629+ false ,
630+ true ,
631+ expect ! [ [ r#"
632+ foo Function FileId(1) 0..15 7..10
633+
634+ FileId(0) 9..12 import
635+ FileId(0) 31..34
636+ FileId(1) 47..50
637+ "# ] ] ,
638+ ) ;
536639 }
537640
538641 #[ test]
@@ -1579,18 +1682,49 @@ fn main() {
15791682 }
15801683
15811684 fn check ( #[ rust_analyzer:: rust_fixture] ra_fixture : & str , expect : Expect ) {
1582- check_with_scope ( ra_fixture, None , expect)
1685+ check_with_filters ( ra_fixture, false , false , false , expect)
1686+ }
1687+
1688+ fn check_with_filters (
1689+ #[ rust_analyzer:: rust_fixture] ra_fixture : & str ,
1690+ exclude_imports : bool ,
1691+ exclude_tests : bool ,
1692+ exclude_library_refs : bool ,
1693+ expect : Expect ,
1694+ ) {
1695+ check_with_scope_and_filters (
1696+ ra_fixture,
1697+ None ,
1698+ exclude_imports,
1699+ exclude_tests,
1700+ exclude_library_refs,
1701+ expect,
1702+ )
15831703 }
15841704
15851705 fn check_with_scope (
15861706 #[ rust_analyzer:: rust_fixture] ra_fixture : & str ,
15871707 search_scope : Option < & mut dyn FnMut ( & RootDatabase ) -> SearchScope > ,
15881708 expect : Expect ,
1709+ ) {
1710+ check_with_scope_and_filters ( ra_fixture, search_scope, false , false , false , expect)
1711+ }
1712+
1713+ fn check_with_scope_and_filters (
1714+ #[ rust_analyzer:: rust_fixture] ra_fixture : & str ,
1715+ search_scope : Option < & mut dyn FnMut ( & RootDatabase ) -> SearchScope > ,
1716+ exclude_imports : bool ,
1717+ exclude_tests : bool ,
1718+ exclude_library_refs : bool ,
1719+ expect : Expect ,
15891720 ) {
15901721 let ( analysis, pos) = fixture:: position ( ra_fixture) ;
15911722 let config = FindAllRefsConfig {
15921723 search_scope : search_scope. map ( |it| it ( & analysis. db ) ) ,
15931724 ra_fixture : RaFixtureConfig :: default ( ) ,
1725+ exclude_imports,
1726+ exclude_tests,
1727+ exclude_library_refs,
15941728 exclude_imports : false ,
15951729 exclude_tests : false ,
15961730 exclude_library_refs : false ,
0 commit comments