Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic if api_info doesn't exist on gui_event, make Option #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/nvim/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ impl NeovimClient {
self.nvim.write().unwrap().replace(nvim);
}

pub fn api_info(&self) -> Rc<NeovimApiInfo> {
self.state
.borrow()
.api_info
.as_ref()
.expect("API info should be initialized by the time this is called")
.clone()
pub fn api_info(&self) -> Option<Rc<NeovimApiInfo>> {
self.state.borrow().api_info.as_ref().cloned()
}

pub fn set_initialized(&self, api_info: NeovimApiInfo) {
Expand Down
36 changes: 32 additions & 4 deletions src/nvim/redraw_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,46 @@ pub fn call_gui_event(
match opt_name.as_str() {
"Popupmenu" => set_ui_opt(
&nvim,
&[("ext_popupmenu", api_info.ext_popupmenu)],
&[(
"ext_popupmenu",
api_info
.as_ref()
.map(|api_info| api_info.ext_popupmenu)
.unwrap_or_default(),
)],
opt_value,
)?,
"Tabline" => {
set_ui_opt(&nvim, &[("ext_tabline", api_info.ext_tabline)], opt_value)?;
set_ui_opt(
&nvim,
&[(
"ext_tabline",
api_info
.as_ref()
.map(|api_info| api_info.ext_tabline)
.unwrap_or_default(),
)],
opt_value,
)?;
ui.set_tabline(opt_value);
}
"Cmdline" => set_ui_opt(
&nvim,
&[
("ext_cmdline", api_info.ext_cmdline),
("ext_wildmenu", api_info.ext_wildmenu),
(
"ext_cmdline",
api_info
.as_ref()
.map(|api_info| api_info.ext_cmdline)
.unwrap_or_default(),
),
(
"ext_wildmenu",
api_info
.as_ref()
.map(|api_info| api_info.ext_wildmenu)
.unwrap_or_default(),
),
],
opt_value,
)?,
Expand Down
5 changes: 3 additions & 2 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,10 +1229,11 @@ impl Shell {
let nvim_client = state.nvim.clone();

if let Some(nvim) = nvim_client.nvim() {
let api_info = nvim_client.api_info();
nvim_client.clear();
nvim.block_timeout(nvim.ui_detach()).report_err();
nvim.block_on(nvim.shutdown(api_info.channel));
if let Some(api_info) = nvim_client.api_info() {
nvim.block_on(nvim.shutdown(api_info.channel));
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ impl Ui {
let commands = commands.join("|");
let nvim_client = shell.nvim_clone();
let nvim = nvim_client.nvim().unwrap();
let channel_id = nvim_client.api_info().channel;
let channel_id = nvim_client
.api_info()
.expect("API info should be initialized by the time this is called")
.channel;
nvim.clone().spawn(async move {
let res = nvim.command(&commands).await;

Expand Down