reovim_plugin_microscope/
commands.rs

1//! Microscope fuzzy finder commands (unified command-event types)
2
3use reovim_core::{
4    command::traits::*,
5    declare_event_command,
6    event_bus::{DynEvent, Event},
7};
8
9// === Core Events (unified types) ===
10
11/// Open microscope with a specific picker
12#[derive(Debug, Clone)]
13pub struct MicroscopeOpen {
14    pub picker: String,
15}
16
17impl MicroscopeOpen {
18    /// Create event for a specific picker
19    #[must_use]
20    pub fn new(picker: impl Into<String>) -> Self {
21        Self {
22            picker: picker.into(),
23        }
24    }
25}
26
27impl Event for MicroscopeOpen {
28    fn priority(&self) -> u32 {
29        100
30    }
31}
32
33/// Insert a character into the query
34#[derive(Debug, Clone, Copy)]
35pub struct MicroscopeInsertChar {
36    pub c: char,
37}
38
39impl MicroscopeInsertChar {
40    /// Create event for specific character
41    #[must_use]
42    pub const fn new(c: char) -> Self {
43        Self { c }
44    }
45}
46
47impl Event for MicroscopeInsertChar {
48    fn priority(&self) -> u32 {
49        100
50    }
51}
52
53// === Navigation & Control (using macro) ===
54
55declare_event_command! {
56    MicroscopeBackspace,
57    id: "microscope_backspace",
58    description: "Delete character from query (backspace)",
59}
60
61declare_event_command! {
62    MicroscopeCursorLeft,
63    id: "microscope_cursor_left",
64    description: "Move cursor left in query",
65}
66
67declare_event_command! {
68    MicroscopeCursorRight,
69    id: "microscope_cursor_right",
70    description: "Move cursor right in query",
71}
72
73declare_event_command! {
74    MicroscopeSelectNext,
75    id: "microscope_select_next",
76    description: "Select next item",
77}
78
79declare_event_command! {
80    MicroscopeSelectPrev,
81    id: "microscope_select_prev",
82    description: "Select previous item",
83}
84
85declare_event_command! {
86    MicroscopePageDown,
87    id: "microscope_page_down",
88    description: "Page down",
89}
90
91declare_event_command! {
92    MicroscopePageUp,
93    id: "microscope_page_up",
94    description: "Page up",
95}
96
97declare_event_command! {
98    MicroscopeGotoFirst,
99    id: "microscope_goto_first",
100    description: "Go to first item",
101}
102
103declare_event_command! {
104    MicroscopeGotoLast,
105    id: "microscope_goto_last",
106    description: "Go to last item",
107}
108
109declare_event_command! {
110    MicroscopeConfirm,
111    id: "microscope_confirm",
112    description: "Confirm selection",
113}
114
115declare_event_command! {
116    MicroscopeClose,
117    id: "microscope_close",
118    description: "Close microscope",
119}
120
121declare_event_command! {
122    MicroscopeEnterInsert,
123    id: "microscope_enter_insert",
124    description: "Enter insert mode (for typing query)",
125}
126
127declare_event_command! {
128    MicroscopeEnterNormal,
129    id: "microscope_enter_normal",
130    description: "Enter normal mode (for j/k navigation)",
131}
132
133// === Normal Mode Prompt Commands ===
134
135declare_event_command! {
136    MicroscopeWordForward,
137    id: "microscope_word_forward",
138    description: "Move cursor forward one word in query",
139}
140
141declare_event_command! {
142    MicroscopeWordBackward,
143    id: "microscope_word_backward",
144    description: "Move cursor backward one word in query",
145}
146
147declare_event_command! {
148    MicroscopeCursorStart,
149    id: "microscope_cursor_start",
150    description: "Move cursor to start of query",
151}
152
153declare_event_command! {
154    MicroscopeCursorEnd,
155    id: "microscope_cursor_end",
156    description: "Move cursor to end of query",
157}
158
159declare_event_command! {
160    MicroscopeClearQuery,
161    id: "microscope_clear_query",
162    description: "Clear the search query",
163}
164
165declare_event_command! {
166    MicroscopeDeleteWord,
167    id: "microscope_delete_word",
168    description: "Delete word before cursor",
169}
170
171// === Picker Commands ===
172// These are separate command types that emit MicroscopeOpen with different picker names
173
174/// Open microscope find files picker
175#[derive(Debug, Clone, Copy)]
176pub struct MicroscopeFindFiles;
177
178impl CommandTrait for MicroscopeFindFiles {
179    fn name(&self) -> &'static str {
180        "microscope_find_files"
181    }
182
183    fn description(&self) -> &'static str {
184        "Find files with fuzzy search"
185    }
186
187    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
188        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("files")))
189    }
190
191    fn clone_box(&self) -> Box<dyn CommandTrait> {
192        Box::new(*self)
193    }
194
195    fn as_any(&self) -> &dyn std::any::Any {
196        self
197    }
198}
199
200/// Open microscope buffers picker
201#[derive(Debug, Clone, Copy)]
202pub struct MicroscopeFindBuffers;
203
204impl CommandTrait for MicroscopeFindBuffers {
205    fn name(&self) -> &'static str {
206        "microscope_find_buffers"
207    }
208
209    fn description(&self) -> &'static str {
210        "Find open buffers"
211    }
212
213    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
214        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("buffers")))
215    }
216
217    fn clone_box(&self) -> Box<dyn CommandTrait> {
218        Box::new(*self)
219    }
220
221    fn as_any(&self) -> &dyn std::any::Any {
222        self
223    }
224}
225
226/// Open microscope live grep picker
227#[derive(Debug, Clone, Copy)]
228pub struct MicroscopeLiveGrep;
229
230impl CommandTrait for MicroscopeLiveGrep {
231    fn name(&self) -> &'static str {
232        "microscope_live_grep"
233    }
234
235    fn description(&self) -> &'static str {
236        "Search text in files"
237    }
238
239    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
240        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("grep")))
241    }
242
243    fn clone_box(&self) -> Box<dyn CommandTrait> {
244        Box::new(*self)
245    }
246
247    fn as_any(&self) -> &dyn std::any::Any {
248        self
249    }
250}
251
252/// Open microscope recent files picker
253#[derive(Debug, Clone, Copy)]
254pub struct MicroscopeFindRecent;
255
256impl CommandTrait for MicroscopeFindRecent {
257    fn name(&self) -> &'static str {
258        "microscope_find_recent"
259    }
260
261    fn description(&self) -> &'static str {
262        "Find recent files"
263    }
264
265    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
266        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("recent")))
267    }
268
269    fn clone_box(&self) -> Box<dyn CommandTrait> {
270        Box::new(*self)
271    }
272
273    fn as_any(&self) -> &dyn std::any::Any {
274        self
275    }
276}
277
278/// Open microscope help picker
279#[derive(Debug, Clone, Copy)]
280pub struct MicroscopeHelp;
281
282impl CommandTrait for MicroscopeHelp {
283    fn name(&self) -> &'static str {
284        "microscope_help"
285    }
286
287    fn description(&self) -> &'static str {
288        "Search help tags"
289    }
290
291    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
292        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("help")))
293    }
294
295    fn clone_box(&self) -> Box<dyn CommandTrait> {
296        Box::new(*self)
297    }
298
299    fn as_any(&self) -> &dyn std::any::Any {
300        self
301    }
302}
303
304/// Open microscope commands picker
305#[derive(Debug, Clone, Copy)]
306pub struct MicroscopeCommands;
307
308impl CommandTrait for MicroscopeCommands {
309    fn name(&self) -> &'static str {
310        "microscope_commands"
311    }
312
313    fn description(&self) -> &'static str {
314        "Search available commands"
315    }
316
317    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
318        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("commands")))
319    }
320
321    fn clone_box(&self) -> Box<dyn CommandTrait> {
322        Box::new(*self)
323    }
324
325    fn as_any(&self) -> &dyn std::any::Any {
326        self
327    }
328}
329
330/// Open microscope keymaps picker
331#[derive(Debug, Clone, Copy)]
332pub struct MicroscopeKeymaps;
333
334impl CommandTrait for MicroscopeKeymaps {
335    fn name(&self) -> &'static str {
336        "microscope_keymaps"
337    }
338
339    fn description(&self) -> &'static str {
340        "Search keybindings"
341    }
342
343    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
344        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("keymaps")))
345    }
346
347    fn clone_box(&self) -> Box<dyn CommandTrait> {
348        Box::new(*self)
349    }
350
351    fn as_any(&self) -> &dyn std::any::Any {
352        self
353    }
354}
355
356/// Open microscope themes picker
357#[derive(Debug, Clone, Copy)]
358pub struct MicroscopeThemes;
359
360impl CommandTrait for MicroscopeThemes {
361    fn name(&self) -> &'static str {
362        "microscope_themes"
363    }
364
365    fn description(&self) -> &'static str {
366        "Search available themes"
367    }
368
369    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
370        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("themes")))
371    }
372
373    fn clone_box(&self) -> Box<dyn CommandTrait> {
374        Box::new(*self)
375    }
376
377    fn as_any(&self) -> &dyn std::any::Any {
378        self
379    }
380}
381
382/// Open microscope profiles picker  
383#[derive(Debug, Clone, Copy)]
384pub struct MicroscopeProfiles;
385
386impl CommandTrait for MicroscopeProfiles {
387    fn name(&self) -> &'static str {
388        "microscope_profiles"
389    }
390
391    fn description(&self) -> &'static str {
392        "Search profiles"
393    }
394
395    fn execute(&self, _ctx: &mut ExecutionContext) -> CommandResult {
396        CommandResult::EmitEvent(DynEvent::new(MicroscopeOpen::new("profiles")))
397    }
398
399    fn clone_box(&self) -> Box<dyn CommandTrait> {
400        Box::new(*self)
401    }
402
403    fn as_any(&self) -> &dyn std::any::Any {
404        self
405    }
406}