Skip to content

Commit 7490a86

Browse files
committed
internal: auto exclude
1 parent bacf7e5 commit 7490a86

7 files changed

Lines changed: 43 additions & 64 deletions

File tree

crates/ide-db/src/search.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'a> FindUsages<'a> {
615615
search_scope: &SearchScope,
616616
name: &str,
617617
) -> bool {
618-
if self.scope.is_some() || self.exclude_library_files {
618+
if self.scope.is_some() {
619619
return false;
620620
}
621621

@@ -897,12 +897,16 @@ impl<'a> FindUsages<'a> {
897897
let finder = Finder::new(name.as_bytes());
898898
// The search for `Self` may return duplicate results with `ContainerName`, so deduplicate them.
899899
let mut self_positions = FxHashSet::default();
900+
let is_possibly_self = is_possibly_self.into_iter().filter(|position| {
901+
!self.exclude_library_files
902+
|| !is_library_file(self.sema.db, position.file_id.file_id(self.sema.db))
903+
});
900904
tracing::info_span!("Self_search").in_scope(|| {
901905
search(
902906
self,
903907
&finder,
904908
name,
905-
is_possibly_self.into_iter().map(|position| {
909+
is_possibly_self.map(|position| {
906910
(position.file_text(self.sema.db).clone(), position.file_id, position.range)
907911
}),
908912
|path, name_position| {

crates/ide/src/annotations.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ pub(crate) fn resolve_annotation(
221221
ra_fixture: config.ra_fixture,
222222
exclude_imports: false,
223223
exclude_tests: false,
224-
exclude_library_refs: false,
225224
},
226225
)
227226
.map(|result| {

crates/ide/src/references.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use hir::{PathResolution, Semantics};
2121
use ide_db::{
2222
FileId, RootDatabase,
23+
base_db::SourceDatabase,
2324
defs::{Definition, NameClass, NameRefClass},
2425
helpers::pick_best_token,
2526
ra_fixture::{RaFixtureConfig, UpmapFromRaFixture},
@@ -93,7 +94,6 @@ pub struct FindAllRefsConfig<'a> {
9394
pub ra_fixture: RaFixtureConfig<'a>,
9495
pub exclude_imports: bool,
9596
pub exclude_tests: bool,
96-
pub exclude_library_refs: bool,
9797
}
9898

9999
/// Find all references to the item at the given position.
@@ -128,6 +128,7 @@ pub(crate) fn find_all_refs(
128128
) -> Option<Vec<ReferenceSearchResult>> {
129129
let _p = tracing::info_span!("find_all_refs").entered();
130130
let syntax = sema.parse_guess_edition(position.file_id).syntax().clone();
131+
let exclude_library_refs = !is_library_file(sema.db, position.file_id);
131132
let make_searcher = |literal_search: bool| {
132133
move |def: Definition| {
133134
let mut excluded_categories = ReferenceCategory::empty();
@@ -141,7 +142,7 @@ pub(crate) fn find_all_refs(
141142
.usages(sema)
142143
.set_scope(config.search_scope.as_ref())
143144
.set_excluded_categories(excluded_categories)
144-
.set_exclude_library_files(config.exclude_library_refs)
145+
.set_exclude_library_files(exclude_library_refs)
145146
.include_self_refs()
146147
.all();
147148
if literal_search {
@@ -182,9 +183,7 @@ pub(crate) fn find_all_refs(
182183
nav,
183184
}
184185
})
185-
.filter(|decl| {
186-
!(config.exclude_library_refs && is_library_file(sema.db, decl.nav.file_id))
187-
});
186+
.filter(|decl| !(exclude_library_refs && is_library_file(sema.db, decl.nav.file_id)));
188187
ReferenceSearchResult { declaration, references }
189188
}
190189
};
@@ -505,7 +504,6 @@ fn test() {
505504
test_func();
506505
}
507506
"#,
508-
false,
509507
false,
510508
false,
511509
expect![[r#"
@@ -529,7 +527,6 @@ fn test() {
529527
test_func();
530528
}
531529
"#,
532-
false,
533530
false,
534531
false,
535532
expect![[r#"
@@ -555,7 +552,6 @@ fn test() {
555552
"#,
556553
false,
557554
true,
558-
false,
559555
expect![[r#"
560556
test_func Function FileId(0) 0..17 3..12
561557
@@ -585,7 +581,6 @@ pub fn also_calls_foo() {
585581
"#,
586582
false,
587583
false,
588-
true,
589584
expect![[r#"
590585
FileId(0) 9..12 import
591586
FileId(0) 31..34
@@ -602,7 +597,6 @@ fn main() {
602597
"#,
603598
false,
604599
false,
605-
true,
606600
expect![[r#"
607601
FileId(0) 46..50
608602
"#]],
@@ -627,7 +621,36 @@ pub fn also_calls_foo() {
627621
"#,
628622
false,
629623
false,
630-
true,
624+
expect![[r#"
625+
foo Function FileId(1) 0..15 7..10
626+
627+
FileId(0) 9..12 import
628+
FileId(0) 31..34
629+
FileId(1) 47..50
630+
"#]],
631+
);
632+
}
633+
634+
#[test]
635+
fn find_refs_from_library_source_keeps_library_refs() {
636+
check_with_filters(
637+
r#"
638+
//- /main.rs crate:main deps:dep
639+
use dep::foo;
640+
641+
fn main() {
642+
foo();
643+
}
644+
645+
//- /dep/lib.rs crate:dep new_source_root:library
646+
pub fn foo$0() {}
647+
648+
pub fn also_calls_foo() {
649+
foo();
650+
}
651+
"#,
652+
false,
653+
false,
631654
expect![[r#"
632655
foo Function FileId(1) 0..15 7..10
633656
@@ -1682,40 +1705,31 @@ fn main() {
16821705
}
16831706

16841707
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
1685-
check_with_filters(ra_fixture, false, false, false, expect)
1708+
check_with_filters(ra_fixture, false, false, expect)
16861709
}
16871710

16881711
fn check_with_filters(
16891712
#[rust_analyzer::rust_fixture] ra_fixture: &str,
16901713
exclude_imports: bool,
16911714
exclude_tests: bool,
1692-
exclude_library_refs: bool,
16931715
expect: Expect,
16941716
) {
1695-
check_with_scope_and_filters(
1696-
ra_fixture,
1697-
None,
1698-
exclude_imports,
1699-
exclude_tests,
1700-
exclude_library_refs,
1701-
expect,
1702-
)
1717+
check_with_scope_and_filters(ra_fixture, None, exclude_imports, exclude_tests, expect)
17031718
}
17041719

17051720
fn check_with_scope(
17061721
#[rust_analyzer::rust_fixture] ra_fixture: &str,
17071722
search_scope: Option<&mut dyn FnMut(&RootDatabase) -> SearchScope>,
17081723
expect: Expect,
17091724
) {
1710-
check_with_scope_and_filters(ra_fixture, search_scope, false, false, false, expect)
1725+
check_with_scope_and_filters(ra_fixture, search_scope, false, false, expect)
17111726
}
17121727

17131728
fn check_with_scope_and_filters(
17141729
#[rust_analyzer::rust_fixture] ra_fixture: &str,
17151730
search_scope: Option<&mut dyn FnMut(&RootDatabase) -> SearchScope>,
17161731
exclude_imports: bool,
17171732
exclude_tests: bool,
1718-
exclude_library_refs: bool,
17191733
expect: Expect,
17201734
) {
17211735
let (analysis, pos) = fixture::position(ra_fixture);
@@ -1724,10 +1738,6 @@ fn main() {
17241738
ra_fixture: RaFixtureConfig::default(),
17251739
exclude_imports,
17261740
exclude_tests,
1727-
exclude_library_refs,
1728-
exclude_imports: false,
1729-
exclude_tests: false,
1730-
exclude_library_refs: false,
17311741
};
17321742
let refs = analysis.find_all_refs(pos, &config).unwrap().unwrap();
17331743

@@ -2234,8 +2244,6 @@ use proc_macros::identity;
22342244
fn func() {}
22352245
"#,
22362246
expect![[r#"
2237-
identity Attribute FileId(1) 1..107 32..40
2238-
22392247
FileId(0) 17..25 import
22402248
FileId(0) 43..51
22412249
"#]],
@@ -2265,8 +2273,6 @@ use proc_macros::mirror;
22652273
mirror$0! {}
22662274
"#,
22672275
expect![[r#"
2268-
mirror ProcMacro FileId(1) 1..77 22..28
2269-
22702276
FileId(0) 17..23 import
22712277
FileId(0) 26..32
22722278
"#]],
@@ -2285,8 +2291,6 @@ use proc_macros::DeriveIdentity;
22852291
struct Foo;
22862292
"#,
22872293
expect![[r#"
2288-
derive_identity Derive FileId(2) 1..107 45..60
2289-
22902294
FileId(0) 17..31 import
22912295
FileId(0) 56..70
22922296
"#]],

crates/rust-analyzer/src/config.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,6 @@ config_data! {
409409
/// Exclude imports from find-all-references.
410410
references_excludeImports: bool = false,
411411

412-
/// Exclude references from dependencies and stdlib in find-all-references.
413-
references_excludeLibraries: bool = false,
414-
415412
/// Exclude tests from find-all-references and call-hierarchy.
416413
references_excludeTests: bool = false,
417414

@@ -2655,10 +2652,6 @@ impl Config {
26552652
*self.references_excludeImports()
26562653
}
26572654

2658-
pub fn find_all_refs_exclude_libraries(&self) -> bool {
2659-
*self.references_excludeLibraries()
2660-
}
2661-
26622655
pub fn find_all_refs_exclude_tests(&self) -> bool {
26632656
*self.references_excludeTests()
26642657
}

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,15 +1396,12 @@ pub(crate) fn handle_references(
13961396

13971397
let exclude_imports = snap.config.find_all_refs_exclude_imports();
13981398
let exclude_tests = snap.config.find_all_refs_exclude_tests();
1399-
let exclude_library_refs = snap.config.find_all_refs_exclude_libraries();
1400-
14011399
let Some(refs) = snap.analysis.find_all_refs(
14021400
position,
14031401
&FindAllRefsConfig {
14041402
search_scope: None,
14051403
ra_fixture: snap.config.ra_fixture(snap.minicore()),
14061404
exclude_imports,
1407-
exclude_library_refs,
14081405
exclude_tests,
14091406
},
14101407
)?
@@ -2214,7 +2211,6 @@ fn show_ref_command_link(
22142211
ra_fixture: snap.config.ra_fixture(snap.minicore()),
22152212
exclude_imports: snap.config.find_all_refs_exclude_imports(),
22162213
exclude_tests: snap.config.find_all_refs_exclude_tests(),
2217-
exclude_library_refs: snap.config.find_all_refs_exclude_libraries(),
22182214
},
22192215
)
22202216
.unwrap_or(None)

docs/book/src/configuration_generated.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,13 +1376,6 @@ Default: `false`
13761376
Exclude imports from find-all-references.
13771377

13781378

1379-
## rust-analyzer.references.excludeLibraries {#references.excludeLibraries}
1380-
1381-
Default: `false`
1382-
1383-
Exclude references from dependencies and stdlib in find-all-references.
1384-
1385-
13861379
## rust-analyzer.references.excludeTests {#references.excludeTests}
13871380

13881381
Default: `false`

editors/code/package.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,16 +2875,6 @@
28752875
}
28762876
}
28772877
},
2878-
{
2879-
"title": "References",
2880-
"properties": {
2881-
"rust-analyzer.references.excludeLibraries": {
2882-
"markdownDescription": "Exclude references from dependencies and stdlib in find-all-references.",
2883-
"default": false,
2884-
"type": "boolean"
2885-
}
2886-
}
2887-
},
28882878
{
28892879
"title": "References",
28902880
"properties": {

0 commit comments

Comments
 (0)