1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Session API traits for resolvers and commands.
//!
//! This module provides focused traits that resolvers and commands
//! use to interact with session state. Each trait does ONE thing well
//! (Unix philosophy).
//!
//! # Traits
//!
//! | Trait | Purpose |
//! |-------|---------|
//! | [`ModeApi`] | Mode stack operations |
//! | [`BufferApi`] | Buffer content and lifecycle |
//! | [`WindowApi`] | Window management and focus |
//! | [`CommandApi`] | Command execution |
//! | [`UndoApi`] | Undo/redo operations |
//! | [`ExtensionApi`] | Module per-session state |
//! | [`ChangeTracker`] | Accumulated change collection |
//!
//! # Architecture
//!
//! ```text
//! ┌──────────────────────────────────────────────────────┐
//! │ MODULES (resolvers, commands) POLICY │
//! │ - Call session.push_mode(), session.move_cursor() │
//! │ - Decide WHAT actions to perform │
//! └──────────────────────────────────────────────────────┘
//! │ calls methods on
//! ↓
//! ┌──────────────────────────────────────────────────────┐
//! │ SESSION API (this module) MECHANISM │
//! │ - Focused traits: ModeApi, BufferApi, etc. │
//! │ - SessionRuntime implements all traits │
//! │ - Returns: StateChanges (what changed) │
//! └──────────────────────────────────────────────────────┘
//! │ returns changes to
//! ↓
//! ┌──────────────────────────────────────────────────────┐
//! │ RUNNER MECHANISM │
//! │ - Passes SessionRuntime to resolvers │
//! │ - Receives StateChanges │
//! │ - Broadcasts notifications to clients │
//! └──────────────────────────────────────────────────────┘
//! ```
//!
//! # Usage
//!
//! Resolvers specify which APIs they need via trait bounds:
//!
//! ```ignore
//! fn resolve_with_session<S>(
//! &self,
//! key: &KeyEvent,
//! state: &mut ModeState,
//! session: &mut S,
//! ) -> ResolveResult
//! where
//! S: ModeApi + BufferApi + CommandApi + ExtensionApi,
//! {
//! // Only has access to the traits specified in bounds
//! }
//! ```
// Buffer API
pub use ;
// Clipboard API (#515)
pub use ClipboardApi;
// Find-char state extension (#563)
pub use ;
// Search state extension
pub use SearchState;
// Compositor API
pub use ;
// Register API
pub use ;
// Change tracking
pub use ;
// Command API
pub use ;
// Extension API
pub use ExtensionApi;
// Mode API
pub use ;
// Undo API
pub use UndoApi;
// Window API
pub use ;
// ============================================================================
// SessionApi - Combined trait for resolvers
// ============================================================================
/// Dyn-compatible session API (without extensions).
///
/// This trait bundles the dyn-compatible API traits for use with trait objects.
/// `ExtensionApi` is excluded because it has generic methods.
///
/// # Why Separate from `SessionApi`?
///
/// Rust's trait object (`dyn Trait`) requires all methods to be dyn-compatible.
/// `ExtensionApi` has generic methods (`ext<T>`, `ext_mut<T>`), so it can't be
/// part of a dyn-compatible trait.
///
/// Use `SessionApiDyn` when you need `&mut dyn SessionApiDyn` (e.g., in resolver traits).
/// Extensions are passed separately as `&mut ExtensionMap`.
///
/// # Example
///
/// ```ignore
/// fn resolve_with_session(
/// &self,
/// key: &KeyEvent,
/// state: &mut ModeState,
/// input: &ResolveInput<'_>,
/// session: &mut dyn SessionApiDyn,
/// extensions: &mut ExtensionMap,
/// ) -> ResolveResult {
/// session.push_mode(insert_mode, TransitionContext::new());
/// session.move_cursor(buffer, Position::new(0, 5));
/// ResolveResult::Completed
/// }
/// ```
// Blanket implementation for SessionApiDyn
/// Full session API for generic bounds (not dyn-compatible).
///
/// This trait includes `ExtensionApi` and is used for generic bounds like
/// `where S: SessionApi`. It cannot be used as `dyn SessionApi` because
/// `ExtensionApi` has generic methods.
///
/// # Example
///
/// ```ignore
/// fn do_something<S: SessionApi>(session: &mut S) {
/// // Full access including extensions
/// let ext = session.ext_mut::<MyExtension>();
/// }
/// ```
// Blanket implementation for SessionApi