aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-04-24 01:49:31 +0000
committerSkyler Hawthorne2022-06-19 03:54:03 +0000
commit2386c81ebc118860107094591b76ef3864e120a8 (patch)
treeeac56099ade96e0722ac13d92197f27db14c65b9 /helix-term/src
parent40120967e9ba48d2e8b5fb4976a6ca1ce8993704 (diff)
use idle timer instead of fixed timeout
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs37
1 files changed, 31 insertions, 6 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 15026bb6..3b96c45a 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -40,6 +40,8 @@ use {
#[cfg(windows)]
type Signals = futures_util::stream::Empty<()>;
+const LSP_DEADLINE: Duration = Duration::from_millis(16);
+
pub struct Application {
compositor: Compositor,
pub editor: Editor,
@@ -54,6 +56,7 @@ pub struct Application {
signals: Signals,
jobs: Jobs,
lsp_progress: LspProgressMap,
+ last_render: Instant,
}
#[cfg(feature = "integration")]
@@ -203,6 +206,7 @@ impl Application {
signals,
jobs: Jobs::new(),
lsp_progress: LspProgressMap::new(),
+ last_render: Instant::now(),
};
Ok(app)
@@ -230,58 +234,79 @@ impl Application {
where
S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
{
- let mut last_render = Instant::now();
- let deadline = Duration::from_secs(1) / 60;
-
self.render();
+ self.last_render = Instant::now();
loop {
if self.editor.should_close() {
break;
}
+ self.event_loop_until_idle(input_stream).await;
+ }
+ }
+
+ pub async fn event_loop_until_idle<S>(&mut self, input_stream: &mut S) -> bool
+ where
+ S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
+ {
+ loop {
+ if self.editor.should_close() {
+ return false;
+ }
+
use futures_util::StreamExt;
tokio::select! {
biased;
Some(event) = input_stream.next() => {
- self.handle_terminal_events(event)
+ self.handle_terminal_events(event);
+ self.editor.reset_idle_timer();
}
Some(signal) = self.signals.next() => {
self.handle_signals(signal).await;
+ self.editor.reset_idle_timer();
}
Some((id, call)) = self.editor.language_servers.incoming.next() => {
self.handle_language_server_message(call, id).await;
// limit render calls for fast language server messages
let last = self.editor.language_servers.incoming.is_empty();
- if last || last_render.elapsed() > deadline {
+
+ if last || self.last_render.elapsed() > LSP_DEADLINE {
self.render();
- last_render = Instant::now();
+ self.last_render = Instant::now();
}
+
+ self.editor.reset_idle_timer();
}
Some(payload) = self.editor.debugger_events.next() => {
let needs_render = self.editor.handle_debugger_message(payload).await;
if needs_render {
self.render();
}
+ self.editor.reset_idle_timer();
}
Some(config_event) = self.editor.config_events.1.recv() => {
self.handle_config_events(config_event);
self.render();
+ self.editor.reset_idle_timer();
}
Some(callback) = self.jobs.futures.next() => {
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
self.render();
+ self.editor.reset_idle_timer();
}
Some(callback) = self.jobs.wait_futures.next() => {
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
self.render();
+ self.editor.reset_idle_timer();
}
_ = &mut self.editor.idle_timer => {
// idle timeout
self.editor.clear_idle_timer();
self.handle_idle_timeout();
+ return true;
}
}
}