lattice_compilation/events.rs
1//! CM.1: the streamed compilation-output event.
2//!
3//! `CompilationService` publishes one [`CompilationOutputPushed`]
4//! per streamed chunk on the editor's typed event bus;
5//! `CompilationMode`'s drain task (subscribed in `on_activate`)
6//! applies each chunk to the `*compilation*` buffer. Peer
7//! subscribers (renderer wake, future telemetry) attach to the
8//! same event with no privileged path — the codified `*messages*`
9//! / ai-log streaming shape.
10
11/// One unit of streamed compilation output. The drain applies
12/// these in arrival order:
13///
14/// - [`OutputChunk::Reset`] clears the buffer and seeds a fresh
15/// run header (full-range replace).
16/// - [`OutputChunk::Append`] appends captured stdout/stderr text
17/// at the end of the buffer (insert-at-end).
18/// - [`OutputChunk::Finished`] appends the terminal summary line
19/// once the process exits (insert-at-end).
20#[derive(Debug, Clone)]
21pub enum OutputChunk {
22 /// Clear the buffer and seed it with the run header.
23 Reset { header: String },
24 /// Append a batch of captured output lines.
25 Append {
26 /// The captured text with every escape sequence already
27 /// removed (CM.5) — this is what lands in the buffer and what
28 /// the error parsers were fed.
29 text: String,
30 /// CM.5: one entry per line of `text`, in order, holding that
31 /// line's ANSI colour spans at byte offsets into the **clean**
32 /// line. Empty when the output carried no colour (the common
33 /// case: a pipe makes most tools disable it) or when no theme
34 /// registry was available to intern the palette.
35 ///
36 /// Travels with the text rather than on a parallel channel for
37 /// the reason the highlight drain states about diff signs:
38 /// one thing being spliced cannot desynchronise from itself.
39 spans: Vec<Vec<lattice_cells::StyledSpan>>,
40 },
41 /// Append the exit summary line.
42 Finished { summary: String },
43}
44
45impl OutputChunk {
46 /// An `Append` carrying no colour — the shape most call sites and
47 /// every test that does not care about ANSI wants.
48 pub fn append(text: impl Into<String>) -> Self {
49 OutputChunk::Append {
50 text: text.into(),
51 spans: Vec::new(),
52 }
53 }
54}
55
56/// Typed event carrying one [`OutputChunk`] from the compilation
57/// service to the `*compilation*` buffer drain.
58#[derive(Debug, Clone)]
59pub struct CompilationOutputPushed {
60 pub chunk: OutputChunk,
61}
62
63lattice_protocol::register_event!(
64 CompilationOutputPushed,
65 "compilation.output-pushed",
66 "Fired for each chunk of streamed compilation output (run header \
67 reset, appended stdout/stderr lines, exit summary). The \
68 `*compilation*` buffer's drain is the primary subscriber; the \
69 renderer wake and future telemetry hooks are peers.",
70 "lattice-compilation",
71);