reovim_plugin_profiles/
lib.rs

1//! Profile management plugin for reovim
2//!
3//! This plugin registers the `:profile` ex-command with subcommands:
4//! - `:profile list` - Open profile picker
5//! - `:profile load <name>` - Load a profile by name
6//! - `:profile save <name>` - Save current settings as a profile
7
8use {
9    reovim_core::{
10        command_line::ExCommandHandler,
11        event_bus::{
12            DynEvent, EventBus, EventResult,
13            core_events::{
14                ProfileListEvent, ProfileLoadEvent, ProfileSaveEvent, RegisterExCommand,
15            },
16        },
17        plugin::{Plugin, PluginContext, PluginId, PluginStateRegistry},
18    },
19    std::{collections::HashMap, sync::Arc},
20};
21
22/// Profile management plugin
23pub struct ProfilesPlugin;
24
25impl Plugin for ProfilesPlugin {
26    fn id(&self) -> PluginId {
27        PluginId::new("core:profiles")
28    }
29
30    fn build(&self, _ctx: &mut PluginContext) {
31        // No build-time setup needed
32    }
33
34    fn subscribe(&self, bus: &EventBus, _state: Arc<PluginStateRegistry>) {
35        // Register :profile subcommands
36        let mut subcommands = HashMap::new();
37
38        // :profile list - Opens profile picker
39        subcommands.insert(
40            "list".to_string(),
41            Box::new(ExCommandHandler::ZeroArg {
42                event_constructor: || DynEvent::new(ProfileListEvent),
43                description: "List all available profiles",
44            }),
45        );
46
47        // :profile load <name> - Load a profile
48        subcommands.insert(
49            "load".to_string(),
50            Box::new(ExCommandHandler::SingleArg {
51                event_constructor: |name| DynEvent::new(ProfileLoadEvent { name }),
52                description: "Load a profile by name",
53            }),
54        );
55
56        // :profile save <name> - Save current settings
57        subcommands.insert(
58            "save".to_string(),
59            Box::new(ExCommandHandler::SingleArg {
60                event_constructor: |name| DynEvent::new(ProfileSaveEvent { name }),
61                description: "Save current settings as a profile",
62            }),
63        );
64
65        // Register the :profile command with all subcommands
66        bus.emit(RegisterExCommand::new(
67            "profile",
68            ExCommandHandler::Subcommand {
69                subcommands,
70                description: "Manage configuration profiles",
71            },
72        ));
73
74        tracing::debug!("ProfilesPlugin: Registered :profile command with subcommands");
75
76        // Subscribe to ProfileListEvent to open the profile picker
77        // TODO: Once profile picker UI is implemented, open it here
78        bus.subscribe::<ProfileListEvent, _>(100, move |_event, ctx| {
79            tracing::info!("ProfileListEvent received - profile picker UI not yet implemented");
80            // Future: ctx.emit(MicroscopeOpen { picker_type: ProfilePicker });
81            ctx.request_render();
82            EventResult::Handled
83        });
84
85        tracing::debug!("ProfilesPlugin: Subscribed to ProfileListEvent");
86    }
87}