diff options
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r-- | helix-term/src/application.rs | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 17ba2652..c55d4c98 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -9,6 +9,7 @@ use log::error; use std::{ io::{stdout, Write}, sync::Arc, + time::{Duration, Instant}, }; use anyhow::Error; @@ -82,15 +83,18 @@ impl Application { editor.new_file(Action::VerticalSplit); compositor.push(Box::new(ui::file_picker(first.clone()))); } else { + let nr_of_files = args.files.len(); + editor.open(first.to_path_buf(), Action::VerticalSplit)?; for file in args.files { if file.is_dir() { return Err(anyhow::anyhow!( "expected a path to file, found a directory. (to open a directory pass it as first argument)" )); } else { - editor.open(file, Action::VerticalSplit)?; + editor.open(file.to_path_buf(), Action::Load)?; } } + editor.set_status(format!("Loaded {} files.", nr_of_files)); } } else { editor.new_file(Action::VerticalSplit); @@ -130,6 +134,8 @@ impl Application { pub async fn event_loop(&mut self) { let mut reader = EventStream::new(); + let mut last_render = Instant::now(); + let deadline = Duration::from_secs(1) / 60; self.render(); @@ -139,26 +145,22 @@ impl Application { break; } - use futures_util::{FutureExt, StreamExt}; + use futures_util::StreamExt; tokio::select! { + biased; + event = reader.next() => { self.handle_terminal_events(event) } Some((id, call)) = self.editor.language_servers.incoming.next() => { self.handle_language_server_message(call, id).await; - - // eagerly process any other available notifications/calls - let now = std::time::Instant::now(); - let deadline = std::time::Duration::from_millis(10); - while let Some(Some((id, call))) = self.editor.language_servers.incoming.next().now_or_never() { - self.handle_language_server_message(call, id).await; - - if now.elapsed() > deadline { // use a deadline so we don't block too long - break; - } + // limit render calls for fast language server messages + let last = self.editor.language_servers.incoming.is_empty(); + if last || last_render.elapsed() > deadline { + self.render(); + last_render = Instant::now(); } - self.render(); } Some(callback) = self.jobs.futures.next() => { self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback); |