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

fix: use alternative oxi binding to get filetype #28

Merged
merged 3 commits into from
Feb 27, 2023
Merged
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
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use utils::{parse_str_color, IntoFont, IntoFontStyle};

use nvim_oxi as oxi;
use oxi::{
api::{self, opts::*, types::*, Buffer, Error},
api::{self, opts::*, types::*, Error},
Dictionary, Function,
};
use silicon::{
Expand All @@ -36,12 +36,14 @@ fn save_image(opts: Opts) -> Result<(), Error> {

let code = get_lines(&opts)?;

let ft: oxi::String = Buffer::current().get_option("filetype")?;
// HACK: This allows us to avoid currently broken oxi APIs to get the filetype option.
// Instead we call into VimL and get the value that way -- super ghetto, but it works without
// any breaking changes from what I can tell.
let ft = oxi::api::exec("echo &filetype", true)?.ok_or_else(|| Error::Other(String::from("Unable to determine filetype!")))?;

let syntax = ps
.find_syntax_by_token(
ft.as_str()
.map_err(|e| Error::Other(format!("utf error: {e}")))?,
&ft
)
.ok_or_else(|| Error::Other("Could not find syntax for filetype.".to_owned()))?;

Expand Down Expand Up @@ -260,4 +262,4 @@ fn silicon() -> oxi::Result<Dictionary> {
("capture", Function::from_fn(save_image)),
("setup", Function::from_fn(setup)),
]))
}
}