reovim_plugin_completion/events.rs
1//! Completion plugin events
2//!
3//! Events for inter-plugin communication, following the treesitter pattern.
4
5use std::sync::Arc;
6
7use reovim_core::event_bus::Event;
8
9use crate::registry::SourceSupport;
10
11/// Event for registering a completion source
12///
13/// External plugins (e.g., LSP, snippets) emit this event to register
14/// their completion sources with the completion plugin.
15///
16/// # Example
17///
18/// ```ignore
19/// // In LSP plugin's subscribe()
20/// bus.emit(RegisterSource {
21/// source: Arc::new(LspCompletionSource::new(client)),
22/// });
23/// ```
24#[derive(Clone)]
25pub struct RegisterSource {
26 /// The completion source to register
27 pub source: Arc<dyn SourceSupport>,
28}
29
30impl std::fmt::Debug for RegisterSource {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 f.debug_struct("RegisterSource")
33 .field("source_id", &self.source.source_id())
34 .finish()
35 }
36}
37
38impl Event for RegisterSource {
39 fn priority(&self) -> u32 {
40 50 // High priority for source registration
41 }
42}
43
44/// Event emitted when completion results are ready
45///
46/// The completion plugin emits this after the saturator has computed
47/// new completion items and updated the cache.
48#[derive(Debug, Clone)]
49pub struct CompletionReady {
50 /// Buffer ID the completions are for
51 pub buffer_id: usize,
52 /// Number of completion items available
53 pub item_count: usize,
54}
55
56impl Event for CompletionReady {
57 fn priority(&self) -> u32 {
58 100 // Standard plugin priority
59 }
60}
61
62/// Event to request completion dismissal
63///
64/// Emitted when completion should be hidden (e.g., mode change, escape key).
65#[derive(Debug, Clone, Copy)]
66pub struct CompletionDismissed;
67
68impl Event for CompletionDismissed {
69 fn priority(&self) -> u32 {
70 100
71 }
72}