#![cfg_attr(coverage_nightly, allow(unused_features))]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
mod buffer;
mod colorscheme;
mod edit;
mod quit;
mod session;
mod set;
mod substitute;
mod write;
use {
reovim_driver_command::{CommandHandler, CommandHandlerStore},
reovim_kernel::api::v1::{Module, ModuleContext, ModuleError, ModuleId, ProbeResult, Version},
};
pub use {
buffer::{BdeleteCommand, BnextCommand, BpreviousCommand, QuitAllCommand},
colorscheme::ColorschemeCommand,
edit::EditCommand,
quit::QuitCommand,
session::{DetachCommand, KillServerCommand, ServersCommand},
set::SetCommand,
substitute::SubstituteCommand,
write::{WriteCommand, WriteQuitCommand},
};
#[must_use]
pub fn command_handlers() -> Vec<Box<dyn CommandHandler>> {
let mut cmds: Vec<Box<dyn CommandHandler>> = vec![
Box::new(EditCommand),
Box::new(QuitCommand),
Box::new(WriteCommand),
Box::new(WriteQuitCommand),
Box::new(ColorschemeCommand),
Box::new(SetCommand),
Box::new(SubstituteCommand),
];
cmds.extend(session::command_handlers());
cmds.extend(buffer::command_handlers());
cmds
}
pub struct CommandsModule;
impl CommandsModule {
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl Default for CommandsModule {
fn default() -> Self {
Self::new()
}
}
impl Module for CommandsModule {
fn id(&self) -> ModuleId {
ModuleId::new("commands")
}
fn name(&self) -> &'static str {
"Ex-Commands"
}
fn version(&self) -> Version {
Version::new(0, 9, 0)
}
fn init(&mut self, ctx: &ModuleContext) -> ProbeResult {
let store = ctx.services.get_or_create::<CommandHandlerStore>();
for handler in command_handlers() {
store.add(handler);
}
ProbeResult::Success
}
fn exit(&mut self) -> Result<(), ModuleError> {
Ok(())
}
fn provides(&self) -> &[&'static str] {
&[reovim_capabilities::COMMAND_DISPATCH]
}
}
#[cfg(feature = "dynamic")]
reovim_module_macros::declare_module!(CommandsModule);
#[cfg(test)]
#[path = "lib_tests.rs"]
mod tests;