-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LS: Add batching files for diagnostics and plug it into refreshing logic
This commit loses separation between open and other files in trace profiles, but with recent speedups these spans stopped being useful. commit-id:bd1161e7
- Loading branch information
Showing
3 changed files
with
88 additions
and
61 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
crates/cairo-lang-language-server/src/lang/diagnostics/file_batches.rs
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::collections::HashSet; | ||
use std::num::NonZero; | ||
|
||
use cairo_lang_defs::db::DefsGroup; | ||
use cairo_lang_filesystem::db::FilesGroup; | ||
use cairo_lang_filesystem::ids::FileId; | ||
use lsp_types::Url; | ||
|
||
use crate::lang::db::AnalysisDatabase; | ||
use crate::lang::lsp::LsProtoGroup; | ||
|
||
/// Finds all analyzable files in `db` that are open and need to be analysed ASAP, thus _primary_. | ||
#[tracing::instrument(skip_all)] | ||
pub fn find_primary_files(db: &AnalysisDatabase, open_files: &HashSet<Url>) -> HashSet<FileId> { | ||
open_files.iter().filter_map(|uri| db.file_for_url(uri)).collect() | ||
} | ||
|
||
/// Finds all analyzable files in `db` that are **not** primary. | ||
#[tracing::instrument(skip_all)] | ||
pub fn find_secondary_files( | ||
db: &AnalysisDatabase, | ||
primary_files: &HashSet<FileId>, | ||
) -> HashSet<FileId> { | ||
let mut result = HashSet::new(); | ||
for crate_id in db.crates() { | ||
for module_id in db.crate_modules(crate_id).iter() { | ||
// Schedule only module main files for refreshing. | ||
// All other related files will be refreshed along with it in a single job. | ||
if let Ok(file) = db.module_main_file(*module_id) { | ||
if !primary_files.contains(&file) { | ||
result.insert(file); | ||
} | ||
} | ||
} | ||
} | ||
result | ||
} | ||
|
||
/// Returns `n` optimally distributed batches of the input. | ||
pub fn batches<'a>( | ||
input: impl IntoIterator<Item = &'a FileId> + Clone + 'a, | ||
n: NonZero<usize>, | ||
) -> Vec<Vec<FileId>> { | ||
let n = n.get(); | ||
let batches = (1..=n) | ||
.map(|offset| input.clone().into_iter().copied().skip(offset - 1).step_by(n).collect()) | ||
.collect::<Vec<_>>(); | ||
debug_assert_eq!(batches.len(), n); | ||
batches | ||
} |
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