reovim_module_commands/
lib.rs1#![cfg_attr(coverage_nightly, allow(unused_features))]
2#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
3mod buffer;
17mod colorscheme;
18mod edit;
19mod quit;
20mod session;
21mod set;
22mod substitute;
23mod write;
24
25use {
26 reovim_driver_command::{CommandHandler, CommandHandlerStore},
27 reovim_kernel::api::v1::{Module, ModuleContext, ModuleError, ModuleId, ProbeResult, Version},
28};
29
30pub use {
31 buffer::{BdeleteCommand, BnextCommand, BpreviousCommand, QuitAllCommand},
32 colorscheme::ColorschemeCommand,
33 edit::EditCommand,
34 quit::QuitCommand,
35 session::{DetachCommand, KillServerCommand, ServersCommand},
36 set::SetCommand,
37 substitute::SubstituteCommand,
38 write::{WriteCommand, WriteQuitCommand},
39};
40
41#[must_use]
43pub fn command_handlers() -> Vec<Box<dyn CommandHandler>> {
44 let mut cmds: Vec<Box<dyn CommandHandler>> = vec![
45 Box::new(EditCommand),
46 Box::new(QuitCommand),
47 Box::new(WriteCommand),
48 Box::new(WriteQuitCommand),
49 Box::new(ColorschemeCommand),
50 Box::new(SetCommand),
51 Box::new(SubstituteCommand),
52 ];
53 cmds.extend(session::command_handlers());
54 cmds.extend(buffer::command_handlers());
55 cmds
56}
57
58pub struct CommandsModule;
64
65impl CommandsModule {
66 #[must_use]
68 pub const fn new() -> Self {
69 Self
70 }
71}
72
73impl Default for CommandsModule {
74 fn default() -> Self {
75 Self::new()
76 }
77}
78
79impl Module for CommandsModule {
80 fn id(&self) -> ModuleId {
81 ModuleId::new("commands")
82 }
83
84 fn name(&self) -> &'static str {
85 "Ex-Commands"
86 }
87
88 fn version(&self) -> Version {
89 Version::new(0, 9, 0)
90 }
91
92 fn init(&mut self, ctx: &ModuleContext) -> ProbeResult {
93 let store = ctx.services.get_or_create::<CommandHandlerStore>();
95 for handler in command_handlers() {
96 store.add(handler);
97 }
98
99 ProbeResult::Success
100 }
101
102 fn exit(&mut self) -> Result<(), ModuleError> {
103 Ok(())
104 }
105
106 fn provides(&self) -> &[&'static str] {
107 &[reovim_capabilities::COMMAND_DISPATCH]
108 }
109}
110
111#[cfg(feature = "dynamic")]
113reovim_module_macros::declare_module!(CommandsModule);
114
115#[cfg(test)]
116#[path = "lib_tests.rs"]
117mod tests;