Use async call in some cases

This commit is contained in:
daa 2018-01-05 15:56:55 +03:00
parent 30b7fc87e1
commit 026891938f
3 changed files with 27 additions and 21 deletions

10
Cargo.lock generated
View File

@ -302,10 +302,10 @@ dependencies = [
[[package]]
name = "neovim-lib"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.5.1"
source = "git+https://github.com/daa84/neovim-lib?branch=async#d3991cf0c81329baaa78dea905b9845ac1667a45"
dependencies = [
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rmpv 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -332,7 +332,7 @@ dependencies = [
"gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"neovim-lib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"neovim-lib 0.5.1 (git+https://github.com/daa84/neovim-lib?branch=async)",
"pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -643,7 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum neovim-lib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1889b79fccec66b11f3f9d3a266ffd97c0944af82a62843ca2b9529fedd82fec"
"checksum neovim-lib 0.5.1 (git+https://github.com/daa84/neovim-lib?branch=async)" = "<none>"
"checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
"checksum pango 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e81c404ab81ea7ea2fc2431a0a7672507b80e4b8bf4b41eac3fc83cc665104e"
"checksum pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34f34a1be107fe16abb2744e0e206bee4b3b07460b5fddd3009a6aaf60bd69ab"

View File

@ -26,7 +26,7 @@ gobject-sys = "0.5"
#pango-sys = { git = 'https://github.com/gtk-rs/sys' }
#gio = { git = 'https://github.com/gtk-rs/gio' }
#pangocairo = { git = 'https://github.com/RazrFalcon/pangocairo-rs' }
neovim-lib = "0.5"
#neovim-lib = "0.5"
phf = "0.7"
log = "0.4"
env_logger = "0.4"
@ -37,8 +37,9 @@ serde_derive = "1.0"
toml = "0.4"
serde_json = "1.0"
#[dependencies.neovim-lib]
#git = "https://github.com/daa84/neovim-lib"
[dependencies.neovim-lib]
git = "https://github.com/daa84/neovim-lib"
branch = "async"
[build-dependencies]
phf_codegen = "0.7"

View File

@ -15,7 +15,7 @@ use gtk;
use gtk::prelude::*;
use pangocairo;
use neovim_lib::{Neovim, NeovimApi, Value};
use neovim_lib::{Neovim, NeovimApi, NeovimApiAsync, Value};
use neovim_lib::neovim_api::Tabpage;
use settings::{Settings, FontSource};
@ -112,6 +112,7 @@ impl State {
/// Return NeovimRef only if vim in non blocking state
///
/// Note that this call also do neovim api call get_mode
#[allow(dead_code)]
pub fn nvim_non_blocked(&self) -> Option<NeovimRef> {
self.nvim().and_then(NeovimRef::non_blocked)
}
@ -268,10 +269,10 @@ impl State {
return;
}
if let Some(mut nvim) = self.nvim_non_blocked() {
if let Err(err) = nvim.ui_try_resize(columns as u64, rows as u64) {
error!("Error trying resize nvim {}", err);
}
if let Some(mut nvim) = self.nvim() {
nvim.ui_try_resize_async(columns as u64, rows as u64)
.cb(|r| r.report_err())
.call();
}
}
@ -280,10 +281,12 @@ impl State {
if let Some(mut nvim) = nvim {
if self.mode.is(&mode::NvimMode::Insert) || self.mode.is(&mode::NvimMode::Normal) {
let paste_code = format!("normal! \"{}P", clipboard);
nvim.command(&paste_code).report_err();
nvim.command_async(&paste_code)
.cb(|r| r.report_err())
.call();
} else {
let paste_code = format!("<C-r>{}", clipboard);
nvim.input(&paste_code).report_err();
nvim.input_async(&paste_code).cb(|r| r.report_err()).call();
};
}
@ -559,9 +562,10 @@ impl Deref for Shell {
}
fn gtk_focus_in(state: &mut State) -> Inhibit {
if let Some(mut nvim) = state.nvim_non_blocked() {
nvim.command("if exists('#FocusGained') | doautocmd FocusGained | endif")
.report_err();
if let Some(mut nvim) = state.nvim() {
nvim.command_async("if exists('#FocusGained') | doautocmd FocusGained | endif")
.cb(|r| r.report_err())
.call();
}
state.im_context.focus_in();
@ -572,9 +576,10 @@ fn gtk_focus_in(state: &mut State) -> Inhibit {
}
fn gtk_focus_out(state: &mut State) -> Inhibit {
if let Some(mut nvim) = state.nvim_non_blocked() {
nvim.command("if exists('#FocusLost') | doautocmd FocusLost | endif")
.report_err();
if let Some(mut nvim) = state.nvim() {
nvim.command_async("if exists('#FocusLost') | doautocmd FocusLost | endif")
.cb(|r| r.report_err())
.call();
}
state.im_context.focus_out();