aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-09-09 08:59:48 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-09-12 13:25:28 -0300
commit2792a0e33c0845fdd5b1b752d99ee573f6534256 (patch)
tree6b7fd940dd8a93f2957ecc11c99f64db8662c398 /src
parent38dcfb60627cbdfa2eaf5d0d991c872c85868f22 (diff)
downloadrneovim-2792a0e33c0845fdd5b1b752d99ee573f6534256.tar.gz
rneovim-2792a0e33c0845fdd5b1b752d99ee573f6534256.tar.bz2
rneovim-2792a0e33c0845fdd5b1b752d99ee573f6534256.zip
api/msgpack-rpc: Remove Position type, using arrays instead.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/buffer.c9
-rw-r--r--src/nvim/api/private/defs.h7
-rw-r--r--src/nvim/api/window.c38
-rw-r--r--src/nvim/os/msgpack_rpc_helpers.c21
-rw-r--r--src/nvim/os/msgpack_rpc_helpers.h4
5 files changed, 26 insertions, 53 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 380de12c89..383e13fd92 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -447,9 +447,9 @@ void buffer_insert(Buffer buffer, Integer lnum, Array lines, Error *err)
/// @param name The mark's name
/// @param[out] err Details of an error that may have occurred
/// @return The (row, col) tuple
-Position buffer_get_mark(Buffer buffer, String name, Error *err)
+Array buffer_get_mark(Buffer buffer, String name, Error *err)
{
- Position rv = POSITION_INIT;
+ Array rv = ARRAY_DICT_INIT;
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
@@ -479,8 +479,9 @@ Position buffer_get_mark(Buffer buffer, String name, Error *err)
return rv;
}
- rv.row = posp->lnum;
- rv.col = posp->col;
+ ADD(rv, INTEGER_OBJ(posp->lnum));
+ ADD(rv, INTEGER_OBJ(posp->col));
+
return rv;
}
diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h
index 689594f231..11800ed786 100644
--- a/src/nvim/api/private/defs.h
+++ b/src/nvim/api/private/defs.h
@@ -8,7 +8,6 @@
#define ARRAY_DICT_INIT {.size = 0, .items = NULL}
#define STRING_INIT {.data = NULL, .size = 0}
#define OBJECT_INIT { .type = kObjectTypeNil }
-#define POSITION_INIT { .row = 0, .col = 0 }
#define REMOTE_TYPE(type) typedef uint64_t type
// Basic types
@@ -33,10 +32,6 @@ REMOTE_TYPE(Tabpage);
typedef struct object Object;
typedef struct {
- Integer row, col;
-} Position;
-
-typedef struct {
Object *items;
size_t size, capacity;
} Array;
@@ -52,7 +47,6 @@ typedef enum {
// The following comments are markers that msgpack-gen.lua uses to extract
// types, don't remove!
// start custom types
- kObjectTypePosition,
kObjectTypeBuffer,
kObjectTypeWindow,
kObjectTypeTabpage,
@@ -69,7 +63,6 @@ typedef enum {
struct object {
ObjectType type;
union {
- Position position;
Buffer buffer;
Window window;
Tabpage tabpage;
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 1ab441bed3..967d8acda4 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -33,14 +33,14 @@ Buffer window_get_buffer(Window window, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return the (row, col) tuple
-Position window_get_cursor(Window window, Error *err)
+Array window_get_cursor(Window window, Error *err)
{
- Position rv = POSITION_INIT;
+ Array rv = ARRAY_DICT_INIT;
win_T *win = find_window_by_handle(window, err);
if (win) {
- rv.row = win->w_cursor.lnum;
- rv.col = win->w_cursor.col;
+ ADD(rv, INTEGER_OBJ(win->w_cursor.lnum));
+ ADD(rv, INTEGER_OBJ(win->w_cursor.col));
}
return rv;
@@ -51,31 +51,35 @@ Position window_get_cursor(Window window, Error *err)
/// @param window The window handle
/// @param pos the (row, col) tuple representing the new position
/// @param[out] err Details of an error that may have occurred
-void window_set_cursor(Window window, Position pos, Error *err)
+void window_set_cursor(Window window, Array pos, Error *err)
{
win_T *win = find_window_by_handle(window, err);
- if (!win) {
+ if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger ||
+ pos.items[1].type != kObjectTypeInteger) {
+ set_api_error("\"pos\" argument must be a [row, col] array", err);
return;
}
- if (pos.row <= 0 || pos.row > win->w_buffer->b_ml.ml_line_count) {
- set_api_error("cursor position outside buffer", err);
+ if (!win) {
return;
}
- if (pos.row > LONG_MAX || pos.row < LONG_MIN) {
- set_api_error("Row value outside range", err);
+ int64_t row = pos.items[0].data.integer;
+ int64_t col = pos.items[1].data.integer;
+
+ if (row <= 0 || row > win->w_buffer->b_ml.ml_line_count) {
+ set_api_error("cursor position outside buffer", err);
return;
}
- if (pos.col > INT_MAX || pos.col < INT_MIN) {
+ if (col > MAXCOL || col < 0) {
set_api_error("Column value outside range", err);
return;
}
- win->w_cursor.lnum = (linenr_T)pos.row;
- win->w_cursor.col = (colnr_T)pos.col;
+ win->w_cursor.lnum = (linenr_T)row;
+ win->w_cursor.col = (colnr_T)col;
win->w_cursor.coladd = 0;
// When column is out of range silently correct it.
check_cursor_col_win(win);
@@ -243,14 +247,14 @@ void window_set_option(Window window, String name, Object value, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return The (row, col) tuple with the window position
-Position window_get_position(Window window, Error *err)
+Array window_get_position(Window window, Error *err)
{
- Position rv = POSITION_INIT;
+ Array rv = ARRAY_DICT_INIT;
win_T *win = find_window_by_handle(window, err);
if (win) {
- rv.col = win->w_wincol;
- rv.row = win->w_winrow;
+ ADD(rv, INTEGER_OBJ(win->w_winrow));
+ ADD(rv, INTEGER_OBJ(win->w_wincol));
}
return rv;
diff --git a/src/nvim/os/msgpack_rpc_helpers.c b/src/nvim/os/msgpack_rpc_helpers.c
index 5d2f53bbcf..67c37fa8f4 100644
--- a/src/nvim/os/msgpack_rpc_helpers.c
+++ b/src/nvim/os/msgpack_rpc_helpers.c
@@ -132,15 +132,6 @@ bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg)
}
}
-bool msgpack_rpc_to_position(msgpack_object *obj, Position *arg)
-{
- return obj->type == MSGPACK_OBJECT_ARRAY
- && obj->via.array.size == 2
- && msgpack_rpc_to_integer(obj->via.array.ptr, &arg->row)
- && msgpack_rpc_to_integer(obj->via.array.ptr + 1, &arg->col);
-}
-
-
bool msgpack_rpc_to_array(msgpack_object *obj, Array *arg)
{
if (obj->type != MSGPACK_OBJECT_ARRAY) {
@@ -236,10 +227,6 @@ void msgpack_rpc_from_object(Object result, msgpack_packer *res)
msgpack_rpc_from_array(result.data.array, res);
break;
- case kObjectTypePosition:
- msgpack_rpc_from_position(result.data.position, res);
- break;
-
case kObjectTypeBuffer:
msgpack_rpc_from_buffer(result.data.buffer, res);
break;
@@ -258,13 +245,6 @@ void msgpack_rpc_from_object(Object result, msgpack_packer *res)
}
}
-void msgpack_rpc_from_position(Position result, msgpack_packer *res)
-{
- msgpack_pack_array(res, 2);;
- msgpack_pack_int64(res, result.row);
- msgpack_pack_int64(res, result.col);
-}
-
void msgpack_rpc_from_array(Array result, msgpack_packer *res)
{
msgpack_pack_array(res, result.size);
@@ -300,7 +280,6 @@ void msgpack_rpc_free_object(Object value)
case kObjectTypeBoolean:
case kObjectTypeInteger:
case kObjectTypeFloat:
- case kObjectTypePosition:
case kObjectTypeBuffer:
case kObjectTypeWindow:
case kObjectTypeTabpage:
diff --git a/src/nvim/os/msgpack_rpc_helpers.h b/src/nvim/os/msgpack_rpc_helpers.h
index 77e3d2637e..0eb2d5c77a 100644
--- a/src/nvim/os/msgpack_rpc_helpers.h
+++ b/src/nvim/os/msgpack_rpc_helpers.h
@@ -24,8 +24,6 @@ bool msgpack_rpc_to_integer(msgpack_object *obj, Integer *arg)
FUNC_ATTR_NONNULL_ALL;
bool msgpack_rpc_to_float(msgpack_object *obj, Float *arg)
FUNC_ATTR_NONNULL_ALL;
-bool msgpack_rpc_to_position(msgpack_object *obj, Position *arg)
- FUNC_ATTR_NONNULL_ALL;
bool msgpack_rpc_to_string(msgpack_object *obj, String *arg)
FUNC_ATTR_NONNULL_ALL;
bool msgpack_rpc_to_buffer(msgpack_object *obj, Buffer *arg)
@@ -53,8 +51,6 @@ void msgpack_rpc_from_integer(Integer result, msgpack_packer *res)
FUNC_ATTR_NONNULL_ARG(2);
void msgpack_rpc_from_float(Float result, msgpack_packer *res)
FUNC_ATTR_NONNULL_ARG(2);
-void msgpack_rpc_from_position(Position result, msgpack_packer *res)
- FUNC_ATTR_NONNULL_ARG(2);
void msgpack_rpc_from_string(String result, msgpack_packer *res)
FUNC_ATTR_NONNULL_ARG(2);
void msgpack_rpc_from_buffer(Buffer result, msgpack_packer *res)