[Chore] upgrade nvim-oxi to v0.5.1 (#131)

main
The Mist 2024-09-22 14:39:06 +08:00 committed by GitHub
parent c2924bf6c9
commit 3a095492ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 90 additions and 170 deletions

209
generator/Cargo.lock generated
View File

@ -87,26 +87,6 @@ dependencies = [
"serde",
]
[[package]]
name = "bindgen"
version = "0.68.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078"
dependencies = [
"bitflags 2.6.0",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -199,15 +179,6 @@ version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f"
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -220,17 +191,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "clang-sys"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "clipboard-win"
version = "5.4.0"
@ -557,12 +517,6 @@ dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.14.5"
@ -632,18 +586,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.155"
@ -666,17 +608,6 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "libuv-sys2"
version = "1.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6125e1a220a5698a154ce76762d2ef8884baf9f77da7ceb8a3bd8c5ce27df343"
dependencies = [
"bindgen",
"cc",
"pkg-config",
]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
@ -775,15 +706,71 @@ dependencies = [
[[package]]
name = "nvim-oxi"
version = "0.3.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d10f3bf0588ed64f764acdb0bef3883b87f1491ff24005a8887bd9fe9c829061"
checksum = "13587f8434641462a0674bc575fb1ca88d66827118470df3c2608e769fc8e3ee"
dependencies = [
"oxi-api",
"oxi-libuv",
"oxi-luajit",
"oxi-macros",
"oxi-types",
"nvim-oxi-api",
"nvim-oxi-libuv",
"nvim-oxi-luajit",
"nvim-oxi-macros",
"nvim-oxi-types",
"thiserror",
]
[[package]]
name = "nvim-oxi-api"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0926b8fac04e376a743a7519382ef21c9d6e3ef584338d439972b911e5d85554"
dependencies = [
"nvim-oxi-luajit",
"nvim-oxi-macros",
"nvim-oxi-types",
"serde",
"serde_repr",
"thiserror",
]
[[package]]
name = "nvim-oxi-libuv"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23c92031113da2a83addafb6d50508f96941f017ee2249b1d27b08094355cefd"
dependencies = [
"nvim-oxi-luajit",
"thiserror",
]
[[package]]
name = "nvim-oxi-luajit"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3d83bb0ca6908c82bad8b22379f7577d0d82aa050601c0dce15d7c691c2131a"
dependencies = [
"thiserror",
]
[[package]]
name = "nvim-oxi-macros"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0db91ed44967f43c9ac9f80ce629391f53787aac6212aac79966422940671f9"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "nvim-oxi-types"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2545fa96873e7bc0bd12e1e68582a89ca593fad872e996e479a8615ae986424"
dependencies = [
"libc",
"nvim-oxi-luajit",
"serde",
"thiserror",
]
@ -924,64 +911,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "oxi-api"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17baa7880f7e8e0b24e523c8278957f769682c1e059b99f875c3c20ff9ca23fb"
dependencies = [
"oxi-luajit",
"oxi-types",
"serde",
"serde_repr",
"thiserror",
]
[[package]]
name = "oxi-libuv"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "beccafca2a99579ed75c536f3579c1ae19537330bca908ce034519fda6e2c99d"
dependencies = [
"libuv-sys2",
"once_cell",
"oxi-luajit",
"thiserror",
]
[[package]]
name = "oxi-luajit"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d1c5f855fc99e1f9f287958d679fb636bf68a784255cbb0e403dbc01495393c"
dependencies = [
"once_cell",
"thiserror",
]
[[package]]
name = "oxi-macros"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fa77de5791207f41bab307dadb91e66a2bbbd19433e4243ef98c9d45e03a007"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "oxi-types"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5f4061c29de229c3ece5e8d22cd29a3e28c64977acda5caeb72cfe8eeb04659"
dependencies = [
"libc",
"oxi-luajit",
"serde",
"thiserror",
]
[[package]]
name = "parking_lot"
version = "0.12.3"
@ -1005,12 +934,6 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "petgraph"
version = "0.6.5"
@ -1287,12 +1210,6 @@ dependencies = [
"syn",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "simd-adler32"
version = "0.3.7"

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
nvim-oxi = { features = ["neovim-0-9", "libuv", "oxi-libuv"], version = "0.3" }
nvim-oxi = { features = ["neovim-0-9", "libuv"], version = "0.5.1" }
tiny-skia = "0.11.4"
syntect = "5.2.0"
cosmic-text = "0.12.0"

View File

@ -1,4 +1,3 @@
use nvim_oxi::lua;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, RenderError>;
@ -21,8 +20,8 @@ pub enum RenderError {
NoSuchFile(String),
}
impl From<RenderError> for nvim_oxi::Error {
impl From<RenderError> for nvim_oxi::api::Error {
fn from(err: RenderError) -> Self {
nvim_oxi::Error::Lua(lua::Error::RuntimeError(err.to_string()))
nvim_oxi::api::Error::Other(err.to_string())
}
}

View File

@ -3,11 +3,11 @@ use crate::{config::TakeSnapshotParams, snapshot::take_snapshot};
use arboard::SetExtLinux;
use arboard::{Clipboard, ImageData};
use nvim_oxi::Result;
use nvim_oxi::api;
// The function will be called as FFI on Lua side
#[allow(dead_code)]
pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<()> {
pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<(), api::Error> {
let pixmap = take_snapshot(config.clone())?;
let premultplied_colors = pixmap.pixels();
let colors = premultplied_colors

View File

@ -5,7 +5,7 @@ use crate::{
use arboard::Clipboard;
#[cfg(target_os = "linux")]
use arboard::SetExtLinux;
use nvim_oxi::Result;
use nvim_oxi::api;
use std::cmp::max;
const SPACE_BOTH_SIDE: usize = 2;
@ -19,7 +19,7 @@ fn optional(component: String, is_view: bool) -> String {
}
#[allow(dead_code)]
pub fn copy_ascii(params: TakeSnapshotParams) -> Result<()> {
pub fn copy_ascii(params: TakeSnapshotParams) -> Result<(), api::Error> {
let code = prepare_code(&params.code);
let (width, height) = calc_wh(&code, 1., 1.);
let calc_line_number_width =
@ -71,7 +71,10 @@ pub fn copy_ascii(params: TakeSnapshotParams) -> Result<()> {
});
#[cfg(not(target_os = "linux"))]
Clipboard::new().unwrap().set_text(ascii_snapshot).unwrap();
Clipboard::new()
.unwrap()
.set_text(ascii_snapshot)
.map_err(|err| api::Error::Other(err.to_string()))?;
Ok(())
}

View File

@ -11,18 +11,19 @@ mod save;
mod snapshot;
mod text;
use config::TakeSnapshotParams;
use copy::copy_into_clipboard;
use copy_ascii::copy_ascii;
use nvim_oxi::{Dictionary, Function, Result};
use nvim_oxi::{api, Dictionary, Function};
use save::save_snapshot;
#[nvim_oxi::module]
fn generator() -> Result<Dictionary> {
#[nvim_oxi::plugin]
fn generator() -> nvim_oxi::Result<Dictionary> {
let copy_into_clipboard: Function<TakeSnapshotParams, Result<(), api::Error>> =
Function::from_fn(copy_into_clipboard);
Ok(Dictionary::from_iter([
(
"copy_into_clipboard",
Function::from_fn(copy_into_clipboard),
),
("copy_into_clipboard", copy_into_clipboard),
("save_snapshot", Function::from_fn(save_snapshot)),
("copy_ascii", Function::from_fn(copy_ascii)),
]))

View File

@ -1,27 +1,27 @@
use crate::{config::TakeSnapshotParams, path::parse_save_path, snapshot::take_snapshot};
use nvim_oxi::{lua::Error::RuntimeError, Error, Result};
use nvim_oxi::api;
// The function will be called as FFI on Lua side
#[allow(dead_code)]
pub fn save_snapshot(config: TakeSnapshotParams) -> Result<()> {
pub fn save_snapshot(config: TakeSnapshotParams) -> Result<(), api::Error> {
match &config.save_path {
Some(path) => {
if !path.ends_with(".png") {
return Err(Error::Lua(RuntimeError(
return Err(api::Error::Other(
"The save_path must ends with .png".to_string(),
)));
));
}
let pixmap = take_snapshot(config.clone())?;
let path = parse_save_path(path.to_string())
.map_err(|err| Error::Lua(RuntimeError(err.to_string())))?;
.map_err(|err| api::Error::Other(err.to_string()))?;
pixmap
.save_png(path)
.map_err(|err| Error::Lua(RuntimeError(err.to_string())))
.map_err(|err| api::Error::Other(err.to_string()))
}
None => Err(Error::Lua(RuntimeError(
None => Err(api::Error::Other(
"Cannot find 'save_path' in config".to_string(),
))),
)),
}
}