Use error! in place of expect() calls
This commit is contained in:
parent
a971d5f56e
commit
d02b54a521
@ -109,9 +109,10 @@ impl FileBrowserWidget {
|
|||||||
// Initialize values.
|
// Initialize values.
|
||||||
let nvim = shell_state.nvim_clone();
|
let nvim = shell_state.nvim_clone();
|
||||||
self.nvim = Some(nvim);
|
self.nvim = Some(nvim);
|
||||||
let dir = get_current_dir(&mut self.nvim().unwrap());
|
if let Some(dir) = get_current_dir(&mut self.nvim().unwrap()) {
|
||||||
update_dir_list(&dir, &self.comps.dir_list_model, &self.comps.dir_list);
|
update_dir_list(&dir, &self.comps.dir_list_model, &self.comps.dir_list);
|
||||||
self.state.borrow_mut().current_dir = dir;
|
self.state.borrow_mut().current_dir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
// Populate tree.
|
// Populate tree.
|
||||||
tree_reload(&self.store, &self.state.borrow());
|
tree_reload(&self.store, &self.state.borrow());
|
||||||
@ -255,7 +256,7 @@ impl FileBrowserWidget {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// FileType::File
|
// FileType::File
|
||||||
let dir = get_current_dir(&mut nvim);
|
if let Some(dir) = get_current_dir(&mut nvim) {
|
||||||
let dir = Path::new(&dir);
|
let dir = Path::new(&dir);
|
||||||
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(&dir)
|
||||||
@ -268,6 +269,7 @@ impl FileBrowserWidget {
|
|||||||
};
|
};
|
||||||
nvim.command(&format!(":e {}", file_path)).report_err();
|
nvim.command(&format!(":e {}", file_path)).report_err();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Connect directory list.
|
// Connect directory list.
|
||||||
@ -441,9 +443,14 @@ fn populate_tree_nodes(
|
|||||||
parent: Option<>k::TreeIter>,
|
parent: Option<>k::TreeIter>,
|
||||||
) {
|
) {
|
||||||
let path = Path::new(dir);
|
let path = Path::new(dir);
|
||||||
let iter = path.read_dir()
|
let read_dir = match path.read_dir() {
|
||||||
.expect("read dir failed")
|
Ok(read_dir) => read_dir,
|
||||||
.filter_map(Result::ok);
|
Err(err) => {
|
||||||
|
error!("Couldn't populate tree: {}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let iter = read_dir.filter_map(Result::ok);
|
||||||
let mut entries: Vec<DirEntry> = if state.show_hidden {
|
let mut entries: Vec<DirEntry> = if state.show_hidden {
|
||||||
iter.collect()
|
iter.collect()
|
||||||
} else {
|
} else {
|
||||||
@ -501,13 +508,14 @@ fn populate_tree_nodes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_current_dir(nvim: &mut NeovimRef) -> String {
|
fn get_current_dir(nvim: &mut NeovimRef) -> Option<String> {
|
||||||
nvim.eval("getcwd()")
|
match nvim.eval("getcwd()") {
|
||||||
.as_ref()
|
Ok(cwd) => cwd.as_str().map(|s| s.to_owned()),
|
||||||
.ok()
|
Err(err) => {
|
||||||
.and_then(|s| s.as_str())
|
error!("Couldn't get cwd: {}", err);
|
||||||
.expect("Couldn't get working directory")
|
None
|
||||||
.to_owned()
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reveals and selects the given file in the file browser.
|
/// Reveals and selects the given file in the file browser.
|
||||||
|
Loading…
Reference in New Issue
Block a user