[Neovim 0.8.0] `list_bufs` and `list_wins` not working as expected
Closed this issue · 2 comments
Hello! Looking for a bit of help (or advice). I'm not sure if this is a bug or just me not understanding how API bindings in Rust works. I'm trying to use list_bufs
and list_wins
, but neither appear to be demonstrating the same behaviour as vim.api.nvim_list_bufs
or vim.api.nvim_list_wins
. For list_bufs
, no buffers are ever found. For list_wins
, I keep hitting a segfault.
Please let me know if I'm doing anything wrong. This is on Neovim 0.8.0 and I've made sure to point to master
with the neovim-0-8
feature flag.
Thanks!
Expected
List buffers
:lua =vim.api.nvim_list_bufs()
{ 1, 2, 3 }
List windows
:lua =vim.api.nvim_list_wins()
{ 1000 }
Found
List buffers
:lua =require("nvim_open").buffers()
"[]"
List windows
:lua =require("nvim_open").windows()
fish: Job 1, 'nvim' terminated by signal SIGSEGV (Address boundary error))
Code
lib.rs
use std::convert::Infallible;
use nvim_oxi as oxi;
use oxi::{
api::{list_bufs, Buffer, Window, list_wins},
Function, Dictionary, Object
};
#[oxi::module]
fn nvim_open() -> oxi::Result<oxi::Dictionary> {
let buffers = Function::from_fn(|()| {
let open_buffers: Vec<Buffer> = list_bufs().collect();
Ok::<_, Infallible>(oxi::String::from(format!("{:?}", open_buffers)))
});
let windows = Function::from_fn(|()| {
let open_windows: Vec<Window> = list_wins().collect();
Ok::<_, Infallible>(oxi::String::from(format!("{:?}", open_windows)))
});
Ok(Dictionary::from_iter([
("buffers", Object::from(buffers)),
("windows", Object::from(windows)),
]))
}
Cargo.toml
[dependencies.nvim-oxi]
git = "https://github.com/noib3/nvim-oxi"
branch = "master"
features = [ "neovim-0-8" ]
fixed by 419563d.
Btw, you can just return a regular String
without converting it to a nvim_oxi::String
let buffers = Function::from_fn(|()| {
let open_buffers: Vec<Buffer> = list_bufs().collect();
Ok::<_, Infallible>(format!("{:?}", open_buffers))
});
let windows = Function::from_fn(|()| {
let open_windows: Vec<Window> = list_wins().collect();
Ok::<_, Infallible>(format!("{:?}", open_windows))
});
or even skip the string conversion altogether
let buffers = Function::from_fn(|()| {
let open_buffers: Vec<Buffer> = list_bufs().collect();
Ok::<_, Infallible>(open_buffers)
});
let windows = Function::from_fn(|()| {
let open_windows: Vec<Window> = list_wins().collect();
Ok::<_, Infallible>(open_windows)
});
Quick follow-up because I forgot: thank you for the fix and suggestions 🙂