Session driver for reovim.
Provides traits and types for session management.
Overview
This driver provides:
- Session infrastructure: Shared state ([
SessionShared]) and runtime ([SessionRuntime]) - Client identification: [
ClientId] for explicit client binding - Window management: [
Window], [WindowLayout], [CursorPosition] - Mode lifecycle: Runtime mode hooks ([
SessionMode], [ModeError]) - Extension system: Module per-session state ([
SessionExtension], [ExtensionMap]) - Empty session handling: Startup behavior ([
EmptySessionHandler])
Architecture (#471, #491)
┌─────────────────────────────────────────────────────────────────┐
│ SESSION DRIVER (server/lib/drivers/session/) - PURE MECHANISM │
│ │
│ SHARED INFRASTRUCTURE: │
│ Session { id, shared: SessionShared } │
│ SessionShared { compositor, home_mode } │
│ │
│ RUNTIME (borrows shared + per-client state): │
│ SessionRuntime::new(&session, &mode_stack, &windows, ...) │
│ │
│ PER-CLIENT TYPES (defined here, owned by server::EditingState): │
│ ModeStack, WindowLayout, KeySequence, ExtensionMap, Viewport │
│ │
│ LIFECYCLE TRAITS: │
│ SessionMode: id(), on_enter(), on_exit() │
│ SessionExtension: create() - module state factory │
│ EmptySessionHandler: handle() - startup behavior │
└─────────────────────────────────────────────────────────────────┘
Per-Client State (#471 Phase 0)
Per-client state (mode, cursor, selection) lives in server::EditingState,
not in this driver. The driver provides shared infrastructure only.
Use [SessionRuntime::new] with per-client state, or [SessionRuntime::with_owner]
for explicit client binding. Per-client state is now REQUIRED (no Option wrappers).
Empty Session Handling
The [EmptySessionHandler] trait defines how to handle sessions
with no buffers. Modules implement this to define policy (e.g.,
create a scratch buffer, show a welcome screen).
use reovim_driver_session::{
EmptySessionHandler, EmptySessionContext, EmptySessionAction
};
struct MyHandler;
impl EmptySessionHandler for MyHandler {
fn handle(&self, ctx: &EmptySessionContext) -> EmptySessionAction {
EmptySessionAction::CreateBuffer {
name: None,
content: String::new(),
}
}
fn id(&self) -> &'static str { "my-module:handler" }
fn description(&self) -> &'static str { "My handler" }
}
Session Extension
Modules store per-session policy state via [SessionExtension]:
use reovim_driver_session::{SessionExtension, ExtensionMap};
#[derive(Default)]
pub struct VimSessionState {
pub pending_count: Option<usize>,
}
impl SessionExtension for VimSessionState {
fn create() -> Self { Self::default() }
}
// Access in resolver
let vim = session.extensions.get_or_insert::<VimSessionState>();
vim.pending_count = Some(5);