aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/handlers.rs
diff options
context:
space:
mode:
authorPascal Kuthe2023-11-30 23:03:27 +0000
committerBlaž Hrastnik2024-01-23 02:20:19 +0000
commit8e592a151fe7adfbf3fb35ae134b7f2a70700f09 (patch)
tree603a94042068620e52f50cb26cf881d5461d1c8d /helix-view/src/handlers.rs
parent13ed4f6c4748019787d24c2b686d417b71604242 (diff)
refactor completion and signature help using hooks
Diffstat (limited to 'helix-view/src/handlers.rs')
-rw-r--r--helix-view/src/handlers.rs37
1 files changed, 33 insertions, 4 deletions
diff --git a/helix-view/src/handlers.rs b/helix-view/src/handlers.rs
index ae3eb545..724e7b19 100644
--- a/helix-view/src/handlers.rs
+++ b/helix-view/src/handlers.rs
@@ -1,12 +1,41 @@
-use std::sync::Arc;
-
use helix_event::send_blocking;
use tokio::sync::mpsc::Sender;
use crate::handlers::lsp::SignatureHelpInvoked;
-use crate::Editor;
+use crate::{DocumentId, Editor, ViewId};
pub mod dap;
pub mod lsp;
-pub struct Handlers {}
+pub struct Handlers {
+ // only public because most of the actual implementation is in helix-term right now :/
+ pub completions: Sender<lsp::CompletionEvent>,
+ pub signature_hints: Sender<lsp::SignatureHelpEvent>,
+}
+
+impl Handlers {
+ /// Manually trigger completion (c-x)
+ pub fn trigger_completions(&self, trigger_pos: usize, doc: DocumentId, view: ViewId) {
+ send_blocking(
+ &self.completions,
+ lsp::CompletionEvent::ManualTrigger {
+ cursor: trigger_pos,
+ doc,
+ view,
+ },
+ );
+ }
+
+ pub fn trigger_signature_help(&self, invocation: SignatureHelpInvoked, editor: &Editor) {
+ let event = match invocation {
+ SignatureHelpInvoked::Automatic => {
+ if !editor.config().lsp.auto_signature_help {
+ return;
+ }
+ lsp::SignatureHelpEvent::Trigger
+ }
+ SignatureHelpInvoked::Manual => lsp::SignatureHelpEvent::Invoked,
+ };
+ send_blocking(&self.signature_hints, event)
+ }
+}