Use nvim.command_async where possible

This commit is contained in:
Christopher Lübbemeier 2018-03-18 18:45:06 +01:00
parent 6ed33aa786
commit a145256182
5 changed files with 38 additions and 30 deletions

View File

@ -13,7 +13,7 @@ use gtk;
use gtk::MenuExt; use gtk::MenuExt;
use gtk::prelude::*; use gtk::prelude::*;
use neovim_lib::NeovimApi; use neovim_lib::{NeovimApi, NeovimApiAsync};
use nvim::{ErrorReport, NeovimClient, NeovimRef}; use nvim::{ErrorReport, NeovimClient, NeovimRef};
use shell; use shell;
@ -235,9 +235,9 @@ impl FileBrowserWidget {
fn connect_events(&self) { fn connect_events(&self) {
// Open file / go to dir, when user clicks on an entry. // Open file / go to dir, when user clicks on an entry.
let store = &self.store; let store = &self.store;
let state_ref = &self.state;
let nvim_ref = self.nvim.as_ref().unwrap(); let nvim_ref = self.nvim.as_ref().unwrap();
self.tree.connect_row_activated(clone!(store, nvim_ref => move |tree, path, _| { self.tree.connect_row_activated(clone!(store, state_ref, nvim_ref => move |tree, path, _| {
let mut nvim = nvim_ref.nvim().unwrap();
let iter = store.get_iter(path).unwrap(); let iter = store.get_iter(path).unwrap();
let file_type = store let file_type = store
.get_value(&iter, Column::FileType as i32) .get_value(&iter, Column::FileType as i32)
@ -256,19 +256,20 @@ impl FileBrowserWidget {
} }
} else { } else {
// FileType::File // FileType::File
if let Some(dir) = get_current_dir(&mut nvim) { let cwd = &state_ref.borrow().current_dir;
let dir = Path::new(&dir); let cwd = Path::new(cwd);
let file_path = if let Some(rel_path) = Path::new(&file_path) let file_path = if let Some(rel_path) = Path::new(&file_path)
.strip_prefix(&dir) .strip_prefix(&cwd)
.ok() .ok()
.and_then(|p| p.to_str()) .and_then(|p| p.to_str())
{ {
rel_path rel_path
} else { } else {
&file_path &file_path
}; };
nvim.command(&format!(":e {}", file_path)).report_err(); nvim_ref.nvim().unwrap().command_async(&format!(":e {}", file_path))
} .cb(|r| r.report_err())
.call();
} }
})); }));

View File

@ -1,6 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use neovim_lib::NeovimApi; use neovim_lib::{NeovimApi, NeovimApiAsync};
use nvim::{NeovimClient, ErrorReport, NeovimRef}; use nvim::{NeovimClient, ErrorReport, NeovimRef};
use value::ValueMapExt; use value::ValueMapExt;
@ -84,7 +84,9 @@ impl Manager {
pub fn reload(&self, path: &str) { pub fn reload(&self, path: &str) {
if let Some(mut nvim) = self.nvim() { 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()
} }
} }
} }

View File

@ -184,13 +184,17 @@ impl State {
pub fn open_file(&self, path: &str) { pub fn open_file(&self, path: &str) {
if let Some(mut nvim) = self.nvim() { 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) { pub fn cd(&self, path: &str) {
if let Some(mut nvim) = self.nvim() { 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(); let nvim = state.nvim();
if let Some(mut nvim) = 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(); let nvim = state.nvim();
if let Some(mut nvim) = nvim { if let Some(mut nvim) = nvim {
nvim.command(":tabe").report_err(); nvim.command_async(":tabe").cb(|r| r.report_err()).call();
} }
} }

View File

@ -1,8 +1,8 @@
use std::collections::HashMap; 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. /// A subscription to a Neovim autocmd event.
struct Subscription { struct Subscription {
@ -93,12 +93,11 @@ impl Subscriptions {
.args .args
.iter() .iter()
.fold("".to_owned(), |acc, arg| acc + ", " + &arg); .fold("".to_owned(), |acc, arg| acc + ", " + &arg);
nvim.command(&format!( nvim.command_async(&format!(
"au {} * call rpcnotify(1, 'subscription', '{}', {} {})", "au {} * call rpcnotify(1, 'subscription', '{}', {} {})",
event_name, event_name, i, args, event_name, event_name, i, args,
)).unwrap_or_else(|err| { )).cb(|r| r.report_err())
error!("Could not set autocmd: {}", err); .call();
});
} }
} }
} }

View File

@ -10,7 +10,7 @@ use glib::signal;
use pango; use pango;
use neovim_lib::NeovimApi; use neovim_lib::{NeovimApi, NeovimApiAsync};
use neovim_lib::neovim_api::Tabpage; use neovim_lib::neovim_api::Tabpage;
use nvim; use nvim;
@ -42,7 +42,9 @@ impl State {
fn close_tab(&self, idx: u32) { fn close_tab(&self, idx: u32) {
if let Some(mut nvim) = self.nvim.as_ref().unwrap().nvim() { 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();
} }
} }
} }