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
//! Command execution abstraction.
//!
//! This module provides traits for command execution:
//! - [`CommandApi`] - For resolvers to execute commands
//! - [`CommandHandle`] - Opaque handle for re-entrant command execution
//! - [`CommandExecutor`] - Abstraction over runner's `CommandRegistry`
//!
//! # Design
//!
//! Following the mechanism vs policy principle:
//! - **Session driver defines traits** (this module)
//! - **Runner implements `CommandExecutor`** (via `CommandRegistry`)
//! - **Modules use `CommandApi`** to execute commands
//!
//! This keeps the session driver decoupled from runner types.
//!
//! # Re-Entrant Execution (#547)
//!
//! `CommandExecutor::get_handle()` returns an owned `Arc<dyn CommandHandle>`,
//! releasing the borrow on `self.executor`. Then `handle.execute(self, &ctx)`
//! can pass `&mut self` cleanly. This enables commands to call other commands
//! via `runtime.execute_command()`.
//!
//! # Example
//!
//! ```ignore
//! use reovim_driver_session::api::CommandApi;
//!
//! fn execute_motion<S: CommandApi>(session: &mut S, motion_cmd: CommandId) {
//! let ctx = CommandContext::new();
//! let result = session.execute_command(motion_cmd, ctx);
//! // Handle result...
//! }
//! ```
use ;
/// Command execution for resolvers.
///
/// Provides a way for resolvers to execute commands without
/// knowing about the runner's command registry.
/// Opaque handle for executing a command with a `SessionRuntime`.
///
/// This trait bridges `CommandHandler` (in `reovim-driver-command`) and
/// `SessionRuntime` (in this crate) without creating a dependency cycle.
/// The server creates these by wrapping `Arc<dyn CommandHandler>` in a
/// `HandlerBridge` wrapper (#547).
/// Trait for command handler lookup.
///
/// Runner's `CommandRegistry` implements this trait.
/// This abstraction prevents session driver from depending on runner types.
///
/// # Design
///
/// Instead of `SessionRuntime` holding a concrete `CommandRegistry`,
/// it holds `&dyn CommandExecutor`. This maintains proper dependency
/// direction: runner depends on session driver, not vice versa.
///
/// # Re-Entrant Execution (#547)
///
/// `get_handle()` returns an owned `Arc<dyn CommandHandle>`, releasing
/// the borrow on the executor. The caller then invokes
/// `handle.execute(runtime, ctx)` with full `&mut SessionRuntime` access.