Mercurial > forks > helix
changeset 6509:844db154f222
minor: Move `CompletionEvent` to a new completion handler module
Completions are not specific to LSP anymore. In the child commits we
will expand on the types in this module so this refactor is done
eagerly to minimize changes later.
author | Michael Davis <mcarsondavis@gmail.com> |
---|---|
date | Sat, 01 Feb 2025 12:49:01 -0500 |
parents | 32eb6190dc50 |
children | c90368b2941f |
files | helix-term/src/handlers/completion.rs helix-view/src/handlers.rs helix-view/src/handlers/completion.rs helix-view/src/handlers/lsp.rs |
diffstat | 4 files changed, 31 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/helix-term/src/handlers/completion.rs Sat Feb 01 12:36:55 2025 -0500 +++ b/helix-term/src/handlers/completion.rs Sat Feb 01 12:49:01 2025 -0500 @@ -12,7 +12,7 @@ use helix_lsp::util::pos_to_lsp_pos; use helix_stdx::rope::RopeSliceExt; use helix_view::document::{Mode, SavePoint}; -use helix_view::handlers::lsp::CompletionEvent; +use helix_view::handlers::completion::CompletionEvent; use helix_view::{DocumentId, Editor, ViewId}; use path::path_completion; use tokio::sync::mpsc::Sender;
--- a/helix-view/src/handlers.rs Sat Feb 01 12:36:55 2025 -0500 +++ b/helix-view/src/handlers.rs Sat Feb 01 12:49:01 2025 -0500 @@ -4,6 +4,7 @@ use crate::handlers::lsp::SignatureHelpInvoked; use crate::{DocumentId, Editor, ViewId}; +pub mod completion; pub mod dap; pub mod diagnostics; pub mod lsp; @@ -16,7 +17,7 @@ pub struct Handlers { // only public because most of the actual implementation is in helix-term right now :/ - pub completions: Sender<lsp::CompletionEvent>, + pub completions: Sender<completion::CompletionEvent>, pub signature_hints: Sender<lsp::SignatureHelpEvent>, pub auto_save: Sender<AutoSaveEvent>, } @@ -26,7 +27,7 @@ pub fn trigger_completions(&self, trigger_pos: usize, doc: DocumentId, view: ViewId) { send_blocking( &self.completions, - lsp::CompletionEvent::ManualTrigger { + completion::CompletionEvent::ManualTrigger { cursor: trigger_pos, doc, view,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/helix-view/src/handlers/completion.rs Sat Feb 01 12:49:01 2025 -0500 @@ -0,0 +1,27 @@ +use crate::{DocumentId, ViewId}; + +pub enum CompletionEvent { + /// Auto completion was triggered by typing a word char + AutoTrigger { + cursor: usize, + doc: DocumentId, + view: ViewId, + }, + /// Auto completion was triggered by typing a trigger char + /// specified by the LSP + TriggerChar { + cursor: usize, + doc: DocumentId, + view: ViewId, + }, + /// A completion was manually requested (c-x) + ManualTrigger { + cursor: usize, + doc: DocumentId, + view: ViewId, + }, + /// Some text was deleted and the cursor is now at `pos` + DeleteText { cursor: usize }, + /// Invalidate the current auto completion trigger + Cancel, +}
--- a/helix-view/src/handlers/lsp.rs Sat Feb 01 12:36:55 2025 -0500 +++ b/helix-view/src/handlers/lsp.rs Sat Feb 01 12:49:01 2025 -0500 @@ -2,37 +2,10 @@ use crate::editor::Action; use crate::Editor; -use crate::{DocumentId, ViewId}; use helix_core::Uri; use helix_lsp::util::generate_transaction_from_edits; use helix_lsp::{lsp, OffsetEncoding}; -pub enum CompletionEvent { - /// Auto completion was triggered by typing a word char - AutoTrigger { - cursor: usize, - doc: DocumentId, - view: ViewId, - }, - /// Auto completion was triggered by typing a trigger char - /// specified by the LSP - TriggerChar { - cursor: usize, - doc: DocumentId, - view: ViewId, - }, - /// A completion was manually requested (c-x) - ManualTrigger { - cursor: usize, - doc: DocumentId, - view: ViewId, - }, - /// Some text was deleted and the cursor is now at `pos` - DeleteText { cursor: usize }, - /// Invalidate the current auto completion trigger - Cancel, -} - #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum SignatureHelpInvoked { Automatic,