Lutra/crates/engine/src/lib.rs
danny 20d1d28c32 M3.5: pending outcomes for commands that wait for the language server
Step 1 of M3.5: the shared mechanism. M3.4 and M3.5 build on it.

- Engine: `Outcome.pending: Option<Pending>`. `Pending::new(rx, timeout,
  finish)`; `Pending::wait()` is called without the engine lock and
  returns at the answer, a dropped sender or the deadline (timeout + 1 s).
  `Engine::resolve(answered)` then runs `finish(state, reply)` inside the
  guard, under the lock. `run_waiting(lock, cmd, params, publish)` does
  all three steps for hosts.
- Hosts: `Host::run`, `testkit::EngineBackend` and the control test
  backend use `run_waiting`.
- New IPC `engine_execute_waiting` (`#[tauri::command(async)]`, off the
  main thread) with `runWaiting()` in `ui/src/ipc.ts`. Only `lsp.*`
  requests use it.

Ordering guarantee:
- `engine_execute` stays synchronous on the main thread, so ordinary
  commands (`buffer.edit`) still run in call order.
- The order towards the server is fixed under the engine lock:
  `buffer.edit` queues its didChange on the session's FIFO queue before
  it returns, and `lsp::submit` queues the request on the same queue.
  A request therefore sees every edit whose `buffer.edit` returned
  first, and the UI awaits the sync's `idle()` before sending one.

Failures:
- A stall is caught by the request timeout, with the deadline as
  backstop.
- On restart, close, quit or crash the request is dropped or resolved
  as stopped, so the waiter gets an error, never a hang.

Tests: `crates/engine/tests/pending.rs` (answer, lock free while
waiting, dropped sender, deadline, resolve, lsp.restart while a
request is pending) and Vitest for `runWaiting`. Gate: 13 steps,
321 s, Vitest 443 + 1 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 06:36:20 +02:00

29 lines
881 B
Rust

//! Engine of Lutra (layer L4).
//!
//! Owns the command registry, the workspace state, the panic guard around every
//! entry point and the crash-recovery journal. Every user-visible action is a
//! [`Command`]; menus, the palette, shortcuts, the CLI, the control channel and
//! MCP all reach it through [`Engine::execute`].
mod buffers;
pub mod cmd;
mod command;
mod engine;
mod error;
mod event;
pub mod guard;
pub mod journal;
pub mod lsp;
mod registry;
pub mod settings;
mod state;
pub mod theme;
pub mod workspace;
pub use buffers::{BufferId, LineEndingName, OpenBuffer};
pub use command::{Answered, Command, CommandInfo, CommandSpec, Effect, Outcome, Pending, Reply};
pub use engine::{Engine, EngineConfig, run_waiting};
pub use error::{EngineError, ErrorPayload};
pub use event::{Event, NotificationLevel, SearchMatch};
pub use registry::Registry;
pub use state::State;