Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Function for Compiling Configuration-Sets in Parallel #41

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions server/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::configuration_set::ConfigurationSet;
use std::path::PathBuf;
use slicec::diagnostics::Diagnostic;
use tokio::sync::{Mutex, RwLock};
use tower_lsp::lsp_types::{DidChangeConfigurationParams, Url};

Expand Down Expand Up @@ -99,4 +100,33 @@ impl Session {
let mut configuration_sets = self.configuration_sets.lock().await;
*configuration_sets = configurations;
}

/// Calls `trigger_compilation` on each configuration set stored in this `Session` and returns all the diagnostics
/// reported by doing so. If there are multiple sets, their diagnostics are all pooled into a single `Vec`.
pub async fn compile_everything(&mut self) -> Vec<Diagnostic> {
let mut configuration_sets = self.configuration_sets.lock().await;

match configuration_sets.as_mut_slice() {
[] => unreachable!("Attempted to compile with no configuration sets!"),

// If there's only one configuration set, we compile it and directly return its diagnostics.
[set] => set.trigger_compilation(),

// If there are multiple configuration sets, we compile them in parallel, and pool all their diagnostics.
sets => {
let mut diagnostics = Vec::new();
std::thread::scope(|thread_spawner| {
let mut handles = Vec::new();
for set in sets {
handles.push(thread_spawner.spawn(|| set.trigger_compilation()));
}
for handle in handles {
let set_diagnostics = handle.join().expect("compilation thread panicked!");
diagnostics.extend(set_diagnostics);
}
});
diagnostics
}
}
}
}