Debian Codegraph @

helix-view/src/handlers/completion.rs

raw symbols SCIP
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 /// Whether the completion response is marked as "incomplete."
32 ///
33 /// This is used by LSP. When completions are "incomplete" and you continue typing, the
34 /// completions should be recomputed by the server instead of filtered.
35 pub is_incomplete: bool,
36 pub priority: i8,
37 pub savepoint: Arc<SavePoint>,
38 }
39
40 pub enum CompletionEvent {
41 /// Auto completion was triggered by typing a word char
42 AutoTrigger {
43 cursor: usize,
44 doc: DocumentId,
45 view: ViewId,
46 },
47 /// Auto completion was triggered by typing a trigger char
48 /// specified by the LSP
49 TriggerChar {
50 cursor: usize,
51 doc: DocumentId,
52 view: ViewId,
53 },
54 /// A completion was manually requested (c-x)
55 ManualTrigger {
56 cursor: usize,
57 doc: DocumentId,
58 view: ViewId,
59 },
60 /// Some text was deleted and the cursor is now at `pos`
61 DeleteText { cursor: usize },
62 /// Invalidate the current auto completion trigger
63 Cancel,
64 }