| 1 |
use std::{collections::HashMap, sync::Arc}; |
| 2 |
|
| 3 |
use helix_core::completion::CompletionProvider; |
| 4 |
use helix_event::{send_blocking, TaskController}; |
| 5 |
|
| 6 |
use crate::{document::SavePoint, DocumentId, ViewId}; |
| 7 |
|
| 8 |
use tokio::sync::mpsc::Sender; |
| 9 |
|
| 10 |
pub struct CompletionHandler { |
| 11 |
event_tx: Sender<CompletionEvent>, |
| 12 |
pub active_completions: HashMap<CompletionProvider, ResponseContext>, |
| 13 |
pub request_controller: TaskController, |
| 14 |
} |
| 15 |
|
| 16 |
impl CompletionHandler { |
| 17 |
pub fn new(event_tx: Sender<CompletionEvent>) -> Self { |
| 18 |
Self { |
| 19 |
event_tx, |
| 20 |
active_completions: HashMap::new(), |
| 21 |
request_controller: TaskController::new(), |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
pub fn event(&self, event: CompletionEvent) { |
| 26 |
send_blocking(&self.event_tx, event); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
pub struct ResponseContext { |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
pub is_incomplete: bool, |
| 36 |
pub priority: i8, |
| 37 |
pub savepoint: Arc<SavePoint>, |
| 38 |
} |
| 39 |
|
| 40 |
pub enum CompletionEvent { |
| 41 |
|
| 42 |
AutoTrigger { |
| 43 |
cursor: usize, |
| 44 |
doc: DocumentId, |
| 45 |
view: ViewId, |
| 46 |
}, |
| 47 |
|
| 48 |
|
| 49 |
TriggerChar { |
| 50 |
cursor: usize, |
| 51 |
doc: DocumentId, |
| 52 |
view: ViewId, |
| 53 |
}, |
| 54 |
|
| 55 |
ManualTrigger { |
| 56 |
cursor: usize, |
| 57 |
doc: DocumentId, |
| 58 |
view: ViewId, |
| 59 |
}, |
| 60 |
|
| 61 |
DeleteText { cursor: usize }, |
| 62 |
|
| 63 |
Cancel, |
| 64 |
} |