Merge pull request #71 from christopher-l/fix/async_commands

Use nvim.command_async where possible
This commit is contained in:
daa84 2018-03-18 22:51:51 +03:00 committed by GitHub
commit e286c1d95a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 30 deletions

View File

@ -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();
}
}));

View File

@ -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()
}
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}