diff options
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 18 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 2 | ||||
-rw-r--r-- | helix-view/src/events.rs | 9 | ||||
-rw-r--r-- | helix-view/src/handlers.rs | 12 | ||||
-rw-r--r-- | helix-view/src/handlers/lsp.rs | 39 | ||||
-rw-r--r-- | helix-view/src/lib.rs | 8 |
6 files changed, 83 insertions, 5 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 6473c2d1..93b83da4 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -36,6 +36,7 @@ use helix_core::{ }; use crate::editor::Config; +use crate::events::{DocumentDidChange, SelectionDidChange}; use crate::{DocumentId, Editor, Theme, View, ViewId}; /// 8kB of buffer space for encoding and decoding `Rope`s. @@ -1096,6 +1097,10 @@ impl Document { // TODO: use a transaction? self.selections .insert(view_id, selection.ensure_invariants(self.text().slice(..))); + helix_event::dispatch(SelectionDidChange { + doc: self, + view: view_id, + }) } /// Find the origin selection of the text in a document, i.e. where @@ -1149,6 +1154,14 @@ impl Document { let success = transaction.changes().apply(&mut self.text); if success { + if emit_lsp_notification { + helix_event::dispatch(DocumentDidChange { + doc: self, + view: view_id, + old_text: &old_doc, + }); + } + for selection in self.selections.values_mut() { *selection = selection .clone() @@ -1164,6 +1177,10 @@ impl Document { view_id, selection.clone().ensure_invariants(self.text.slice(..)), ); + helix_event::dispatch(SelectionDidChange { + doc: self, + view: view_id, + }); } self.modified_since_accessed = true; @@ -1276,6 +1293,7 @@ impl Document { } if emit_lsp_notification { + // TODO: move to hook // emit lsp notification for language_server in self.language_servers() { let notify = language_server.text_document_did_change( diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0ab4be8b..44c706d7 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -2,6 +2,7 @@ use crate::{ align_view, document::{DocumentSavedEventFuture, DocumentSavedEventResult, Mode, SavePoint}, graphics::{CursorKind, Rect}, + handlers::Handlers, info::Info, input::KeyEvent, register::Registers, @@ -960,6 +961,7 @@ pub struct Editor { /// field is set and any old requests are automatically /// canceled as a result pub completion_request_handle: Option<oneshot::Sender<()>>, + pub handlers: Handlers, } pub type Motion = Box<dyn Fn(&mut Editor)>; diff --git a/helix-view/src/events.rs b/helix-view/src/events.rs new file mode 100644 index 00000000..8b789cc0 --- /dev/null +++ b/helix-view/src/events.rs @@ -0,0 +1,9 @@ +use helix_core::Rope; +use helix_event::events; + +use crate::{Document, ViewId}; + +events! { + DocumentDidChange<'a> { doc: &'a mut Document, view: ViewId, old_text: &'a Rope } + SelectionDidChange<'a> { doc: &'a mut Document, view: ViewId } +} diff --git a/helix-view/src/handlers.rs b/helix-view/src/handlers.rs new file mode 100644 index 00000000..ae3eb545 --- /dev/null +++ b/helix-view/src/handlers.rs @@ -0,0 +1,12 @@ +use std::sync::Arc; + +use helix_event::send_blocking; +use tokio::sync::mpsc::Sender; + +use crate::handlers::lsp::SignatureHelpInvoked; +use crate::Editor; + +pub mod dap; +pub mod lsp; + +pub struct Handlers {} diff --git a/helix-view/src/handlers/lsp.rs b/helix-view/src/handlers/lsp.rs index 8b137891..95838564 100644 --- a/helix-view/src/handlers/lsp.rs +++ b/helix-view/src/handlers/lsp.rs @@ -1 +1,40 @@ +use crate::{DocumentId, ViewId}; +#[derive(Debug, Clone, Copy)] +pub struct CompletionTrigger { + /// The char position of the primary cursor when the + /// completion was triggered + pub trigger_pos: usize, + pub doc: DocumentId, + pub view: ViewId, + /// Whether the cause of the trigger was an automatic completion (any word + /// char for words longer than minimum word length). + /// This is false for trigger chars send by the LS + pub auto: bool, +} + +pub enum CompletionEvent { + /// Auto completion was triggered by typing a word char + /// or a completion trigger + Trigger(CompletionTrigger), + /// A completion was manually requested (c-x) + Manual, + /// Some text was deleted and the cursor is now at `pos` + DeleteText { pos: usize }, + /// Invalidate the current auto completion trigger + Cancel, +} + +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub enum SignatureHelpInvoked { + Automatic, + Manual, +} + +pub enum SignatureHelpEvent { + Invoked, + Trigger, + ReTrigger, + Cancel, + RequestComplete { open: bool }, +} diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index 6a68e7d6..82827b5d 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -1,17 +1,15 @@ #[macro_use] pub mod macros; +pub mod base64; pub mod clipboard; pub mod document; pub mod editor; pub mod env; +pub mod events; pub mod graphics; pub mod gutter; -pub mod handlers { - pub mod dap; - pub mod lsp; -} -pub mod base64; +pub mod handlers; pub mod info; pub mod input; pub mod keyboard; |