Skip to main content

reovim_driver_session/
lib.rs

1#![cfg_attr(coverage_nightly, allow(unused_features))]
2#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
3//! Session driver for reovim.
4//!
5//! Provides traits and types for session management.
6//!
7//! # Overview
8//!
9//! This driver provides:
10//!
11//! - **Session infrastructure**: Shared state ([`SessionShared`]) and runtime ([`SessionRuntime`])
12//! - **Client identification**: [`ClientId`] for explicit client binding
13//! - **Window management**: [`Window`], [`WindowLayout`], [`CursorPosition`]
14//! - **Mode lifecycle**: Runtime mode hooks ([`SessionMode`], [`ModeError`])
15//! - **Extension system**: Module per-session state ([`SessionExtension`], [`ExtensionMap`])
16//! - **Empty session handling**: Startup behavior ([`EmptySessionHandler`])
17//!
18//! # Architecture (#471, #491)
19//!
20//! ```text
21//! ┌─────────────────────────────────────────────────────────────────┐
22//! │ SESSION DRIVER (server/lib/drivers/session/) - PURE MECHANISM   │
23//! │                                                                 │
24//! │ SHARED INFRASTRUCTURE:                                          │
25//! │   Session { id, shared: SessionShared }                         │
26//! │   SessionShared { compositor, home_mode }                       │
27//! │                                                                 │
28//! │ RUNTIME (borrows shared + per-client state):                    │
29//! │   SessionRuntime::new(&session, &mode_stack, &windows, ...)     │
30//! │                                                                 │
31//! │ PER-CLIENT TYPES (defined here, owned by server::EditingState): │
32//! │   ModeStack, WindowLayout, KeySequence, ExtensionMap, Viewport  │
33//! │                                                                 │
34//! │ LIFECYCLE TRAITS:                                               │
35//! │   SessionMode: id(), on_enter(), on_exit()                      │
36//! │   SessionExtension: create() - module state factory             │
37//! │   EmptySessionHandler: handle() - startup behavior              │
38//! └─────────────────────────────────────────────────────────────────┘
39//! ```
40//!
41//! # Per-Client State (#471 Phase 0)
42//!
43//! Per-client state (mode, cursor, selection) lives in `server::EditingState`,
44//! not in this driver. The driver provides shared infrastructure only.
45//! Use [`SessionRuntime::new`] with per-client state, or [`SessionRuntime::with_owner`]
46//! for explicit client binding. Per-client state is now REQUIRED (no Option wrappers).
47//!
48//! # Empty Session Handling
49//!
50//! The [`EmptySessionHandler`] trait defines how to handle sessions
51//! with no buffers. Modules implement this to define policy (e.g.,
52//! create a scratch buffer, show a welcome screen).
53//!
54//! ```ignore
55//! use reovim_driver_session::{
56//!     EmptySessionHandler, EmptySessionContext, EmptySessionAction
57//! };
58//!
59//! struct MyHandler;
60//!
61//! impl EmptySessionHandler for MyHandler {
62//!     fn handle(&self, ctx: &EmptySessionContext) -> EmptySessionAction {
63//!         EmptySessionAction::CreateBuffer {
64//!             name: None,
65//!             content: String::new(),
66//!         }
67//!     }
68//!     fn id(&self) -> &'static str { "my-module:handler" }
69//!     fn description(&self) -> &'static str { "My handler" }
70//! }
71//! ```
72//!
73//! # Session Extension
74//!
75//! Modules store per-session policy state via [`SessionExtension`]:
76//!
77//! ```ignore
78//! use reovim_driver_session::{SessionExtension, ExtensionMap};
79//!
80//! #[derive(Default)]
81//! pub struct VimSessionState {
82//!     pub pending_count: Option<usize>,
83//! }
84//!
85//! impl SessionExtension for VimSessionState {
86//!     fn create() -> Self { Self::default() }
87//! }
88//!
89//! // Access in resolver
90//! let vim = session.extensions.get_or_insert::<VimSessionState>();
91//! vim.pending_count = Some(5);
92//! ```
93
94pub mod api;
95pub mod bridges;
96mod buffer_access;
97mod empty_handler;
98mod extension;
99mod handler_key;
100mod handler_registry;
101mod initial_mode;
102mod leader_key;
103mod mode;
104mod notification_drain;
105mod notification_queue;
106mod operator_state;
107mod runtime;
108mod snippet_expander;
109pub mod tab;
110pub mod testing;
111pub mod tick;
112mod transition;
113mod types;
114
115// Empty session handling
116pub use empty_handler::{EmptySessionAction, EmptySessionContext, EmptySessionHandler};
117
118// Initial mode provider for cross-personality support (#623)
119pub use initial_mode::InitialModeProvider;
120
121// Leader key provider for personality-aware binding expansion (#700)
122pub use leader_key::{LeaderKeyProvider, expand_leader};
123
124// Session extension system
125pub use extension::{ExtensionMap, SessionExtension, SessionExtensionDyn, TextInputSink};
126
127// Operator-pending state for text object communication
128pub use operator_state::OperatorPendingState;
129
130// Mode lifecycle
131pub use mode::{ModeError, SessionMode};
132
133// Session types
134pub use types::{
135    BootstrapState, ClientContext, ClientId, CursorPosition, CursorSnapshot, KeySequence, Session,
136    SessionShared, TextObjRange, Viewport, Window, WindowLayout,
137};
138
139// SessionContext removed in #491 - use SessionRuntime instead
140
141// Transition types
142pub use transition::{PopResult, TransitionContext};
143
144// Session runtime (implements all API traits)
145pub use runtime::SessionRuntime;
146
147// Session API traits (re-export for convenience)
148pub use api::{
149    BufferApi, BufferError, ChangeTracker, ClipboardApi, CommandApi, CommandExecutor,
150    CommandHandle, CompositorApi, CompositorError, ExtensionApi, FindCharRecord, FindCharState,
151    ModeApi, ModeError as ApiModeError, RegisterApi, RegisterContent, Selection, SelectionMode,
152    SessionApi, SessionApiDyn, StateChanges, WindowApi, WindowError, YankType,
153};
154
155// Tab page management (#401)
156pub use tab::{TabPage, TabPageSet};
157
158// Re-export typed key and registry (Epic #417 - UniqueProvider abstraction)
159pub use {handler_key::SessionHandlerKey, handler_registry::SessionHandlerRegistry};
160
161// Pending notification queue (#542 - cross-module decoupling, #691 - progress ops)
162pub use notification_queue::{
163    PendingEntry, PendingLevel, PendingNotification, PendingNotificationQueue, PendingOp,
164};
165
166// Notification drain trait (#542 - decouple completion from notification module)
167pub use notification_drain::{NotificationDrain, NotificationDrainRegistry};
168
169// Snippet expander trait (#542 - decouple completion from snippet module)
170pub use snippet_expander::{SnippetExpander, SnippetExpanderRegistry};
171
172// Tick scheduler (#546 - periodic state advancement)
173pub use tick::{TickScheduler, TickSchedulerHandle};
174
175pub use buffer_access::BufferReadAccess;