Skip to content

Commit

Permalink
api: update GetExtmarkOpts for nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Oct 1, 2023
1 parent 8b22cb6 commit 72352f2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/oxi-api/src/extmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl Buffer {
opts: &GetExtmarksOpts,
) -> Result<impl SuperIterator<(u32, usize, usize, Option<ExtmarkInfos>)>>
{
#[cfg(not(feature = "neovim-nightly"))]
let opts = Dictionary::from(opts);
let mut err = nvim::Error::new();
let extmarks = unsafe {
Expand All @@ -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,
)
};
Expand Down
3 changes: 2 additions & 1 deletion crates/oxi-api/src/ffi/extmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ extern "C" {
ns_id: Integer,
start: Object,
end: Object,
opts: NonOwning<Dictionary>,
#[cfg(not(feature = "neovim-nightly"))] opts: NonOwning<Dictionary>,
#[cfg(feature = "neovim-nightly")] opts: *const GetExtmarksOpts,
err: *mut Error,
) -> Array;

Expand Down
73 changes: 71 additions & 2 deletions crates/oxi-api/src/opts/get_extmarks.rs
Original file line number Diff line number Diff line change
@@ -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 {
/// <overlap><hl_name><details><limit><type>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`].
Expand All @@ -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<S: Into<nvim::String>>(&mut self, ty: S) -> &mut Self {
self.0.ty = ty.into();
self.0.mask |= 0b11;
self
}

Expand All @@ -43,6 +111,7 @@ impl GetExtmarksOptsBuilder {
}
}

#[cfg(not(feature = "neovim-nightly"))]
impl From<&GetExtmarksOpts> for Dictionary {
fn from(opts: &GetExtmarksOpts) -> Self {
Self::from_iter([
Expand Down

0 comments on commit 72352f2

Please sign in to comment.