Skip to content

Commit

Permalink
fix(api): update Buffer::set_mark on nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 7, 2023
1 parent 3a4ef97 commit 4e2b029
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
15 changes: 10 additions & 5 deletions crates/oxi-api/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use oxi_types::{
conversion::{self, FromObject, ToObject},
Array,
BufHandle,
Dictionary,
Function,
Integer,
Object,
Expand Down Expand Up @@ -107,7 +106,7 @@ impl Buffer {
let mut err = nvim::Error::new();

#[cfg(not(feature = "neovim-nightly"))]
let opts = Dictionary::from(opts);
let opts = oxi_types::Dictionary::from(opts);

let has_attached = unsafe {
nvim_buf_attach(
Expand Down Expand Up @@ -261,7 +260,7 @@ impl Buffer {
let mut err = nvim::Error::new();

#[cfg(not(feature = "neovim-nightly"))]
let opts = Dictionary::from(opts);
let opts = oxi_types::Dictionary::from(opts);

unsafe {
nvim_buf_delete(
Expand Down Expand Up @@ -452,7 +451,7 @@ impl Buffer {
{
let mut err = nvim::Error::new();
#[cfg(not(feature = "neovim-nightly"))]
let opts = Dictionary::from(opts);
let opts = oxi_types::Dictionary::from(opts);
let (start, end) = utils::range_to_limits(line_range);
let lines = unsafe {
nvim_buf_get_text(
Expand Down Expand Up @@ -603,16 +602,22 @@ impl Buffer {
name: char,
line: usize,
col: usize,
opts: &SetMarkOpts,
) -> Result<()> {
let mut err = nvim::Error::new();
let name = nvim::String::from(name);
#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))]
let opts = oxi_types::Dictionary::from(opts);
let mark_was_set = unsafe {
nvim_buf_set_mark(
self.0,
name.non_owning(),
line.try_into()?,
col.try_into()?,
Dictionary::new().non_owning(),
#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))]
opts.non_owning(),
#[cfg(feature = "neovim-nightly")]
opts,
&mut err,
)
};
Expand Down
2 changes: 2 additions & 0 deletions crates/oxi-api/src/ffi/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ extern "C" {
name: NonOwning<String>,
line: Integer,
col: Integer,
#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))]
opts: NonOwning<Dictionary>,
#[cfg(feature = "neovim-nightly")] opts: *const SetMarkOpts,
err: *mut Error,
) -> bool;

Expand Down
2 changes: 2 additions & 0 deletions crates/oxi-api/src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod select_popup_menu_item;
mod set_extmark;
mod set_highlight;
mod set_keymap;
mod set_mark;

pub use buf_attach::*;
pub use buf_delete::*;
Expand All @@ -52,3 +53,4 @@ pub use select_popup_menu_item::*;
pub use set_extmark::*;
pub use set_highlight::*;
pub use set_keymap::*;
pub use set_mark::*;
16 changes: 16 additions & 0 deletions crates/oxi-api/src/opts/set_mark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// Options passed to [`Buffer::set_mark()`](crate::Buffer::get_mark).
/// Currently unused.
#[derive(Clone, Debug, Default, oxi_macros::OptsBuilder)]
#[repr(C)]
pub struct SetMarkOpts {
#[cfg(feature = "neovim-nightly")]
#[builder(mask)]
mask: u64,
}

#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))]
impl From<&SetMarkOpts> for oxi_types::Dictionary {
fn from(_: &SetMarkOpts) -> Self {
Self::new()
}
}
3 changes: 2 additions & 1 deletion tests/src/api/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ fn set_get_del_lines() {
#[oxi::test]
fn buf_set_get_del_mark() {
let mut buf = Buffer::current();
let opts = SetMarkOpts::default();

let res = buf.set_mark('a', 1, 0);
let res = buf.set_mark('a', 1, 0, &opts);
assert_eq!(Ok(()), res);

assert_eq!((1, 0), buf.get_mark('a').unwrap());
Expand Down
3 changes: 2 additions & 1 deletion tests/src/api/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ fn set_get_del_keymap() {
#[oxi::test]
fn set_get_del_mark() {
let mut buf = Buffer::current();
let opts = SetMarkOpts::default();

let res = buf.set_mark('A', 1, 0);
let res = buf.set_mark('A', 1, 0, &opts);
assert_eq!(Ok(()), res);

assert_eq!(
Expand Down

0 comments on commit 4e2b029

Please sign in to comment.