Skip to main content

reovim_module_vim/
providers.rs

1//! Default mode provider for the Vim module.
2//!
3//! This module implements `DefaultModeProvider` to declare `vim:normal`
4//! as the entry mode for reovim.
5
6use std::sync::Arc;
7
8use {
9    reovim_driver_input::{DefaultModeProvider, ProviderPriority},
10    reovim_kernel::api::v1::{ModeId, ModuleId},
11};
12
13/// Vim module's default mode provider.
14///
15/// Declares `vim:normal` as the entry mode with default priority.
16/// This can be overridden by user configuration with higher priority.
17pub struct VimDefaultModeProvider {
18    /// Cached reference to `VIM_MODULE` for lifetime safety.
19    _marker: (),
20}
21
22impl VimDefaultModeProvider {
23    /// Create a new provider.
24    #[must_use]
25    pub const fn new() -> Self {
26        Self { _marker: () }
27    }
28}
29
30impl Default for VimDefaultModeProvider {
31    fn default() -> Self {
32        Self::new()
33    }
34}
35
36impl DefaultModeProvider for VimDefaultModeProvider {
37    fn provider_id(&self) -> &ModuleId {
38        // Use static for stable address (const creates temporaries)
39        static ID: ModuleId = ModuleId::new("vim");
40        &ID
41    }
42
43    fn priority(&self) -> ProviderPriority {
44        ProviderPriority::Default
45    }
46
47    fn entry_mode(&self) -> &ModeId {
48        // Use static for stable address (const creates temporaries)
49        static MODE: ModeId = ModeId::with_discriminant(ModuleId::new("vim"), "normal", 0);
50        &MODE
51    }
52}
53
54/// Marker struct for implementing `DefaultModeProviderModule` on `VimModule`.
55///
56/// This is used internally to provide the companion trait implementation.
57pub struct VimModuleProviderExt;
58
59impl VimModuleProviderExt {
60    /// Get the default mode provider for the Vim module.
61    #[must_use]
62    pub fn default_mode_provider() -> Option<Arc<dyn DefaultModeProvider>> {
63        Some(Arc::new(VimDefaultModeProvider::new()))
64    }
65}