Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into string-macro
Browse files Browse the repository at this point in the history
  • Loading branch information
SCJangra committed Oct 31, 2024
2 parents db11076 + 39b84fe commit 9197625
Show file tree
Hide file tree
Showing 35 changed files with 213 additions and 209 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

## [Unreleased]

### Added

- a `String::to_str()` method which returns a `&str` if the string contains
valid UTF-8 data;

- a `WindowConfig::mouse` field and a `WindowOptsBuilder::mouse()` method
on nightly ([#189](https://github.com/noib3/nvim-oxi/pull/189));

### Changed

- `nvim_oxi::api::echo` is now generic over the highlight group type instead of
expecting a string slice;

- renamed the `lua_<Foo>` types to `<Foo>`;

## [0.5.1] - June 23 2024

### Added

- a `handle` method on `Buffer`, `Window`, and `TabPage` which returns the
underlying handle ([#176](https://github.com/noib3/nvim-oxi/pull/176));
underlying handle ([#176](https://github.com/noib3/nvim-oxi/pull/176));

### Removed

Expand Down Expand Up @@ -66,7 +81,7 @@
## [0.4.0] - Dec 11 2023

[Unreleased]: https://github.com/noib3/nvim-oxi/compare/v0.5.1...HEAD
[0.5.0]: https://github.com/noib3/nvim-oxi/tree/v0.5.1
[0.5.1]: https://github.com/noib3/nvim-oxi/tree/v0.5.1
[0.5.0]: https://github.com/noib3/nvim-oxi/tree/v0.5.0
[0.4.2]: https://github.com/noib3/nvim-oxi/tree/v0.4.2
[0.4.1]: https://github.com/noib3/nvim-oxi/tree/v0.4.1
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl FromObject for Buffer {

impl Poppable for Buffer {
unsafe fn pop(
lstate: *mut lua::ffi::lua_State,
lstate: *mut lua::ffi::State,
) -> std::result::Result<Self, lua::Error> {
BufHandle::pop(lstate).map(Into::into)
}
Expand All @@ -80,7 +80,7 @@ impl Poppable for Buffer {
impl Pushable for Buffer {
unsafe fn push(
self,
lstate: *mut lua::ffi::lua_State,
lstate: *mut lua::ffi::State,
) -> std::result::Result<std::ffi::c_int, lua::Error> {
self.0.push(lstate)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/ffi/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extern "C" {
strict_indexing: bool,
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
arena: *mut Arena,
lstate: *mut luajit::ffi::lua_State,
lstate: *mut luajit::ffi::State,
err: *mut Error,
) -> Array;

Expand Down Expand Up @@ -124,7 +124,7 @@ extern "C" {
opts: *const GetTextOpts,
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
arena: *mut Arena,
lstate: *mut luajit::ffi::lua_State,
lstate: *mut luajit::ffi::State,
err: *mut Error,
) -> Array;

Expand Down
5 changes: 4 additions & 1 deletion crates/api/src/opts/set_highlight.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use types::Object;
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
use types::{Boolean, Integer};
use types::{Boolean, Integer, String as NvimString};

#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
#[derive(Clone, Debug, Default, PartialEq, macros::OptsBuilder)]
Expand Down Expand Up @@ -98,6 +98,9 @@ pub struct SetHighlightOpts {

#[builder(argtype = "bool")]
force: Boolean,

#[builder(skip)]
url: NvimString,
}

/// Options passed to [`set_hl()`](crate::set_hl).
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/tabpage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl From<TabPage> for Object {

impl Poppable for TabPage {
unsafe fn pop(
lstate: *mut lua::ffi::lua_State,
lstate: *mut lua::ffi::State,
) -> std::result::Result<Self, lua::Error> {
TabHandle::pop(lstate).map(Into::into)
}
Expand All @@ -55,7 +55,7 @@ impl Poppable for TabPage {
impl Pushable for TabPage {
unsafe fn push(
self,
lstate: *mut lua::ffi::lua_State,
lstate: *mut lua::ffi::State,
) -> std::result::Result<std::ffi::c_int, lua::Error> {
self.0.push(lstate)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/api/src/trait_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl HlGroup for &str {
let hl_id = unsafe {
crate::ffi::helpers::object_to_hl_id(
obj,
b"hl_group\0".as_ptr() as *const _,
c"hl_group".as_ptr() as *const _,
&mut err,
)
};
Expand Down
2 changes: 1 addition & 1 deletion crates/api/src/types/autocmd_callback_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl FromObject for AutocmdCallbackArgs {

impl luajit::Poppable for AutocmdCallbackArgs {
unsafe fn pop(
lstate: *mut luajit::ffi::lua_State,
lstate: *mut luajit::ffi::State,
) -> Result<Self, luajit::Error> {
let obj = Object::pop(lstate)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/api/src/types/command_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl FromObject for CommandArgs {

impl luajit::Poppable for CommandArgs {
unsafe fn pop(
lstate: *mut luajit::ffi::lua_State,
lstate: *mut luajit::ffi::State,
) -> Result<Self, luajit::Error> {
let obj = Object::pop(lstate)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/api/src/types/command_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'de> de::Deserialize<'de> for CommandRange {
{
struct CommandRangeVisitor;

impl<'de> de::Visitor<'de> for CommandRangeVisitor {
impl de::Visitor<'_> for CommandRangeVisitor {
type Value = CommandRange;

fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
15 changes: 15 additions & 0 deletions crates/api/src/types/window_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pub struct WindowConfig {
)]
pub hide: Option<bool>,

#[cfg_attr(docsrs, doc(cfg(feature = "neovim-nightly")))]
#[cfg(feature = "neovim-nightly")] // On 0.10 and nightly.
#[serde(default)]
pub mouse: bool,

/// If `true` then no buffer-related autocommand events such as `BufEnter`
/// or `BufLeave` are fired when calling [`open_win`](crate::open_win).
pub noautocmd: Option<bool>,
Expand Down Expand Up @@ -436,6 +441,9 @@ pub struct WindowOpts {
bufpos: Array,
external: Boolean,
focusable: Boolean,
#[cfg_attr(docsrs, doc(cfg(feature = "neovim-nightly")))]
#[cfg(feature = "neovim-nightly")]
mouse: Boolean,
vertical: Boolean,
zindex: Integer,
border: Object,
Expand Down Expand Up @@ -501,6 +509,9 @@ impl From<&WindowConfig> for WindowOpts {
builder.focusable(focusable);
}

#[cfg(feature = "neovim-nightly")]
builder.mouse(config.mouse);

if let Some(vertical) = config.vertical {
builder.vertical(vertical);
}
Expand Down Expand Up @@ -567,6 +578,8 @@ impl TryFrom<WindowOpts> for WindowConfig {
footer_pos,
height,
hide,
#[cfg(feature = "neovim-nightly")]
mouse,
noautocmd,
relative,
row,
Expand Down Expand Up @@ -639,6 +652,8 @@ impl TryFrom<WindowOpts> for WindowConfig {
))?,
height: deserialize(height)?,
hide: deserialize(hide)?,
#[cfg(feature = "neovim-nightly")]
mouse,
noautocmd: deserialize(noautocmd)?,
relative,
row: deserialize(row)?,
Expand Down
7 changes: 4 additions & 3 deletions crates/api/src/vim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,22 @@ pub fn del_var(name: &str) -> Result<()> {
/// Echoes a message to the Neovim message area.
///
/// [1]: https://neovim.io/doc/user/api.html#nvim_echo()
pub fn echo<'hl, Text, Chunks>(
pub fn echo<HlGroup, Text, Chunks>(
chunks: Chunks,
history: bool,
opts: &EchoOpts,
) -> Result<()>
where
Chunks: IntoIterator<Item = (Text, Option<&'hl str>)>,
Chunks: IntoIterator<Item = (Text, Option<HlGroup>)>,
Text: Into<nvim::String>,
HlGroup: Into<nvim::String>,
{
let chunks = chunks
.into_iter()
.map(|(text, hlgroup)| {
Array::from_iter([
Object::from(text.into()),
Object::from(hlgroup.map(|hl| hl.to_owned())),
Object::from(hlgroup.map(Into::into)),
])
})
.collect::<Array>();
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl FromObject for Window {

impl Poppable for Window {
unsafe fn pop(
lstate: *mut lua::ffi::lua_State,
lstate: *mut lua::ffi::State,
) -> std::result::Result<Self, lua::Error> {
WinHandle::pop(lstate).map(Into::into)
}
Expand All @@ -74,7 +74,7 @@ impl Poppable for Window {
impl Pushable for Window {
unsafe fn push(
self,
lstate: *mut lua::ffi::lua_State,
lstate: *mut lua::ffi::State,
) -> std::result::Result<std::ffi::c_int, lua::Error> {
self.0.push(lstate)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/libuv/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl crate::ProperLayout for uv_timer_t {}
extern "C" {
// https://github.com/luvit/luv/blob/master/src/luv.c#L751
pub(crate) fn luv_loop(
lua_state: *mut luajit::ffi::lua_State,
lua_state: *mut luajit::ffi::State,
) -> *mut uv_loop_t;

pub(crate) fn uv_async_init(
Expand Down
4 changes: 2 additions & 2 deletions crates/libuv/src/loop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cell::OnceCell;

use luajit::ffi::lua_State;
use luajit::ffi::State;

use crate::ffi;

Expand All @@ -13,7 +13,7 @@ thread_local! {
/// NOTE: this function **must** be called before calling any other function
/// exposed by this crate or there will be segfaults.
#[doc(hidden)]
pub unsafe fn init(lua_state: *mut lua_State) {
pub unsafe fn init(lua_state: *mut State) {
LOOP.with(|uv_loop| uv_loop.set(ffi::luv_loop(lua_state)))
.unwrap_unchecked();
}
Expand Down
4 changes: 2 additions & 2 deletions crates/luajit/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ffi::c_int;
use core::ffi::c_int;

use thiserror::Error as ThisError;

Expand Down Expand Up @@ -54,7 +54,7 @@ impl Error {
}

pub unsafe fn pop_wrong_type_at_idx<T>(
lstate: *mut crate::ffi::lua_State,
lstate: *mut crate::ffi::State,
idx: std::ffi::c_int,
) -> Self {
let expected = std::any::type_name::<T>();
Expand Down
Loading

0 comments on commit 9197625

Please sign in to comment.