Unnamed repository; edit this file 'description' to name the repository.
internal: auto exclude
| -rw-r--r-- | crates/ide-db/src/search.rs | 8 | ||||
| -rw-r--r-- | crates/ide/src/annotations.rs | 1 | ||||
| -rw-r--r-- | crates/ide/src/references.rs | 70 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/config.rs | 7 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/handlers/request.rs | 4 | ||||
| -rw-r--r-- | docs/book/src/configuration_generated.md | 7 | ||||
| -rw-r--r-- | editors/code/package.json | 10 |
7 files changed, 43 insertions, 64 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs index a0655341fa..8922eb6587 100644 --- a/crates/ide-db/src/search.rs +++ b/crates/ide-db/src/search.rs @@ -615,7 +615,7 @@ impl<'a> FindUsages<'a> { search_scope: &SearchScope, name: &str, ) -> bool { - if self.scope.is_some() || self.exclude_library_files { + if self.scope.is_some() { return false; } @@ -897,12 +897,16 @@ impl<'a> FindUsages<'a> { let finder = Finder::new(name.as_bytes()); // The search for `Self` may return duplicate results with `ContainerName`, so deduplicate them. let mut self_positions = FxHashSet::default(); + let is_possibly_self = is_possibly_self.into_iter().filter(|position| { + !self.exclude_library_files + || !is_library_file(self.sema.db, position.file_id.file_id(self.sema.db)) + }); tracing::info_span!("Self_search").in_scope(|| { search( self, &finder, name, - is_possibly_self.into_iter().map(|position| { + is_possibly_self.map(|position| { (position.file_text(self.sema.db).clone(), position.file_id, position.range) }), |path, name_position| { diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 3d61b9d35f..f716f94d71 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -221,7 +221,6 @@ pub(crate) fn resolve_annotation( ra_fixture: config.ra_fixture, exclude_imports: false, exclude_tests: false, - exclude_library_refs: false, }, ) .map(|result| { diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 2dd13ecbce..ea32f02267 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -20,6 +20,7 @@ use hir::{PathResolution, Semantics}; use ide_db::{ FileId, RootDatabase, + base_db::SourceDatabase, defs::{Definition, NameClass, NameRefClass}, helpers::pick_best_token, ra_fixture::{RaFixtureConfig, UpmapFromRaFixture}, @@ -93,7 +94,6 @@ pub struct FindAllRefsConfig<'a> { pub ra_fixture: RaFixtureConfig<'a>, pub exclude_imports: bool, pub exclude_tests: bool, - pub exclude_library_refs: bool, } /// Find all references to the item at the given position. @@ -128,6 +128,7 @@ pub(crate) fn find_all_refs( ) -> Option<Vec<ReferenceSearchResult>> { let _p = tracing::info_span!("find_all_refs").entered(); let syntax = sema.parse_guess_edition(position.file_id).syntax().clone(); + let exclude_library_refs = !is_library_file(sema.db, position.file_id); let make_searcher = |literal_search: bool| { move |def: Definition| { let mut excluded_categories = ReferenceCategory::empty(); @@ -141,7 +142,7 @@ pub(crate) fn find_all_refs( .usages(sema) .set_scope(config.search_scope.as_ref()) .set_excluded_categories(excluded_categories) - .set_exclude_library_files(config.exclude_library_refs) + .set_exclude_library_files(exclude_library_refs) .include_self_refs() .all(); if literal_search { @@ -182,9 +183,7 @@ pub(crate) fn find_all_refs( nav, } }) - .filter(|decl| { - !(config.exclude_library_refs && is_library_file(sema.db, decl.nav.file_id)) - }); + .filter(|decl| !(exclude_library_refs && is_library_file(sema.db, decl.nav.file_id))); ReferenceSearchResult { declaration, references } } }; @@ -507,7 +506,6 @@ fn test() { "#, false, false, - false, expect![[r#" test_func Function FileId(0) 0..17 3..12 @@ -531,7 +529,6 @@ fn test() { "#, false, false, - false, expect![[r#" test_func Function FileId(0) 0..17 3..12 @@ -555,7 +552,6 @@ fn test() { "#, false, true, - false, expect![[r#" test_func Function FileId(0) 0..17 3..12 @@ -585,7 +581,6 @@ pub fn also_calls_foo() { "#, false, false, - true, expect![[r#" FileId(0) 9..12 import FileId(0) 31..34 @@ -602,7 +597,6 @@ fn main() { "#, false, false, - true, expect![[r#" FileId(0) 46..50 "#]], @@ -627,7 +621,36 @@ pub fn also_calls_foo() { "#, false, false, - true, + expect![[r#" + foo Function FileId(1) 0..15 7..10 + + FileId(0) 9..12 import + FileId(0) 31..34 + FileId(1) 47..50 + "#]], + ); + } + + #[test] + fn find_refs_from_library_source_keeps_library_refs() { + check_with_filters( + r#" +//- /main.rs crate:main deps:dep +use dep::foo; + +fn main() { + foo(); +} + +//- /dep/lib.rs crate:dep new_source_root:library +pub fn foo$0() {} + +pub fn also_calls_foo() { + foo(); +} +"#, + false, + false, expect![[r#" foo Function FileId(1) 0..15 7..10 @@ -1682,24 +1705,16 @@ fn main() { } fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) { - check_with_filters(ra_fixture, false, false, false, expect) + check_with_filters(ra_fixture, false, false, expect) } fn check_with_filters( #[rust_analyzer::rust_fixture] ra_fixture: &str, exclude_imports: bool, exclude_tests: bool, - exclude_library_refs: bool, expect: Expect, ) { - check_with_scope_and_filters( - ra_fixture, - None, - exclude_imports, - exclude_tests, - exclude_library_refs, - expect, - ) + check_with_scope_and_filters(ra_fixture, None, exclude_imports, exclude_tests, expect) } fn check_with_scope( @@ -1707,7 +1722,7 @@ fn main() { search_scope: Option<&mut dyn FnMut(&RootDatabase) -> SearchScope>, expect: Expect, ) { - check_with_scope_and_filters(ra_fixture, search_scope, false, false, false, expect) + check_with_scope_and_filters(ra_fixture, search_scope, false, false, expect) } fn check_with_scope_and_filters( @@ -1715,7 +1730,6 @@ fn main() { search_scope: Option<&mut dyn FnMut(&RootDatabase) -> SearchScope>, exclude_imports: bool, exclude_tests: bool, - exclude_library_refs: bool, expect: Expect, ) { let (analysis, pos) = fixture::position(ra_fixture); @@ -1724,10 +1738,6 @@ fn main() { ra_fixture: RaFixtureConfig::default(), exclude_imports, exclude_tests, - exclude_library_refs, - exclude_imports: false, - exclude_tests: false, - exclude_library_refs: false, }; let refs = analysis.find_all_refs(pos, &config).unwrap().unwrap(); @@ -2234,8 +2244,6 @@ use proc_macros::identity; fn func() {} "#, expect![[r#" - identity Attribute FileId(1) 1..107 32..40 - FileId(0) 17..25 import FileId(0) 43..51 "#]], @@ -2265,8 +2273,6 @@ use proc_macros::mirror; mirror$0! {} "#, expect![[r#" - mirror ProcMacro FileId(1) 1..77 22..28 - FileId(0) 17..23 import FileId(0) 26..32 "#]], @@ -2285,8 +2291,6 @@ use proc_macros::DeriveIdentity; struct Foo; "#, expect![[r#" - derive_identity Derive FileId(2) 1..107 45..60 - FileId(0) 17..31 import FileId(0) 56..70 "#]], diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 27546b50ca..3a88a8fe84 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -409,9 +409,6 @@ config_data! { /// Exclude imports from find-all-references. references_excludeImports: bool = false, - /// Exclude references from dependencies and stdlib in find-all-references. - references_excludeLibraries: bool = false, - /// Exclude tests from find-all-references and call-hierarchy. references_excludeTests: bool = false, @@ -2655,10 +2652,6 @@ impl Config { *self.references_excludeImports() } - pub fn find_all_refs_exclude_libraries(&self) -> bool { - *self.references_excludeLibraries() - } - pub fn find_all_refs_exclude_tests(&self) -> bool { *self.references_excludeTests() } diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index c6485badd4..35c5df6e91 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -1396,15 +1396,12 @@ pub(crate) fn handle_references( let exclude_imports = snap.config.find_all_refs_exclude_imports(); let exclude_tests = snap.config.find_all_refs_exclude_tests(); - let exclude_library_refs = snap.config.find_all_refs_exclude_libraries(); - let Some(refs) = snap.analysis.find_all_refs( position, &FindAllRefsConfig { search_scope: None, ra_fixture: snap.config.ra_fixture(snap.minicore()), exclude_imports, - exclude_library_refs, exclude_tests, }, )? @@ -2214,7 +2211,6 @@ fn show_ref_command_link( ra_fixture: snap.config.ra_fixture(snap.minicore()), exclude_imports: snap.config.find_all_refs_exclude_imports(), exclude_tests: snap.config.find_all_refs_exclude_tests(), - exclude_library_refs: snap.config.find_all_refs_exclude_libraries(), }, ) .unwrap_or(None) diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md index 245e77f088..da37fc1582 100644 --- a/docs/book/src/configuration_generated.md +++ b/docs/book/src/configuration_generated.md @@ -1376,13 +1376,6 @@ Default: `false` Exclude imports from find-all-references. -## rust-analyzer.references.excludeLibraries {#references.excludeLibraries} - -Default: `false` - -Exclude references from dependencies and stdlib in find-all-references. - - ## rust-analyzer.references.excludeTests {#references.excludeTests} Default: `false` diff --git a/editors/code/package.json b/editors/code/package.json index 2f1d75816a..29cbc8bd4f 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -2878,16 +2878,6 @@ { "title": "References", "properties": { - "rust-analyzer.references.excludeLibraries": { - "markdownDescription": "Exclude references from dependencies and stdlib in find-all-references.", - "default": false, - "type": "boolean" - } - } - }, - { - "title": "References", - "properties": { "rust-analyzer.references.excludeTests": { "markdownDescription": "Exclude tests from find-all-references and call-hierarchy.", "default": false, |