M1.3: engine workspace, file and buffer commands, event stream
State holds the open project (VFS project, watcher, watched directories)
and versioned buffers. New commands: project.open/close/children,
file.open/save/saveAll, buffer.get/edit/close. buffer.edit takes UTF-16
change sets based on a version and fails with the new stale_version code;
closing dirty buffers or projects without force fails with
unsaved_changes. Commands queue events (projectOpened, treeChanged,
bufferChanged, dirtyChanged, fileChangedOnDisk, ...) that the engine
returns in Outcome.events; Engine::pump_vfs maps changes on disk to
events and reloads clean buffers. project.children watches listed
directories, capped at 256 native / 32 polling, least recently listed
dropped first.
Control channel: events.subscribe streams {"event": ...} lines, with
bounded per-subscriber queues (lutra_control::Subscribers) and method docs
in methods.rs. testkit's EngineBackend and the desktop Host implement the
new Backend::subscribe. Verified with 14 engine integration tests, a TCP
events test and the running app over the control channel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a63ab4ac45
commit
f1976c7d67
30 changed files with 2235 additions and 46 deletions
|
|
@ -1,10 +1,35 @@
|
|||
//! Workspace state that commands read and change.
|
||||
|
||||
use crate::Event;
|
||||
use crate::buffers::Buffers;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
/// Everything the engine knows about the running session.
|
||||
///
|
||||
/// Empty in milestone M0; M1 adds the open project, buffers and settings.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct State {
|
||||
/// Number of commands that ran to completion, successful or not.
|
||||
pub commands_run: u64,
|
||||
/// The open project, if any.
|
||||
pub project: Option<Workspace>,
|
||||
/// Open buffers. Empty whenever no project is open.
|
||||
pub buffers: Buffers,
|
||||
/// Events queued for the host, oldest first.
|
||||
events: Vec<Event>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// Queues an event for the host.
|
||||
pub fn emit(&mut self, event: Event) {
|
||||
self.events.push(event);
|
||||
}
|
||||
|
||||
/// Takes the queued events, oldest first.
|
||||
pub fn take_events(&mut self) -> Vec<Event> {
|
||||
std::mem::take(&mut self.events)
|
||||
}
|
||||
|
||||
/// Whether a project is open.
|
||||
pub fn has_project(&self) -> bool {
|
||||
self.project.is_some()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue