diff --git a/src/nvim/client.rs b/src/nvim/client.rs index 325be89..cbd8150 100644 --- a/src/nvim/client.rs +++ b/src/nvim/client.rs @@ -69,9 +69,7 @@ impl NeovimClientAsync { impl Clone for NeovimClientAsync { fn clone(&self) -> Self { - NeovimClientAsync { - nvim: self.nvim.clone() - } + NeovimClientAsync { nvim: self.nvim.clone() } } } @@ -90,11 +88,17 @@ impl NeovimClient { } } + pub fn clear(&self) { + let mut nvim = self.nvim.borrow_mut(); + if nvim.is_some() { + nvim.take(); + } else { + self.nvim_async.nvim.lock().unwrap().take(); + } + } + pub fn async_to_sync(&self) { - let mut lock = self.nvim_async - .nvim - .lock() - .unwrap(); + let mut lock = self.nvim_async.nvim.lock().unwrap(); let nvim = lock.take().unwrap(); *self.nvim.borrow_mut() = Some(nvim); } diff --git a/src/shell.rs b/src/shell.rs index 1470c79..8ba03f3 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -783,7 +783,14 @@ fn init_nvim_async( thread::spawn(move || { guard.join().expect("Can't join dispatch thread"); - idle_cb_call!(state_ref.detach_cb()); + glib::idle_add(move || { + state_ref.borrow().nvim.clear(); + if let Some(ref cb) = state_ref.borrow().detach_cb { + (&mut *cb.borrow_mut())(); + } + + glib::Continue(false) + }); }); // attach ui