diff --git a/Cargo.lock b/Cargo.lock index e2e74f4..52d3350 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1581,9 +1581,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" +checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" dependencies = [ "hermit-abi", "libc", @@ -1592,7 +1592,7 @@ dependencies = [ [[package]] name = "nvim-rs" version = "0.1.1-alpha.0" -source = "git+https://github.com/KillTheMule/nvim-rs?branch=futures#d2012790f7d3876f3bad88185d07a030e4933d37" +source = "git+https://github.com/KillTheMule/nvim-rs?branch=futures#9efc7480f976d80f9e57443d62c1da2f37805186" dependencies = [ "async-trait", "futures 0.3.1", @@ -2452,9 +2452,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" +checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" dependencies = [ "serde", ] diff --git a/src/main.rs b/src/main.rs index ea8bf6e..e074e1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,10 +18,9 @@ use std::sync::mpsc::{channel, Receiver}; use async_trait::async_trait; use rmpv::Value; -use tokio::process::ChildStdin; -use nvim_rs::{create::tokio as create, Neovim, UiAttachOptions, Handler, -compat::tokio::Compat}; -use tokio::process::Command; +use nvim_rs::{create::tokio as create, Neovim, UiAttachOptions, Handler, compat::tokio::Compat}; +use tokio::process::{ChildStdin, Command}; +use tokio::task::spawn_blocking; use tokio::runtime::Runtime; use window::ui_loop; @@ -65,7 +64,6 @@ impl Handler for NeovimHandler { type Writer = Compat; async fn handle_notify(&self, event_name: String, arguments: Vec, _neovim: Neovim>) { - dbg!(&event_name); let parsed_events = parse_neovim_event(event_name, arguments) .unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim"); for event in parsed_events { @@ -75,7 +73,7 @@ impl Handler for NeovimHandler { } } -async fn start_nvim(editor: Arc>, receiver: Receiver) { +async fn start_nvim(editor: Arc>, receiver: Arc>>) { let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler(editor.clone())).await .unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process"); @@ -97,10 +95,13 @@ async fn start_nvim(editor: Arc>, receiver: Receiver) { .unwrap_or_explained_panic("Could not attach.", "Could not attach ui to neovim process"); loop { - let r = receiver.recv(); + let receiver = receiver.clone(); + let r = spawn_blocking(move || { + let receiver = receiver.lock().unwrap(); + receiver.recv() + }).await.expect("Could not await blocking call"); if let Ok(ui_command) = r { - dbg!(&ui_command); ui_command.execute(&nvim).await; } else { return @@ -114,7 +115,8 @@ fn main() { let editor = Arc::new(Mutex::new(Editor::new(INITIAL_WIDTH, INITIAL_HEIGHT))); let (sender, receiver) = channel::(); let editor_clone = editor.clone(); - rt.spawn_blocking(async move { + let receiver = Arc::new(Mutex::new(receiver)); + rt.spawn(async move { start_nvim(editor_clone, receiver).await; }); ui_loop(editor, sender, (INITIAL_WIDTH, INITIAL_HEIGHT));