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.
This commit is contained in:
Michael Davis 2025-02-01 12:49:01 -05:00
parent 018081a5b1
commit 1ab35ade2d
No known key found for this signature in database
4 changed files with 31 additions and 30 deletions
helix-term/src/handlers
helix-view/src

View file

@ -12,7 +12,7 @@ use helix_lsp::lsp;
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;

View file

@ -4,6 +4,7 @@ use tokio::sync::mpsc::Sender;
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 enum AutoSaveEvent {
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 @@ impl Handlers {
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,

View file

@ -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,
}

View file

@ -2,37 +2,10 @@ use std::fmt::Display;
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,