Skip to main content

reovim_module_bufferline/
lib.rs

1#![cfg_attr(coverage_nightly, allow(unused_features))]
2#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
3//! Bufferline module for reovim.
4//!
5//! Provides pin/unpin/close commands for the buffer tab bar. The buffer
6//! list itself is fetched client-side via `list_buffers()` gRPC — this
7//! module only manages server-owned pin state and a thin bridge that
8//! emits pin changes to clients.
9
10pub mod bridge;
11pub mod commands;
12pub mod ids;
13mod keybinding;
14pub mod state;
15
16use {
17    reovim_driver_command::CommandHandlerStore,
18    reovim_driver_input::KeybindingStore,
19    reovim_driver_session::bridges::BridgeProvider,
20    reovim_kernel::api::v1::{
21        KeybindingRegistration, Module, ModuleContext, ModuleError, ModuleId, ProbeResult, Version,
22    },
23};
24
25const KIND: &str = "bufferline";
26
27/// Bufferline module.
28///
29/// Registers pin commands, keybindings, and a thin pin-state bridge.
30/// Buffer list data flows client-side (no server-side aggregation).
31pub struct BufferlineModule;
32
33impl BufferlineModule {
34    /// Create a new instance.
35    #[must_use]
36    pub const fn new() -> Self {
37        Self
38    }
39}
40
41#[cfg_attr(coverage_nightly, coverage(off))]
42impl Default for BufferlineModule {
43    fn default() -> Self {
44        Self::new()
45    }
46}
47
48impl Module for BufferlineModule {
49    fn id(&self) -> ModuleId {
50        ids::MODULE
51    }
52
53    fn name(&self) -> &'static str {
54        "Bufferline"
55    }
56
57    fn version(&self) -> Version {
58        Version::new(0, 2, 0)
59    }
60
61    #[cfg_attr(coverage_nightly, coverage(off))]
62    fn init(&mut self, ctx: &ModuleContext) -> ProbeResult {
63        // Register pin-state bridge.
64        let provider = ctx.services.get_or_create::<BridgeProvider>();
65        provider.register(bridge::PinBridge);
66
67        // Register command handlers.
68        let command_store = ctx.services.get_or_create::<CommandHandlerStore>();
69        for handler in commands::command_handlers() {
70            command_store.add(handler);
71        }
72
73        // Register keybindings.
74        let keybinding_store = ctx.services.get_or_create::<KeybindingStore>();
75        keybinding_store.add_all(self.keybindings());
76
77        ProbeResult::Success
78    }
79
80    fn exit(&mut self) -> Result<(), ModuleError> {
81        Ok(())
82    }
83
84    fn extension_kinds(&self) -> &[&'static str] {
85        &[KIND]
86    }
87
88    #[cfg_attr(coverage_nightly, coverage(off))]
89    fn keybindings(&self) -> Vec<KeybindingRegistration> {
90        keybinding::all()
91    }
92}
93
94#[cfg(feature = "dynamic")]
95reovim_module_macros::declare_module!(BufferlineModule);
96
97#[cfg(test)]
98#[path = "lib_tests.rs"]
99mod tests;