Fix compilation, show errors
This commit is contained in:
parent
7a46e1cac5
commit
ba20088bc6
13
src/error.rs
13
src/error.rs
@ -28,6 +28,19 @@ impl ErrorArea {
|
||||
ErrorArea { base, label }
|
||||
}
|
||||
|
||||
pub fn show_nvim_init_error(&self, err: &str) {
|
||||
error!("Can't initialize nvim: {}", err);
|
||||
self.label.set_markup(&format!("<big>Can't initialize nvim:</big>\n\
|
||||
<span foreground=\"red\"><i>{}</i></span>\n\n\
|
||||
<big>Possible error reasons:</big>\n\
|
||||
● Not supported nvim version (minimum supported version is <b>{}</b>)\n\
|
||||
● Error in configuration file (init.vim or ginit.vim)\n\
|
||||
● Wrong nvim binary path \
|
||||
(right path can be passed with <i>--nvim-bin-path=path_here</i>)",
|
||||
encode_minimal(err), shell::MINIMUM_SUPPORTED_NVIM_VERSION));
|
||||
self.base.show_all();
|
||||
}
|
||||
|
||||
pub fn show_nvim_start_error(&self, err: &str, cmd: &str) {
|
||||
error!("Can't start nvim: {}\nCommand line: {}", err, cmd);
|
||||
self.label.set_markup(&format!("<big>Can't start nvim instance:</big>\n\
|
||||
|
50
src/nvim.rs
50
src/nvim.rs
@ -526,41 +526,41 @@ impl RepaintMode {
|
||||
}
|
||||
|
||||
|
||||
enum NeovimClientWrapper {
|
||||
enum NeovimClientState {
|
||||
Uninitialized,
|
||||
InitInProgress,
|
||||
Initialized(Neovim),
|
||||
Error,
|
||||
}
|
||||
|
||||
impl NeovimClientWrapper {
|
||||
impl NeovimClientState {
|
||||
pub fn is_uninitialized(&self) -> bool {
|
||||
match *self {
|
||||
NeovimClientWrapper::Uninitialized => true,
|
||||
NeovimClientState::Uninitialized => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_initialized(&self) -> bool {
|
||||
match *self {
|
||||
NeovimClientWrapper::Initialized(_) => true,
|
||||
NeovimClientState::Initialized(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_error(&self) -> bool {
|
||||
match *self {
|
||||
NeovimClientWrapper::Error => true,
|
||||
NeovimClientState::Error => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nvim(&self) -> &Neovim {
|
||||
match *self {
|
||||
NeovimClientWrapper::Initialized(ref nvim) => nvim,
|
||||
NeovimClientWrapper::InitInProgress |
|
||||
NeovimClientWrapper::Uninitialized => panic!("Access to uninitialized neovim client"),
|
||||
NeovimClientWrapper::Error => {
|
||||
NeovimClientState::Initialized(ref nvim) => nvim,
|
||||
NeovimClientState::InitInProgress |
|
||||
NeovimClientState::Uninitialized => panic!("Access to uninitialized neovim client"),
|
||||
NeovimClientState::Error => {
|
||||
panic!("Access to neovim client that is not started due to some error")
|
||||
}
|
||||
}
|
||||
@ -568,10 +568,10 @@ impl NeovimClientWrapper {
|
||||
|
||||
pub fn nvim_mut(&mut self) -> &mut Neovim {
|
||||
match *self {
|
||||
NeovimClientWrapper::Initialized(ref mut nvim) => nvim,
|
||||
NeovimClientWrapper::InitInProgress |
|
||||
NeovimClientWrapper::Uninitialized => panic!("Access to uninitialized neovim client"),
|
||||
NeovimClientWrapper::Error => {
|
||||
NeovimClientState::Initialized(ref mut nvim) => nvim,
|
||||
NeovimClientState::InitInProgress |
|
||||
NeovimClientState::Uninitialized => panic!("Access to uninitialized neovim client"),
|
||||
NeovimClientState::Error => {
|
||||
panic!("Access to neovim client that is not started due to some error")
|
||||
}
|
||||
}
|
||||
@ -579,40 +579,44 @@ impl NeovimClientWrapper {
|
||||
}
|
||||
|
||||
pub struct NeovimClient {
|
||||
nvim: NeovimClientWrapper,
|
||||
state: NeovimClientState,
|
||||
}
|
||||
|
||||
impl NeovimClient {
|
||||
pub fn new() -> Self {
|
||||
NeovimClient { nvim: NeovimClientWrapper::Uninitialized }
|
||||
NeovimClient { state: NeovimClientState::Uninitialized }
|
||||
}
|
||||
|
||||
pub fn set_nvim(&mut self, nvim: Neovim) {
|
||||
self.nvim = NeovimClientWrapper::Initialized(nvim);
|
||||
pub fn set_initialized(&mut self, nvim: Neovim) {
|
||||
self.state = NeovimClientState::Initialized(nvim);
|
||||
}
|
||||
|
||||
pub fn set_error(&mut self) {
|
||||
self.nvim = NeovimClientWrapper::Error;
|
||||
self.state = NeovimClientState::Error;
|
||||
}
|
||||
|
||||
pub fn set_in_progress(&mut self) {
|
||||
self.state = NeovimClientState::InitInProgress;
|
||||
}
|
||||
|
||||
pub fn is_initialized(&self) -> bool {
|
||||
self.nvim.is_initialized()
|
||||
self.state.is_initialized()
|
||||
}
|
||||
|
||||
pub fn is_uninitialized(&self) -> bool {
|
||||
self.nvim.is_uninitialized()
|
||||
self.state.is_uninitialized()
|
||||
}
|
||||
|
||||
pub fn is_error(&self) -> bool {
|
||||
self.nvim.is_error()
|
||||
self.state.is_error()
|
||||
}
|
||||
|
||||
pub fn nvim(&self) -> &Neovim {
|
||||
self.nvim.nvim()
|
||||
self.state.nvim()
|
||||
}
|
||||
|
||||
pub fn nvim_mut(&mut self) -> &mut Neovim {
|
||||
self.nvim.nvim_mut()
|
||||
self.state.nvim_mut()
|
||||
}
|
||||
}
|
||||
|
||||
|
76
src/shell.rs
76
src/shell.rs
@ -238,6 +238,14 @@ impl State {
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn show_error_area(&self) {
|
||||
let stack = self.stack.clone();
|
||||
gtk::idle_add(move || {
|
||||
stack.set_visible_child_name("Error");
|
||||
Continue(false)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UiState {
|
||||
@ -554,7 +562,17 @@ fn init_nvim_async(state_arc: Arc<UiMutex<State>>,
|
||||
let mut nvim = match nvim::start(state_arc.clone(), options.nvim_bin_path.as_ref()) {
|
||||
Ok(nvim) => nvim,
|
||||
Err(err) => {
|
||||
// TODO: process error //
|
||||
let source = err.source();
|
||||
let cmd = err.cmd().unwrap().to_owned();
|
||||
|
||||
glib::idle_add(move || {
|
||||
let state = state_arc.borrow();
|
||||
state.nvim.borrow_mut().set_error();
|
||||
state.error_area.show_nvim_start_error(&source, &cmd);
|
||||
state.show_error_area();
|
||||
|
||||
Continue(false)
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
@ -569,59 +587,45 @@ fn init_nvim_async(state_arc: Arc<UiMutex<State>>,
|
||||
});
|
||||
|
||||
// attach ui
|
||||
let state_ref = state_arc.clone();
|
||||
let mut post_init = Some(move || {
|
||||
let mut nvim = nvim;
|
||||
let mut nvim = Some(nvim);
|
||||
glib::idle_add(move || {
|
||||
let mut nvim = nvim.take().unwrap();
|
||||
if let Err(err) = nvim::post_start_init(&mut nvim,
|
||||
options.open_path.as_ref(),
|
||||
cols as u64,
|
||||
rows as u64) {
|
||||
// TODO: process error //
|
||||
let source = err.source();
|
||||
|
||||
let state_ref = state_arc.clone();
|
||||
glib::idle_add(move || {
|
||||
let state = state_ref.borrow();
|
||||
state.nvim.borrow_mut().set_error();
|
||||
state.error_area.show_nvim_init_error(&source);
|
||||
state.show_error_area();
|
||||
|
||||
Continue(false)
|
||||
});
|
||||
} else {
|
||||
let state = state_arc.borrow_mut();
|
||||
state.nvim.borrow_mut().set_initialized(nvim);
|
||||
}
|
||||
|
||||
let state = state_arc.borrow_mut();
|
||||
state.nvim.borrow_mut().set_nvim(nvim);
|
||||
});
|
||||
|
||||
glib::idle_add(move || {
|
||||
let cl = post_init.take();
|
||||
cl();
|
||||
Continue(false)
|
||||
});
|
||||
|
||||
//{
|
||||
//Ok(nvim) => nvim,
|
||||
//Err(err) => {
|
||||
//nvim_client.set_error();
|
||||
//state
|
||||
//.error_area
|
||||
//.show_nvim_start_error(&err.source(), err.cmd());
|
||||
|
||||
//let stack = state.stack.clone();
|
||||
//gtk::idle_add(move || {
|
||||
//stack.set_visible_child_name("Error");
|
||||
//Continue(false)
|
||||
//});
|
||||
|
||||
//return;
|
||||
//}
|
||||
//};
|
||||
|
||||
|
||||
|
||||
//nvim_client.set_nvim(nvim);
|
||||
}
|
||||
|
||||
fn init_nvim(state_arc: &Arc<UiMutex<State>>) {
|
||||
let state = state_arc.borrow();
|
||||
|
||||
if state.nvim.borrow().is_uninitialized() {
|
||||
let mut nvim = state.nvim.borrow_mut();
|
||||
if nvim.is_uninitialized() {
|
||||
nvim.set_in_progress();
|
||||
|
||||
let (cols, rows) = state.calc_nvim_size().unwrap();
|
||||
|
||||
let state_arc = state_arc.clone();
|
||||
let options = state.options.clone();
|
||||
thread::spawn(move || { init_nvim_async(state_arc, options, cols, rows); });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user