From fef393ddc06f4eadaeb916963bc84eed5ce11071 Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Fri, 27 Nov 2026 21:56:59 +0530 Subject: [PATCH] Language packs: fmt, a Status struct for clippy, std Result in the tests Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd.rs | 4 ++-- crates/engine/src/cmd/packs.rs | 2 +- crates/engine/src/packs.rs | 27 ++++++++++++++++++++++----- crates/engine/src/tests/packs.rs | 6 +++--- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index 76c9914a26..c8fb66f630 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -65,6 +65,8 @@ pub(crate) mod objects_on_path; mod opacitymask; mod overprint; pub mod package; +#[cfg(not(target_arch = "wasm32"))] +pub mod packs; mod paint; mod panelcmds; pub mod params; @@ -92,8 +94,6 @@ pub(crate) mod shaper; pub mod shortcutset; pub(crate) mod slices; pub mod spelling; -#[cfg(not(target_arch = "wasm32"))] -pub mod packs; mod stroke; mod style; pub use style::styled_node; diff --git a/crates/engine/src/cmd/packs.rs b/crates/engine/src/cmd/packs.rs index 9941596f59..b90cec9c3d 100644 --- a/crates/engine/src/cmd/packs.rs +++ b/crates/engine/src/cmd/packs.rs @@ -67,7 +67,7 @@ fn list(s: &mut Session, p: &Value) -> Result { }) }) .collect(); - let (installing, refreshing, errors) = packs::status(); + let packs::Status { installing, refreshing, errors } = packs::status(); // An install that ended since the last frame shows in every document's layout. s.poll_language_packs(); Ok(json!({ diff --git a/crates/engine/src/packs.rs b/crates/engine/src/packs.rs index ba1e85c3d0..8ab8f2be17 100644 --- a/crates/engine/src/packs.rs +++ b/crates/engine/src/packs.rs @@ -154,11 +154,24 @@ pub fn available() -> Vec { backend().map(|b| b.cached_index()).unwrap_or_default() } -/// What `proof.packs` reports about the jobs: the installs running as (locale, done, total), whether -/// the index is being fetched, and the last error of each locale (`""`: the index). -pub fn status() -> (Vec<(String, u64, u64)>, bool, BTreeMap) { +/// What `proof.packs` reports about the jobs. +pub struct Status { + /// The installs running, as (locale, bytes done, bytes in all). + pub installing: Vec<(String, u64, u64)>, + /// Whether the index is being fetched. + pub refreshing: bool, + /// The last error of each locale (`""`: the index fetch). + pub errors: BTreeMap, +} + +/// The jobs running and the last errors. +pub fn status() -> Status { let j = jobs(); - (j.installing.iter().map(|(l, job)| (l.clone(), job.done, job.total)).collect(), j.refreshing.is_some(), j.errors.clone()) + Status { + installing: j.installing.iter().map(|(l, job)| (l.clone(), job.done, job.total)).collect(), + refreshing: j.refreshing.is_some(), + errors: j.errors.clone(), + } } /// What an install or a fetch did. @@ -176,7 +189,11 @@ fn run(f: impl FnOnce() + Send + 'static) -> Result { f(); return Ok(Outcome::Done); } - std::thread::Builder::new().name("language-pack".into()).spawn(f).map(|_| Outcome::Started).map_err(|e| format!("couldn't start the download: {e}")) + std::thread::Builder::new() + .name("language-pack".into()) + .spawn(f) + .map(|_| Outcome::Started) + .map_err(|e| format!("couldn't start the download: {e}")) } /// Fetches the pinned pack index again. Needs downloads on. diff --git a/crates/engine/src/tests/packs.rs b/crates/engine/src/tests/packs.rs index 473640f263..37825e8cd2 100644 --- a/crates/engine/src/tests/packs.rs +++ b/crates/engine/src/tests/packs.rs @@ -119,11 +119,11 @@ impl Backend for Fake { vec![nl] } - fn fetch_index(&self, _: &Cancel) -> Result, String> { + fn fetch_index(&self, _: &Cancel) -> std::result::Result, String> { Ok(self.cached_index()) } - fn install(&self, locale: &str, cancel: &Cancel, progress: &mut dyn FnMut(u64, u64)) -> Result<(), String> { + fn install(&self, locale: &str, cancel: &Cancel, progress: &mut dyn FnMut(u64, u64)) -> std::result::Result<(), String> { progress(1, 2); while self.hold.load(Ordering::Relaxed) { if cancel.is_cancelled() { @@ -139,7 +139,7 @@ impl Backend for Fake { Ok(()) } - fn remove(&self, locale: &str) -> Result<(), String> { + fn remove(&self, locale: &str) -> std::result::Result<(), String> { std::fs::remove_dir_all(self.dir.join(locale)).map_err(|e| e.to_string()) } }