forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#17900 - darichey:exclude-vendored-libraries, …
…r=davidbarsky Add scip/lsif flag to exclude vendored libaries rust-lang#17809 changed StaticIndex to include vendored libraries. This PR adds a flag to disable that behavior. At work, our monorepo has too many rust targets to index all at once, so we split them up into several shards. Since all of our libraries are vendored, if rust-analyzer includes them, sharding no longer has much benefit, because every shard will have to index the entire transitive dependency graphs of all of its targets. We get around the issue presented in rust-lang#17809 because some other shard will index the libraries directly.
- Loading branch information
Showing
5 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,11 @@ fn documentation_for_definition( | |
) | ||
} | ||
|
||
pub enum VendoredLibrariesConfig<'a> { | ||
Included { workspace_root: &'a VfsPath }, | ||
Excluded, | ||
} | ||
|
||
impl StaticIndex<'_> { | ||
fn add_file(&mut self, file_id: FileId) { | ||
let current_crate = crates_for(self.db, file_id).pop().map(Into::into); | ||
|
@@ -240,15 +245,22 @@ impl StaticIndex<'_> { | |
self.files.push(result); | ||
} | ||
|
||
pub fn compute<'a>(analysis: &'a Analysis, workspace_root: &VfsPath) -> StaticIndex<'a> { | ||
pub fn compute<'a>( | ||
analysis: &'a Analysis, | ||
vendored_libs_config: VendoredLibrariesConfig<'_>, | ||
) -> StaticIndex<'a> { | ||
let db = &*analysis.db; | ||
let work = all_modules(db).into_iter().filter(|module| { | ||
let file_id = module.definition_source_file_id(db).original_file(db); | ||
let source_root = db.file_source_root(file_id.into()); | ||
let source_root = db.source_root(source_root); | ||
let is_vendored = source_root | ||
.path_for_file(&file_id.into()) | ||
.is_some_and(|module_path| module_path.starts_with(workspace_root)); | ||
let is_vendored = match vendored_libs_config { | ||
VendoredLibrariesConfig::Included { workspace_root } => source_root | ||
.path_for_file(&file_id.into()) | ||
.is_some_and(|module_path| module_path.starts_with(workspace_root)), | ||
VendoredLibrariesConfig::Excluded => false, | ||
}; | ||
|
||
!source_root.is_library || is_vendored | ||
}); | ||
let mut this = StaticIndex { | ||
|
@@ -278,10 +290,11 @@ mod tests { | |
use ide_db::{base_db::VfsPath, FileRange, FxHashSet}; | ||
use syntax::TextSize; | ||
|
||
fn check_all_ranges(ra_fixture: &str) { | ||
use super::VendoredLibrariesConfig; | ||
|
||
fn check_all_ranges(ra_fixture: &str, vendored_libs_config: VendoredLibrariesConfig<'_>) { | ||
let (analysis, ranges) = fixture::annotations_without_marker(ra_fixture); | ||
let s = | ||
StaticIndex::compute(&analysis, &VfsPath::new_virtual_path("/workspace".to_owned())); | ||
let s = StaticIndex::compute(&analysis, vendored_libs_config); | ||
let mut range_set: FxHashSet<_> = ranges.iter().map(|it| it.0).collect(); | ||
for f in s.files { | ||
for (range, _) in f.tokens { | ||
|
@@ -298,10 +311,9 @@ mod tests { | |
} | ||
|
||
#[track_caller] | ||
fn check_definitions(ra_fixture: &str) { | ||
fn check_definitions(ra_fixture: &str, vendored_libs_config: VendoredLibrariesConfig<'_>) { | ||
let (analysis, ranges) = fixture::annotations_without_marker(ra_fixture); | ||
let s = | ||
StaticIndex::compute(&analysis, &VfsPath::new_virtual_path("/workspace".to_owned())); | ||
let s = StaticIndex::compute(&analysis, vendored_libs_config); | ||
let mut range_set: FxHashSet<_> = ranges.iter().map(|it| it.0).collect(); | ||
for (_, t) in s.tokens.iter() { | ||
if let Some(t) = t.definition { | ||
|
@@ -329,6 +341,9 @@ struct Foo; | |
enum E { X(Foo) } | ||
//^ ^ ^^^ | ||
"#, | ||
VendoredLibrariesConfig::Included { | ||
workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()), | ||
}, | ||
); | ||
check_definitions( | ||
r#" | ||
|
@@ -337,6 +352,9 @@ struct Foo; | |
enum E { X(Foo) } | ||
//^ ^ | ||
"#, | ||
VendoredLibrariesConfig::Included { | ||
workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()), | ||
}, | ||
); | ||
} | ||
|
||
|
@@ -359,6 +377,9 @@ pub func() { | |
} | ||
"#, | ||
VendoredLibrariesConfig::Included { | ||
workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()), | ||
}, | ||
); | ||
} | ||
|
||
|
@@ -377,9 +398,30 @@ struct ExternalLibrary(i32); | |
struct VendoredLibrary(i32); | ||
//^^^^^^^^^^^^^^^ ^^^ | ||
"#, | ||
VendoredLibrariesConfig::Included { | ||
workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()), | ||
}, | ||
); | ||
} | ||
|
||
#[test] | ||
fn vendored_crate_excluded() { | ||
check_all_ranges( | ||
r#" | ||
//- /workspace/main.rs crate:main deps:external,vendored | ||
struct Main(i32); | ||
//^^^^ ^^^ | ||
//- /external/lib.rs new_source_root:library crate:[email protected],https://a.b/foo.git library | ||
struct ExternalLibrary(i32); | ||
//- /workspace/vendored/lib.rs new_source_root:library crate:[email protected],https://a.b/bar.git library | ||
struct VendoredLibrary(i32); | ||
"#, | ||
VendoredLibrariesConfig::Excluded, | ||
) | ||
} | ||
|
||
#[test] | ||
fn derives() { | ||
check_all_ranges( | ||
|
@@ -394,6 +436,9 @@ pub macro Copy {} | |
struct Hello(i32); | ||
//^^^^^ ^^^ | ||
"#, | ||
VendoredLibrariesConfig::Included { | ||
workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()), | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters