Add nonblocking check for resize event
Refactor error report
This commit is contained in:
parent
e6bce42532
commit
9edfa9b609
@ -2,7 +2,8 @@ use std::ops::{Deref, DerefMut};
|
||||
use std::cell::{Cell, RefCell, RefMut};
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
use neovim_lib::Neovim;
|
||||
use super::ErrorReport;
|
||||
use neovim_lib::{Neovim, NeovimApi};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum NeovimClientState {
|
||||
@ -31,6 +32,17 @@ impl<'a> NeovimRef<'a> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn non_blocked(mut self) -> Option<Self> {
|
||||
self.get_mode().ok_and_report().and_then(|mode| {
|
||||
mode.iter()
|
||||
.find(|kv| {
|
||||
kv.0.as_str().map(|key| key == "blocking").unwrap_or(false)
|
||||
})
|
||||
.map(|kv| kv.1.as_bool().unwrap_or(false))
|
||||
.and_then(|block| if block { None } else { Some(self) })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for NeovimRef<'a> {
|
||||
|
@ -1,42 +1,23 @@
|
||||
|
||||
use std::result;
|
||||
use super::client::NeovimRef;
|
||||
|
||||
use neovim_lib::{NeovimApi, CallError};
|
||||
use neovim_lib::CallError;
|
||||
|
||||
pub trait ErrorReport<T> {
|
||||
fn report_err(&self, nvim: &mut NeovimApi);
|
||||
fn report_err(&self);
|
||||
|
||||
fn ok_and_report(self, nvim: &mut NeovimApi) -> Option<T>;
|
||||
fn ok_and_report(self) -> Option<T>;
|
||||
}
|
||||
|
||||
impl<T> ErrorReport<T> for result::Result<T, CallError> {
|
||||
fn report_err(&self, _: &mut NeovimApi) {
|
||||
fn report_err(&self) {
|
||||
if let Err(ref err) = *self {
|
||||
error!("{}", err);
|
||||
//nvim.report_error(&err_msg).expect("Error report error :)");
|
||||
}
|
||||
}
|
||||
|
||||
fn ok_and_report(self, nvim: &mut NeovimApi) -> Option<T> {
|
||||
self.report_err(nvim);
|
||||
fn ok_and_report(self) -> Option<T> {
|
||||
self.report_err();
|
||||
self.ok()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NeovimExt: Sized {
|
||||
fn non_blocked(self) -> Option<Self>;
|
||||
}
|
||||
|
||||
impl <'a>NeovimExt for NeovimRef<'a> {
|
||||
fn non_blocked(mut self) -> Option<Self> {
|
||||
self.get_mode().ok_and_report(&mut *self).and_then(|mode| {
|
||||
mode.iter()
|
||||
.find(|kv| {
|
||||
kv.0.as_str().map(|key| key == "blocking").unwrap_or(false)
|
||||
})
|
||||
.map(|kv| kv.1.as_bool().unwrap_or(false))
|
||||
.and_then(|block| if block { None } else { Some(self) })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ pub use self::redraw_handler::{RedrawEvents, GuiApi};
|
||||
pub use self::repaint_mode::RepaintMode;
|
||||
pub use self::client::{NeovimClient, NeovimClientAsync, NeovimRef};
|
||||
pub use self::mode_info::{ModeInfo, CursorShape};
|
||||
pub use self::ext::{ErrorReport, NeovimExt};
|
||||
pub use self::ext::ErrorReport;
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
@ -70,7 +70,7 @@ impl Manager {
|
||||
if let Some(mut nvim) = self.nvim() {
|
||||
let loaded_plug = nvim.eval("exists('g:loaded_plug')");
|
||||
loaded_plug
|
||||
.ok_and_report(&mut *nvim)
|
||||
.ok_and_report()
|
||||
.and_then(|loaded_plug| loaded_plug.as_i64())
|
||||
.map_or(false, |loaded_plug| if loaded_plug > 0 {
|
||||
true
|
||||
@ -84,9 +84,7 @@ impl Manager {
|
||||
|
||||
pub fn reload(&self, path: &str) {
|
||||
if let Some(mut nvim) = self.nvim() {
|
||||
nvim.command(&format!("source {}", path)).report_err(
|
||||
&mut *nvim,
|
||||
);
|
||||
nvim.command(&format!("source {}", path)).report_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ fn tree_button_press(tree: >k::TreeView, ev: &EventButton, nvim: &mut Neovim)
|
||||
}
|
||||
apply_command.push_str("<C-y>");
|
||||
|
||||
nvim.input(&apply_command).report_err(nvim);
|
||||
nvim.input(&apply_command).report_err();
|
||||
}
|
||||
|
||||
Inhibit(false)
|
||||
|
@ -394,7 +394,7 @@ fn list_old_files(nvim: &mut Neovim) -> Vec<String> {
|
||||
}
|
||||
}
|
||||
err @ Err(_) => {
|
||||
err.report_err(nvim);
|
||||
err.report_err();
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
@ -427,7 +427,7 @@ impl EntryStore {
|
||||
println!("Error get current directory");
|
||||
}
|
||||
}
|
||||
err @ Err(_) => err.report_err(nvim),
|
||||
err @ Err(_) => err.report_err(),
|
||||
}
|
||||
|
||||
let old_files = list_old_files(nvim);
|
||||
|
22
src/shell.rs
22
src/shell.rs
@ -21,7 +21,7 @@ use neovim_lib::neovim_api::Tabpage;
|
||||
use settings::{Settings, FontSource};
|
||||
use ui_model::{UiModel, Attrs, ModelRect};
|
||||
use color::{ColorModel, Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
|
||||
use nvim::{self, RedrawEvents, GuiApi, RepaintMode, ErrorReport, NeovimExt, NeovimClient,
|
||||
use nvim::{self, RedrawEvents, GuiApi, RepaintMode, ErrorReport, NeovimClient,
|
||||
NeovimRef, NeovimClientAsync};
|
||||
use input;
|
||||
use input::keyval_to_input_string;
|
||||
@ -122,7 +122,7 @@ impl State {
|
||||
///
|
||||
/// Note that this call also do neovim api call get_mode
|
||||
pub fn nvim_non_blocked(&self) -> Option<NeovimRef> {
|
||||
self.nvim().and_then(NeovimExt::non_blocked)
|
||||
self.nvim().and_then(NeovimRef::non_blocked)
|
||||
}
|
||||
|
||||
pub fn nvim(&self) -> Option<NeovimRef> {
|
||||
@ -177,20 +177,20 @@ impl State {
|
||||
|
||||
pub fn open_file(&self, path: &str) {
|
||||
if let Some(mut nvim) = self.nvim() {
|
||||
nvim.command(&format!("e {}", path)).report_err(&mut *nvim);
|
||||
nvim.command(&format!("e {}", path)).report_err();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cd(&self, path: &str) {
|
||||
if let Some(mut nvim) = self.nvim() {
|
||||
nvim.command(&format!("cd {}", path)).report_err(&mut *nvim);
|
||||
nvim.command(&format!("cd {}", path)).report_err();
|
||||
}
|
||||
}
|
||||
|
||||
fn close_popup_menu(&self) {
|
||||
if self.popup_menu.borrow().is_open() {
|
||||
if let Some(mut nvim) = self.nvim() {
|
||||
nvim.input("<Esc>").report_err(&mut *nvim);
|
||||
nvim.input("<Esc>").report_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -298,7 +298,7 @@ impl State {
|
||||
gtk::timeout_add(250, move || {
|
||||
resize_state.set(ResizeState::NvimResizeRequest(columns, rows));
|
||||
|
||||
if let Some(mut nvim) = nvim.nvim() {
|
||||
if let Some(mut nvim) = nvim.nvim().and_then(NeovimRef::non_blocked) {
|
||||
if let Err(err) = nvim.ui_try_resize(columns as u64, rows as u64) {
|
||||
error!("Error trying resize nvim {}", err);
|
||||
}
|
||||
@ -341,10 +341,10 @@ 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(&mut *nvim);
|
||||
nvim.command(&paste_code).report_err();
|
||||
} else {
|
||||
let paste_code = format!("<C-r>{}", clipboard);
|
||||
nvim.input(&paste_code).report_err(&mut *nvim);
|
||||
nvim.input(&paste_code).report_err();
|
||||
};
|
||||
|
||||
}
|
||||
@ -583,7 +583,7 @@ impl Shell {
|
||||
|
||||
let nvim = state.nvim();
|
||||
if let Some(mut nvim) = nvim {
|
||||
nvim.command(":wa").report_err(&mut *nvim);
|
||||
nvim.command(":wa").report_err();
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,7 +615,7 @@ 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(&mut *nvim);
|
||||
.report_err();
|
||||
}
|
||||
|
||||
state.im_context.focus_in();
|
||||
@ -628,7 +628,7 @@ 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(&mut *nvim);
|
||||
.report_err();
|
||||
}
|
||||
|
||||
state.im_context.focus_out();
|
||||
|
@ -34,7 +34,7 @@ impl State {
|
||||
let target = &self.data[idx as usize];
|
||||
if Some(target) != self.selected.as_ref() {
|
||||
if let Some(mut nvim) = self.nvim.as_ref().unwrap().nvim() {
|
||||
nvim.set_current_tabpage(target).report_err(&mut *nvim);
|
||||
nvim.set_current_tabpage(target).report_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ fn get_hl_color(map: &HashMap<&str, &Value>, color_name: &str) -> Option<Color>
|
||||
|
||||
fn get_hl_colors(nvim: &mut Neovim, hl: &str) -> (Option<Color>, Option<Color>) {
|
||||
nvim.get_hl_by_name(hl, true)
|
||||
.ok_and_report(nvim)
|
||||
.ok_and_report()
|
||||
.and_then(|m| if let Some(m) = m.to_attrs_map_report() {
|
||||
Some((
|
||||
get_hl_color(&m, "background"),
|
||||
|
Loading…
Reference in New Issue
Block a user