aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorPascal Kuthe2023-03-02 22:12:50 +0000
committerBlaž Hrastnik2023-03-09 04:01:02 +0000
commit8cb7cdfd7a01b9cb50b9142e9a5d133bd1e23256 (patch)
treeeaa47f455751d44baf3e4a64d8984b56f8ec1e1e /helix-view
parente8898fd9a8ac8120827fb2d6f4752b3cb2431a62 (diff)
discard stale completion requests
Completion requests are computed asynchronously to avoid common micro freezes while editing. This means that once a completion request completes, the state of the editor might have changed. Currently, there is a check to ensure we are still in insert mode. However, we also need to ensure that the view and document hasn't changed to avoid accidentally using a savepoint with the wrong view/document. Furthermore, the editor might request a new completion while the previous completion request hasn't complemented yet. This can lead to weird flickering or an outdated completion request replacing a newer completion that has already completed (the LSP server is not required to process completion requests in order). This change also needed to ensure determinism/linear ordering so that completion popup always correspond to the last completion request.
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 5b819b33..c6541105 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -31,7 +31,7 @@ use std::{
use tokio::{
sync::{
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
- Notify, RwLock,
+ oneshot, Notify, RwLock,
},
time::{sleep, Duration, Instant, Sleep},
};
@@ -852,6 +852,14 @@ pub struct Editor {
/// avoid calculating the cursor position multiple
/// times during rendering and should not be set by other functions.
pub cursor_cache: Cell<Option<Option<Position>>>,
+ /// When a new completion request is sent to the server old
+ /// unifinished request must be dropped. Each completion
+ /// request is associated with a channel that cancels
+ /// when the channel is dropped. That channel is stored
+ /// here. When a new completion request is sent this
+ /// field is set and any old requests are automatically
+ /// canceled as a result
+ pub completion_request_handle: Option<oneshot::Sender<()>>,
}
pub type RedrawHandle = (Arc<Notify>, Arc<RwLock<()>>);
@@ -950,6 +958,7 @@ impl Editor {
redraw_handle: Default::default(),
needs_redraw: false,
cursor_cache: Cell::new(None),
+ completion_request_handle: None,
}
}