| 1 |
use completion::{CompletionEvent, CompletionHandler}; |
| 2 |
use helix_event::send_blocking; |
| 3 |
use tokio::sync::mpsc::Sender; |
| 4 |
|
| 5 |
use crate::handlers::lsp::SignatureHelpInvoked; |
| 6 |
use crate::{DocumentId, Editor, ViewId}; |
| 7 |
|
| 8 |
pub mod completion; |
| 9 |
pub mod dap; |
| 10 |
pub mod diagnostics; |
| 11 |
pub mod lsp; |
| 12 |
pub mod word_index; |
| 13 |
|
| 14 |
#[derive(Debug)] |
| 15 |
pub enum AutoSaveEvent { |
| 16 |
DocumentChanged { save_after: u64 }, |
| 17 |
LeftInsertMode, |
| 18 |
} |
| 19 |
|
| 20 |
pub struct Handlers { |
| 21 |
|
| 22 |
pub completions: CompletionHandler, |
| 23 |
pub signature_hints: Sender<lsp::SignatureHelpEvent>, |
| 24 |
pub auto_save: Sender<AutoSaveEvent>, |
| 25 |
pub document_colors: Sender<lsp::DocumentColorsEvent>, |
| 26 |
pub document_links: Sender<lsp::DocumentLinksEvent>, |
| 27 |
pub word_index: word_index::Handler, |
| 28 |
pub pull_diagnostics: Sender<lsp::PullDiagnosticsEvent>, |
| 29 |
pub pull_all_documents_diagnostics: Sender<lsp::PullAllDocumentsDiagnosticsEvent>, |
| 30 |
pub code_action_hint: Sender<lsp::CodeActionHintEvent>, |
| 31 |
} |
| 32 |
|
| 33 |
impl Handlers { |
| 34 |
|
| 35 |
pub fn trigger_completions(&self, trigger_pos: usize, doc: DocumentId, view: ViewId) { |
| 36 |
self.completions.event(CompletionEvent::ManualTrigger { |
| 37 |
cursor: trigger_pos, |
| 38 |
doc, |
| 39 |
view, |
| 40 |
}); |
| 41 |
} |
| 42 |
|
| 43 |
pub fn trigger_signature_help(&self, invocation: SignatureHelpInvoked, editor: &Editor) { |
| 44 |
let event = match invocation { |
| 45 |
SignatureHelpInvoked::Automatic => { |
| 46 |
if !editor.config().lsp.auto_signature_help { |
| 47 |
return; |
| 48 |
} |
| 49 |
lsp::SignatureHelpEvent::Trigger |
| 50 |
} |
| 51 |
SignatureHelpInvoked::Manual => lsp::SignatureHelpEvent::Invoked, |
| 52 |
}; |
| 53 |
send_blocking(&self.signature_hints, event) |
| 54 |
} |
| 55 |
|
| 56 |
pub fn word_index(&self) -> &word_index::WordIndex { |
| 57 |
&self.word_index.index |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
pub fn register_hooks(handlers: &Handlers) { |
| 62 |
lsp::register_hooks(handlers); |
| 63 |
word_index::register_hooks(handlers); |
| 64 |
} |