reovim_module_textobjects/
lib.rs1#![cfg_attr(coverage_nightly, allow(unused_features))]
2#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
3pub mod bracket;
29pub mod ids;
30pub mod paragraph;
31pub mod quote;
32pub mod semantic;
33pub mod word;
34
35use {
36 reovim_driver_command::{CommandHandler, CommandHandlerStore, CommandProvider},
37 reovim_kernel::api::v1::{Module, ModuleContext, ModuleError, ModuleId, ProbeResult, Version},
38};
39
40pub const TEXTOBJECTS_MODULE: ModuleId = ModuleId::new("textobjects");
42
43pub struct TextObjectsModule;
45
46impl TextObjectsModule {
47 #[must_use]
49 pub const fn new() -> Self {
50 Self
51 }
52}
53
54impl Default for TextObjectsModule {
55 fn default() -> Self {
56 Self::new()
57 }
58}
59
60impl Module for TextObjectsModule {
61 fn id(&self) -> ModuleId {
62 TEXTOBJECTS_MODULE
63 }
64
65 fn name(&self) -> &'static str {
66 "Vim Text Objects"
67 }
68
69 fn version(&self) -> Version {
70 Version::new(0, 9, 0)
71 }
72
73 fn init(&mut self, ctx: &ModuleContext) -> ProbeResult {
74 let command_store = ctx.services.get_or_create::<CommandHandlerStore>();
76 for handler in self.command_handlers() {
77 command_store.add(handler);
78 }
79 ProbeResult::Success
80 }
81
82 fn exit(&mut self) -> Result<(), ModuleError> {
83 Ok(())
84 }
85}
86
87impl CommandProvider for TextObjectsModule {
88 fn command_handlers(&self) -> Vec<Box<dyn CommandHandler>> {
89 all_commands()
90 }
91}
92
93#[must_use]
95pub fn all_commands() -> Vec<Box<dyn CommandHandler>> {
96 let mut cmds = Vec::new();
97 cmds.extend(word::all_commands());
98 cmds.extend(quote::all_commands());
99 cmds.extend(bracket::all_commands());
100 cmds.extend(paragraph::all_commands());
101 cmds.extend(semantic::all_commands());
102 cmds
103}
104
105#[cfg(feature = "dynamic")]
107reovim_module_macros::declare_module!(TextObjectsModule);
108
109#[cfg(test)]
110mod bracket_tests;
111#[cfg(test)]
112mod lib_tests;
113#[cfg(test)]
114mod paragraph_tests;
115#[cfg(test)]
116mod quote_tests;
117#[cfg(test)]
118mod semantic_tests;
119#[cfg(test)]
120mod word_tests;