mirror of https://github.com/helix-editor/helix
Add a completion handler type in helix-view for tracking responses
This will replace the `Sender<CompletionEvent>` in the child commits. It tracks sender alongside extra metadata about the responses received from providers - namely whether a request is incomplete or not - which can be reused between subsequent requests to the provider.pull/12778/head
parent
1ab35ade2d
commit
4e0fc0efc6
|
@ -1,4 +1,41 @@
|
||||||
use crate::{DocumentId, ViewId};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
|
use helix_core::completion::CompletionProvider;
|
||||||
|
use helix_event::{send_blocking, TaskController};
|
||||||
|
|
||||||
|
use crate::{document::SavePoint, DocumentId, ViewId};
|
||||||
|
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
pub struct CompletionHandler {
|
||||||
|
event_tx: Sender<CompletionEvent>,
|
||||||
|
pub active_completions: HashMap<CompletionProvider, ResponseContext>,
|
||||||
|
pub request_controller: TaskController,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompletionHandler {
|
||||||
|
pub fn new(event_tx: Sender<CompletionEvent>) -> Self {
|
||||||
|
Self {
|
||||||
|
event_tx,
|
||||||
|
active_completions: HashMap::new(),
|
||||||
|
request_controller: TaskController::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn event(&self, event: CompletionEvent) {
|
||||||
|
send_blocking(&self.event_tx, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ResponseContext {
|
||||||
|
/// Whether the completion response is marked as "incomplete."
|
||||||
|
///
|
||||||
|
/// This is used by LSP. When completions are "incomplete" and you continue typing, the
|
||||||
|
/// completions should be recomputed by the server instead of filtered.
|
||||||
|
pub is_incomplete: bool,
|
||||||
|
pub priority: i8,
|
||||||
|
pub savepoint: Arc<SavePoint>,
|
||||||
|
}
|
||||||
|
|
||||||
pub enum CompletionEvent {
|
pub enum CompletionEvent {
|
||||||
/// Auto completion was triggered by typing a word char
|
/// Auto completion was triggered by typing a word char
|
||||||
|
|
Loading…
Reference in New Issue