From 72352f2de4ff6721f85c9b8ac8a8734acc9db7a1 Mon Sep 17 00:00:00 2001 From: Riccardo Mazzarini Date: Sun, 1 Oct 2023 20:12:38 +0200 Subject: [PATCH] api: update `GetExtmarkOpts` for nightly --- crates/oxi-api/src/extmark.rs | 4 ++ crates/oxi-api/src/ffi/extmark.rs | 3 +- crates/oxi-api/src/opts/get_extmarks.rs | 73 ++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/crates/oxi-api/src/extmark.rs b/crates/oxi-api/src/extmark.rs index 15323d8e..b10249a6 100644 --- a/crates/oxi-api/src/extmark.rs +++ b/crates/oxi-api/src/extmark.rs @@ -168,6 +168,7 @@ impl Buffer { opts: &GetExtmarksOpts, ) -> Result)>> { + #[cfg(not(feature = "neovim-nightly"))] let opts = Dictionary::from(opts); let mut err = nvim::Error::new(); let extmarks = unsafe { @@ -176,7 +177,10 @@ impl Buffer { ns_id as Integer, start.into(), end.into(), + #[cfg(not(feature = "neovim-nightly"))] opts.non_owning(), + #[cfg(feature = "neovim-nightly")] + opts, &mut err, ) }; diff --git a/crates/oxi-api/src/ffi/extmark.rs b/crates/oxi-api/src/ffi/extmark.rs index 12452fba..f0d43d60 100644 --- a/crates/oxi-api/src/ffi/extmark.rs +++ b/crates/oxi-api/src/ffi/extmark.rs @@ -55,7 +55,8 @@ extern "C" { ns_id: Integer, start: Object, end: Object, - opts: NonOwning, + #[cfg(not(feature = "neovim-nightly"))] opts: NonOwning, + #[cfg(feature = "neovim-nightly")] opts: *const GetExtmarksOpts, err: *mut Error, ) -> Array; diff --git a/crates/oxi-api/src/opts/get_extmarks.rs b/crates/oxi-api/src/opts/get_extmarks.rs index 377252d8..1a845852 100644 --- a/crates/oxi-api/src/opts/get_extmarks.rs +++ b/crates/oxi-api/src/opts/get_extmarks.rs @@ -1,13 +1,41 @@ +#[cfg(feature = "neovim-nightly")] +use oxi_types::{self as nvim, Boolean, Integer, String as NvimString}; +#[cfg(not(feature = "neovim-nightly"))] use oxi_types::{Dictionary, Object}; /// Options passed to /// [`Buffer::get_extmarks()`](crate::Buffer::get_extmarks). +#[cfg(not(feature = "neovim-nightly"))] #[derive(Clone, Debug, Default)] +#[repr(C)] pub struct GetExtmarksOpts { details: Object, limits: Object, } +#[cfg(feature = "neovim-nightly")] +#[derive(Clone, Debug, Default)] +#[repr(C)] +pub struct GetExtmarksOpts { + ///
1 + mask: u64, + + /// 2nd in the mask. + limits: Integer, + + /// 3rd in the mask. + details: Boolean, + + /// 4th in the mask. + hl_name: Boolean, + + /// 5th in the mask. + overlap: Boolean, + + /// 1st in the mask. + ty: NvimString, +} + impl GetExtmarksOpts { #[inline(always)] /// Creates a new [`GetExtmarksOptsBuilder`]. @@ -26,13 +54,53 @@ impl GetExtmarksOptsBuilder { /// [`Buffer::get_extmarks()`](crate::Buffer::get_extmarks). #[inline] pub fn details(&mut self, details: bool) -> &mut Self { - self.0.details = details.into(); + #[cfg(not(feature = "neovim-nightly"))] + { + self.0.details = details.into(); + } + #[cfg(feature = "neovim-nightly")] + { + self.0.details = details; + self.0.mask |= 0b1001; + } + self + } + + #[cfg(feature = "neovim-nightly")] + #[inline] + pub fn hl_name(&mut self, hl_name: bool) -> &mut Self { + self.0.hl_name = hl_name; + self.0.mask |= 0b10001; self } #[inline] pub fn limits(&mut self, limits: bool) -> &mut Self { - self.0.limits = limits.into(); + #[cfg(not(feature = "neovim-nightly"))] + { + self.0.limits = limits.into(); + } + #[cfg(feature = "neovim-nightly")] + { + self.0.limits = limits as Integer; + self.0.mask |= 0b101; + } + self + } + + #[cfg(feature = "neovim-nightly")] + #[inline] + pub fn overlap(&mut self, overlap: bool) -> &mut Self { + self.0.overlap = overlap; + self.0.mask |= 0b100001; + self + } + + #[cfg(feature = "neovim-nightly")] + #[inline] + pub fn ty>(&mut self, ty: S) -> &mut Self { + self.0.ty = ty.into(); + self.0.mask |= 0b11; self } @@ -43,6 +111,7 @@ impl GetExtmarksOptsBuilder { } } +#[cfg(not(feature = "neovim-nightly"))] impl From<&GetExtmarksOpts> for Dictionary { fn from(opts: &GetExtmarksOpts) -> Self { Self::from_iter([