Skip to content

Commit

Permalink
Merge pull request #14 from turboladen/feature/mappings
Browse files Browse the repository at this point in the history
Feature/mappings
  • Loading branch information
turboladen authored Jan 25, 2022
2 parents 6ec5f75 + 4d3bf4a commit 836b229
Show file tree
Hide file tree
Showing 39 changed files with 2,709 additions and 368 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can use `nvim-api` in a similar fashion to neovim's Lua API. For example, to
`signcolumn` option to `"yes:4"`, you could do:

```rust
use nvim_api::api::nvim;
use nvim_api::nvim;

#[no_mangle]
pub extern "C" fn set_my_options() {
Expand Down
5 changes: 5 additions & 0 deletions neovim_sys/src/api/nvim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,9 @@ extern "C" {
/// Creates a new namespace, or gets and existing one.
///
pub fn nvim_create_namespace(name: NvimString) -> Integer;

/// `mode` should be the 1-letter string of the mode ("n", "i", "v", etc).
/// Returns an `Array` of `Dictionary`s.
///
pub fn nvim_get_keymap(mode: NvimString) -> Array;
}
32 changes: 17 additions & 15 deletions neovim_sys/src/api/nvim/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use super::{collection::Collection, Object, ObjectType};
use std::{
convert::TryFrom,
marker::PhantomData,
mem::{self, ManuallyDrop},
ptr,
ptr::{self, NonNull},
};

///
Expand All @@ -25,16 +26,17 @@ impl TryFrom<Object> for Array {
let mut dst = ManuallyDrop::new(Vec::with_capacity(size));

unsafe {
ptr::copy(data.array().items, dst.as_mut_ptr(), size);
ptr::copy(data.array().items.as_ptr(), dst.as_mut_ptr(), size);
dst.set_len(size);
}

let ptr = dst.as_mut_ptr();
let ptr = unsafe { NonNull::new_unchecked(dst.as_mut_ptr()) };

let a = Self {
items: ptr,
size,
capacity: size,
_marker: PhantomData,
};
mem::forget(value);
Ok(a)
Expand All @@ -54,20 +56,20 @@ mod tests {
use approx::assert_ulps_eq;

#[test]
fn test_new() {
let subject = Array::new([]);
fn test_new_from() {
let subject = Array::new_from([]);
assert_eq!(subject.len(), 0);

let subject = Array::new([Object::from(4.2)]);
let subject = Array::new_from([Object::from(4.2)]);
assert_eq!(subject.len(), 1);

let subject = Array::new([Object::from(4.2), Object::new_nil()]);
let subject = Array::new_from([Object::from(4.2), Object::new_nil()]);
assert_eq!(subject.len(), 2);
}

#[test]
fn test_vec_from_bool() {
let array = Array::new([Object::from(true), Object::from(false)]);
let array = Array::new_from([Object::from(true), Object::from(false)]);
assert_eq!(array.len(), 2);
assert_eq!(array.capacity(), 2);

Expand All @@ -81,7 +83,7 @@ mod tests {

#[test]
fn test_from_vec_int() {
let array = Array::new([
let array = Array::new_from([
Object::from(i64::max_value()),
Object::from(i64::min_value()),
]);
Expand All @@ -98,7 +100,7 @@ mod tests {

#[test]
fn test_from_vec_floats() {
let array = Array::new([Object::from(f64::MAX), Object::from(f64::MIN)]);
let array = Array::new_from([Object::from(f64::MAX), Object::from(f64::MIN)]);
assert_eq!(array.len(), 2);
assert_eq!(array.capacity(), 2);

Expand All @@ -112,7 +114,7 @@ mod tests {

#[test]
fn test_vec_strings() {
let array = Array::new([
let array = Array::new_from([
Object::from(NvimString::new_unchecked("first one")),
Object::from(NvimString::new_unchecked("second one")),
]);
Expand All @@ -135,14 +137,14 @@ mod tests {

#[test]
fn test_from_vec_of_vecs() {
let inner1_array = Array::new([Object::from(42), Object::from(42.42)]);
let inner1_array = Array::new_from([Object::from(42), Object::from(42.42)]);

let inner2_array = Array::new([
let inner2_array = Array::new_from([
Object::from(NvimString::new_unchecked("first one")),
Object::from(true),
]);

let array = Array::new([Object::from(inner1_array), Object::from(inner2_array)]);
let array = Array::new_from([Object::from(inner1_array), Object::from(inner2_array)]);
assert_eq!(array.len(), 2);
assert_eq!(array.capacity(), 2);

Expand Down Expand Up @@ -176,7 +178,7 @@ mod tests {
#[test]
fn test_clone() {
let original_array = {
Array::new([
Array::new_from([
Object::from(NvimString::new_unchecked("first one")),
Object::from(NvimString::new_unchecked("second one")),
])
Expand Down
Loading

0 comments on commit 836b229

Please sign in to comment.