diff --git a/src/file_browser.rs b/src/file_browser.rs index 2b992ac..810546f 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -13,7 +13,7 @@ use gtk; use gtk::MenuExt; use gtk::prelude::*; -use neovim_lib::NeovimApi; +use neovim_lib::{NeovimApi, NeovimApiAsync}; use nvim::{ErrorReport, NeovimClient, NeovimRef}; use shell; @@ -235,9 +235,9 @@ impl FileBrowserWidget { fn connect_events(&self) { // Open file / go to dir, when user clicks on an entry. let store = &self.store; + let state_ref = &self.state; let nvim_ref = self.nvim.as_ref().unwrap(); - self.tree.connect_row_activated(clone!(store, nvim_ref => move |tree, path, _| { - let mut nvim = nvim_ref.nvim().unwrap(); + self.tree.connect_row_activated(clone!(store, state_ref, nvim_ref => move |tree, path, _| { let iter = store.get_iter(path).unwrap(); let file_type = store .get_value(&iter, Column::FileType as i32) @@ -256,19 +256,20 @@ impl FileBrowserWidget { } } else { // FileType::File - if let Some(dir) = get_current_dir(&mut nvim) { - let dir = Path::new(&dir); - let file_path = if let Some(rel_path) = Path::new(&file_path) - .strip_prefix(&dir) - .ok() - .and_then(|p| p.to_str()) - { - rel_path - } else { - &file_path - }; - nvim.command(&format!(":e {}", file_path)).report_err(); - } + let cwd = &state_ref.borrow().current_dir; + let cwd = Path::new(cwd); + let file_path = if let Some(rel_path) = Path::new(&file_path) + .strip_prefix(&cwd) + .ok() + .and_then(|p| p.to_str()) + { + rel_path + } else { + &file_path + }; + nvim_ref.nvim().unwrap().command_async(&format!(":e {}", file_path)) + .cb(|r| r.report_err()) + .call(); } })); diff --git a/src/plug_manager/vim_plug.rs b/src/plug_manager/vim_plug.rs index e30e5b0..3bff9a6 100644 --- a/src/plug_manager/vim_plug.rs +++ b/src/plug_manager/vim_plug.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use neovim_lib::NeovimApi; +use neovim_lib::{NeovimApi, NeovimApiAsync}; use nvim::{NeovimClient, ErrorReport, NeovimRef}; use value::ValueMapExt; @@ -84,7 +84,9 @@ impl Manager { pub fn reload(&self, path: &str) { if let Some(mut nvim) = self.nvim() { - nvim.command(&format!("source {}", path)).report_err(); + nvim.command_async(&format!("source {}", path)) + .cb(|r| r.report_err()) + .call() } } } diff --git a/src/shell.rs b/src/shell.rs index ae4be61..48cca72 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -184,13 +184,17 @@ impl State { pub fn open_file(&self, path: &str) { if let Some(mut nvim) = self.nvim() { - nvim.command(&format!("e {}", path)).report_err(); + nvim.command_async(&format!("e {}", path)) + .cb(|r| r.report_err()) + .call(); } } pub fn cd(&self, path: &str) { if let Some(mut nvim) = self.nvim() { - nvim.command(&format!("cd {}", path)).report_err(); + nvim.command_async(&format!("cd {}", path)) + .cb(|r| r.report_err()) + .call(); } } @@ -600,7 +604,7 @@ impl Shell { let nvim = state.nvim(); if let Some(mut nvim) = nvim { - nvim.command(":wa").report_err(); + nvim.command_async(":wa").cb(|r| r.report_err()).call(); } } @@ -609,7 +613,7 @@ impl Shell { let nvim = state.nvim(); if let Some(mut nvim) = nvim { - nvim.command(":tabe").report_err(); + nvim.command_async(":tabe").cb(|r| r.report_err()).call(); } } diff --git a/src/subscriptions.rs b/src/subscriptions.rs index 40b7629..50db097 100644 --- a/src/subscriptions.rs +++ b/src/subscriptions.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use neovim_lib::{NeovimApi, Value}; +use neovim_lib::{NeovimApi, NeovimApiAsync, Value}; -use nvim::NeovimRef; +use nvim::{ErrorReport, NeovimRef}; /// A subscription to a Neovim autocmd event. struct Subscription { @@ -93,12 +93,11 @@ impl Subscriptions { .args .iter() .fold("".to_owned(), |acc, arg| acc + ", " + &arg); - nvim.command(&format!( + nvim.command_async(&format!( "au {} * call rpcnotify(1, 'subscription', '{}', {} {})", event_name, event_name, i, args, - )).unwrap_or_else(|err| { - error!("Could not set autocmd: {}", err); - }); + )).cb(|r| r.report_err()) + .call(); } } } diff --git a/src/tabline.rs b/src/tabline.rs index f6eb8b3..20f4d57 100644 --- a/src/tabline.rs +++ b/src/tabline.rs @@ -10,7 +10,7 @@ use glib::signal; use pango; -use neovim_lib::NeovimApi; +use neovim_lib::{NeovimApi, NeovimApiAsync}; use neovim_lib::neovim_api::Tabpage; use nvim; @@ -42,7 +42,9 @@ impl State { fn close_tab(&self, idx: u32) { if let Some(mut nvim) = self.nvim.as_ref().unwrap().nvim() { - nvim.command(&format!(":tabc {}", idx + 1)).report_err(); + nvim.command_async(&format!(":tabc {}", idx + 1)) + .cb(|r| r.report_err()) + .call(); } } }