mirror of
https://github.com/noib3/nvim-oxi.git
synced 2025-08-04 19:08:31 +00:00
Fix nvim_oxi::api::notify()
(#208)
* Remove `mlua` from the `dev-dependencies` * Test `api::notify()` * Fix `api::notify()`'s API * Test `api::notify()` w/ custom provider * Add an `Arena` argument to `nvim_notify` on 0.10 and Nightly * Directly implement `Error` for `types::Error` * Test that errors returned by `vim.notify` are propagated * Fix using `mlua` in CI * Don't test `notify_custom{_err}` on `v0.9.5` on macOS and Windows
This commit is contained in:
parent
61cc490370
commit
a72ad38339
12 changed files with 96 additions and 55 deletions
|
@ -252,6 +252,8 @@ extern "C" {
|
|||
msg: NonOwning<String>,
|
||||
log_level: Integer,
|
||||
opts: NonOwning<Dictionary>,
|
||||
#[cfg(feature = "neovim-0-10")] // On 0.10 and Nightly.
|
||||
arena: *mut Arena,
|
||||
err: *mut Error,
|
||||
) -> Object;
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ mod get_mark;
|
|||
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
|
||||
mod get_namespace;
|
||||
mod get_text;
|
||||
mod notify;
|
||||
mod open_term;
|
||||
mod option;
|
||||
mod parse_cmd;
|
||||
|
@ -61,7 +60,6 @@ pub use get_mark::*;
|
|||
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
|
||||
pub use get_namespace::*;
|
||||
pub use get_text::*;
|
||||
pub use notify::*;
|
||||
pub use open_term::*;
|
||||
pub use option::*;
|
||||
pub use parse_cmd::*;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
use types::Dictionary;
|
||||
|
||||
/// Options passed to [`notify()`](crate::notify). Currently unused.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct NotifyOpts {}
|
||||
|
||||
impl NotifyOpts {
|
||||
#[inline(always)]
|
||||
pub fn builder() -> NotifyOptsBuilder {
|
||||
NotifyOptsBuilder::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct NotifyOptsBuilder(NotifyOpts);
|
||||
|
||||
impl NotifyOptsBuilder {
|
||||
#[inline]
|
||||
pub fn build(&mut self) -> NotifyOpts {
|
||||
std::mem::take(&mut self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&NotifyOpts> for Dictionary {
|
||||
fn from(_: &NotifyOpts) -> Self {
|
||||
Dictionary::new()
|
||||
}
|
||||
}
|
|
@ -715,20 +715,21 @@ pub fn load_context(ctx: EditorContext) {
|
|||
pub fn notify(
|
||||
msg: &str,
|
||||
log_level: LogLevel,
|
||||
opts: &NotifyOpts,
|
||||
) -> Result<()> {
|
||||
opts: &Dictionary,
|
||||
) -> Result<Object> {
|
||||
let msg = nvim::String::from(msg);
|
||||
let opts = Dictionary::from(opts);
|
||||
let mut err = nvim::Error::new();
|
||||
let _ = unsafe {
|
||||
let obj = unsafe {
|
||||
nvim_notify(
|
||||
msg.non_owning(),
|
||||
log_level as Integer,
|
||||
opts.non_owning(),
|
||||
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
|
||||
types::arena(),
|
||||
&mut err,
|
||||
)
|
||||
};
|
||||
choose!(err, ())
|
||||
choose!(err, Ok(obj))
|
||||
}
|
||||
|
||||
/// Binding to [`nvim_open_term()`][1].
|
||||
|
|
|
@ -2,12 +2,10 @@ use std::error::Error as StdError;
|
|||
use std::ffi::{c_char, CStr, CString};
|
||||
use std::fmt;
|
||||
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
// https://github.com/neovim/neovim/blob/v0.9.0/src/nvim/api/private/defs.h#L64-L67
|
||||
//
|
||||
/// Binding to the error type used by Neovim.
|
||||
#[derive(Clone, ThisError, Eq, PartialEq, Hash)]
|
||||
#[derive(Clone, Eq, PartialEq, Hash)]
|
||||
#[repr(C)]
|
||||
pub struct Error {
|
||||
r#type: ErrorType,
|
||||
|
@ -16,6 +14,7 @@ pub struct Error {
|
|||
|
||||
unsafe impl Send for Error {}
|
||||
unsafe impl Sync for Error {}
|
||||
impl StdError for Error {}
|
||||
|
||||
// https://github.com/neovim/neovim/blob/v0.9.0/src/nvim/api/private/defs.h#L27-L31
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue