mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 03:16:31 +00:00
Use more descriptive names for API primitive types
Instead of exposing native C types to a public API that can be consumed by other platforms, we are now using the following translation: int64_t -> Integer double -> Float bool -> Boolean
This commit is contained in:
@@ -40,7 +40,7 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra);
|
||||
// Normalizes 0-based indexes to buffer line numbers
|
||||
static int64_t normalize_index(buf_T *buf, int64_t index);
|
||||
|
||||
int64_t buffer_get_length(Buffer buffer, Error *err)
|
||||
Integer buffer_get_length(Buffer buffer, Error *err)
|
||||
{
|
||||
buf_T *buf = find_buffer(buffer, err);
|
||||
|
||||
@@ -51,7 +51,7 @@ int64_t buffer_get_length(Buffer buffer, Error *err)
|
||||
return buf->b_ml.ml_line_count;
|
||||
}
|
||||
|
||||
String buffer_get_line(Buffer buffer, int64_t index, Error *err)
|
||||
String buffer_get_line(Buffer buffer, Integer index, Error *err)
|
||||
{
|
||||
String rv = {.size = 0};
|
||||
StringArray slice = buffer_get_slice(buffer, index, index, true, true, err);
|
||||
@@ -63,23 +63,23 @@ String buffer_get_line(Buffer buffer, int64_t index, Error *err)
|
||||
return rv;
|
||||
}
|
||||
|
||||
void buffer_set_line(Buffer buffer, int64_t index, String line, Error *err)
|
||||
void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
|
||||
{
|
||||
StringArray array = {.items = &line, .size = 1};
|
||||
buffer_set_slice(buffer, index, index, true, true, array, err);
|
||||
}
|
||||
|
||||
void buffer_del_line(Buffer buffer, int64_t index, Error *err)
|
||||
void buffer_del_line(Buffer buffer, Integer index, Error *err)
|
||||
{
|
||||
StringArray array = {.size = 0};
|
||||
buffer_set_slice(buffer, index, index, true, true, array, err);
|
||||
}
|
||||
|
||||
StringArray buffer_get_slice(Buffer buffer,
|
||||
int64_t start,
|
||||
int64_t end,
|
||||
bool include_start,
|
||||
bool include_end,
|
||||
Integer start,
|
||||
Integer end,
|
||||
Boolean include_start,
|
||||
Boolean include_end,
|
||||
Error *err)
|
||||
{
|
||||
StringArray rv = {.size = 0};
|
||||
@@ -109,10 +109,10 @@ StringArray buffer_get_slice(Buffer buffer,
|
||||
}
|
||||
|
||||
void buffer_set_slice(Buffer buffer,
|
||||
int64_t start,
|
||||
int64_t end,
|
||||
bool include_start,
|
||||
bool include_end,
|
||||
Integer start,
|
||||
Integer end,
|
||||
Boolean include_start,
|
||||
Boolean include_end,
|
||||
StringArray replacement,
|
||||
Error *err)
|
||||
{
|
||||
@@ -310,15 +310,15 @@ void buffer_set_name(Buffer buffer, String name, Error *err)
|
||||
}
|
||||
}
|
||||
|
||||
bool buffer_is_valid(Buffer buffer)
|
||||
Boolean buffer_is_valid(Buffer buffer)
|
||||
{
|
||||
Error stub = {.set = false};
|
||||
return find_buffer(buffer, &stub) != NULL;
|
||||
}
|
||||
|
||||
void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err)
|
||||
void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err)
|
||||
{
|
||||
buffer_set_slice(buffer, index, index, false, true, lines, err);
|
||||
buffer_set_slice(buffer, lnum, lnum, false, true, lines, err);
|
||||
}
|
||||
|
||||
Position buffer_get_mark(Buffer buffer, String name, Error *err)
|
||||
|
@@ -11,7 +11,7 @@
|
||||
/// @param buffer The buffer handle
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return The line count
|
||||
int64_t buffer_get_length(Buffer buffer, Error *err);
|
||||
Integer buffer_get_length(Buffer buffer, Error *err);
|
||||
|
||||
/// Gets a buffer line
|
||||
///
|
||||
@@ -19,7 +19,7 @@ int64_t buffer_get_length(Buffer buffer, Error *err);
|
||||
/// @param index The line index
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return The line string
|
||||
String buffer_get_line(Buffer buffer, int64_t index, Error *err);
|
||||
String buffer_get_line(Buffer buffer, Integer index, Error *err);
|
||||
|
||||
/// Sets a buffer line
|
||||
///
|
||||
@@ -27,14 +27,14 @@ String buffer_get_line(Buffer buffer, int64_t index, Error *err);
|
||||
/// @param index The line index
|
||||
/// @param line The new line.
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void buffer_set_line(Buffer buffer, int64_t index, String line, Error *err);
|
||||
void buffer_set_line(Buffer buffer, Integer index, String line, Error *err);
|
||||
|
||||
/// Deletes a buffer line
|
||||
///
|
||||
/// @param buffer The buffer handle
|
||||
/// @param index The line index
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void buffer_del_line(Buffer buffer, int64_t index, Error *err);
|
||||
void buffer_del_line(Buffer buffer, Integer index, Error *err);
|
||||
|
||||
/// Retrieves a line range from the buffer
|
||||
///
|
||||
@@ -46,10 +46,10 @@ void buffer_del_line(Buffer buffer, int64_t index, Error *err);
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return An array of lines
|
||||
StringArray buffer_get_slice(Buffer buffer,
|
||||
int64_t start,
|
||||
int64_t end,
|
||||
bool include_start,
|
||||
bool include_end,
|
||||
Integer start,
|
||||
Integer end,
|
||||
Boolean include_start,
|
||||
Boolean include_end,
|
||||
Error *err);
|
||||
|
||||
/// Replaces a line range on the buffer
|
||||
@@ -63,10 +63,10 @@ StringArray buffer_get_slice(Buffer buffer,
|
||||
/// will simply delete the line range)
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void buffer_set_slice(Buffer buffer,
|
||||
int64_t start,
|
||||
int64_t end,
|
||||
bool include_start,
|
||||
bool include_end,
|
||||
Integer start,
|
||||
Integer end,
|
||||
Boolean include_start,
|
||||
Boolean include_end,
|
||||
StringArray replacement,
|
||||
Error *err);
|
||||
|
||||
@@ -122,16 +122,16 @@ void buffer_set_name(Buffer buffer, String name, Error *err);
|
||||
///
|
||||
/// @param buffer The buffer handle
|
||||
/// @return true if the buffer is valid, false otherwise
|
||||
bool buffer_is_valid(Buffer buffer);
|
||||
Boolean buffer_is_valid(Buffer buffer);
|
||||
|
||||
/// Inserts a sequence of lines to a buffer at a certain index
|
||||
///
|
||||
/// @param buffer The buffer handle
|
||||
/// @param lnum Insert the lines before `lnum`. If negative, it will append
|
||||
/// @param lnum Insert the lines after `lnum`. If negative, it will append
|
||||
/// to the end of the buffer.
|
||||
/// @param lines An array of lines
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err);
|
||||
void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err);
|
||||
|
||||
/// Return a tuple (row,col) representing the position of the named mark
|
||||
///
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define NVIM_API_DEFS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
// Basic types
|
||||
@@ -10,14 +11,18 @@ typedef struct {
|
||||
bool set;
|
||||
} Error;
|
||||
|
||||
typedef bool Boolean;
|
||||
typedef int64_t Integer;
|
||||
typedef double Float;
|
||||
|
||||
typedef struct {
|
||||
char *data;
|
||||
size_t size;
|
||||
} String;
|
||||
|
||||
typedef int64_t Buffer;
|
||||
typedef int64_t Window;
|
||||
typedef int64_t Tabpage;
|
||||
typedef Integer Buffer;
|
||||
typedef Integer Window;
|
||||
typedef Integer Tabpage;
|
||||
|
||||
typedef struct object Object;
|
||||
|
||||
@@ -27,7 +32,7 @@ typedef struct {
|
||||
} StringArray;
|
||||
|
||||
typedef struct {
|
||||
int64_t row, col;
|
||||
Integer row, col;
|
||||
} Position;
|
||||
|
||||
typedef struct {
|
||||
@@ -44,8 +49,8 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
kObjectTypeNil,
|
||||
kObjectTypeBool,
|
||||
kObjectTypeInt,
|
||||
kObjectTypeBoolean,
|
||||
kObjectTypeInteger,
|
||||
kObjectTypeFloat,
|
||||
kObjectTypeString,
|
||||
kObjectTypeArray,
|
||||
@@ -55,9 +60,9 @@ typedef enum {
|
||||
struct object {
|
||||
ObjectType type;
|
||||
union {
|
||||
bool boolean;
|
||||
int64_t integer;
|
||||
double floating_point;
|
||||
Boolean boolean;
|
||||
Integer integer;
|
||||
Float floating;
|
||||
String string;
|
||||
Array array;
|
||||
Dictionary dictionary;
|
||||
|
@@ -190,10 +190,10 @@ Object get_option_from(void *from, int type, String name, Error *err)
|
||||
}
|
||||
|
||||
if (flags & SOPT_BOOL) {
|
||||
rv.type = kObjectTypeBool;
|
||||
rv.type = kObjectTypeBoolean;
|
||||
rv.data.boolean = numval ? true : false;
|
||||
} else if (flags & SOPT_NUM) {
|
||||
rv.type = kObjectTypeInt;
|
||||
rv.type = kObjectTypeInteger;
|
||||
rv.data.integer = numval;
|
||||
} else if (flags & SOPT_STRING) {
|
||||
if (stringval) {
|
||||
@@ -242,7 +242,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
||||
int opt_flags = (type ? OPT_LOCAL : OPT_GLOBAL);
|
||||
|
||||
if (flags & SOPT_BOOL) {
|
||||
if (value.type != kObjectTypeBool) {
|
||||
if (value.type != kObjectTypeBoolean) {
|
||||
set_api_error("option requires a boolean value", err);
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -250,7 +250,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
||||
set_option_value_for(key, val, NULL, opt_flags, type, to, err);
|
||||
|
||||
} else if (flags & SOPT_NUM) {
|
||||
if (value.type != kObjectTypeInt) {
|
||||
if (value.type != kObjectTypeInteger) {
|
||||
set_api_error("option requires an integer value", err);
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -330,19 +330,19 @@ static bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
||||
tv->vval.v_number = 0;
|
||||
break;
|
||||
|
||||
case kObjectTypeBool:
|
||||
case kObjectTypeBoolean:
|
||||
tv->v_type = VAR_NUMBER;
|
||||
tv->vval.v_number = obj.data.boolean;
|
||||
break;
|
||||
|
||||
case kObjectTypeInt:
|
||||
case kObjectTypeInteger:
|
||||
tv->v_type = VAR_NUMBER;
|
||||
tv->vval.v_number = obj.data.integer;
|
||||
break;
|
||||
|
||||
case kObjectTypeFloat:
|
||||
tv->v_type = VAR_FLOAT;
|
||||
tv->vval.v_float = obj.data.floating_point;
|
||||
tv->vval.v_float = obj.data.floating;
|
||||
break;
|
||||
|
||||
case kObjectTypeString:
|
||||
@@ -431,13 +431,13 @@ static Object vim_to_object_rec(typval_T *obj, khash_t(Lookup) *lookup)
|
||||
break;
|
||||
|
||||
case VAR_NUMBER:
|
||||
rv.type = kObjectTypeInt;
|
||||
rv.type = kObjectTypeInteger;
|
||||
rv.data.integer = obj->vval.v_number;
|
||||
break;
|
||||
|
||||
case VAR_FLOAT:
|
||||
rv.type = kObjectTypeFloat;
|
||||
rv.data.floating_point = obj->vval.v_float;
|
||||
rv.data.floating = obj->vval.v_float;
|
||||
break;
|
||||
|
||||
case VAR_LIST:
|
||||
|
@@ -7,9 +7,9 @@
|
||||
#include "nvim/api/defs.h"
|
||||
#include "nvim/api/helpers.h"
|
||||
|
||||
int64_t tabpage_get_window_count(Tabpage tabpage, Error *err)
|
||||
Integer tabpage_get_window_count(Tabpage tabpage, Error *err)
|
||||
{
|
||||
uint64_t rv = 0;
|
||||
Integer rv = 0;
|
||||
tabpage_T *tab = find_tab(tabpage, err);
|
||||
|
||||
if (!tab) {
|
||||
@@ -80,7 +80,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)
|
||||
}
|
||||
}
|
||||
|
||||
bool tabpage_is_valid(Tabpage tabpage)
|
||||
Boolean tabpage_is_valid(Tabpage tabpage)
|
||||
{
|
||||
Error stub = {.set = false};
|
||||
return find_tab(tabpage, &stub) != NULL;
|
||||
|
@@ -11,7 +11,7 @@
|
||||
/// @param tabpage The tabpage
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return The number of windows in `tabpage`
|
||||
int64_t tabpage_get_window_count(Tabpage tabpage, Error *err);
|
||||
Integer tabpage_get_window_count(Tabpage tabpage, Error *err);
|
||||
|
||||
/// Gets a tabpage variable
|
||||
///
|
||||
@@ -41,7 +41,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err);
|
||||
///
|
||||
/// @param tabpage The tab page handle
|
||||
/// @return true if the tab page is valid, false otherwise
|
||||
bool tabpage_is_valid(Tabpage tabpage);
|
||||
Boolean tabpage_is_valid(Tabpage tabpage);
|
||||
|
||||
#endif // NVIM_API_TABPAGE_H
|
||||
|
||||
|
@@ -66,7 +66,7 @@ Object vim_eval(String str, Error *err)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int64_t vim_strwidth(String str)
|
||||
Integer vim_strwidth(String str)
|
||||
{
|
||||
return mb_string2cells((char_u *)str.data, str.size);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ void vim_err_write(String str)
|
||||
write_msg(str, true);
|
||||
}
|
||||
|
||||
int64_t vim_get_buffer_count(void)
|
||||
Integer vim_get_buffer_count(void)
|
||||
{
|
||||
buf_T *b = firstbuf;
|
||||
uint64_t n = 0;
|
||||
@@ -212,7 +212,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err)
|
||||
try_end(err);
|
||||
}
|
||||
|
||||
int64_t vim_get_window_count(void)
|
||||
Integer vim_get_window_count(void)
|
||||
{
|
||||
tabpage_T *tp;
|
||||
win_T *wp;
|
||||
@@ -265,7 +265,7 @@ void vim_set_current_window(Window window, Error *err)
|
||||
try_end(err);
|
||||
}
|
||||
|
||||
int64_t vim_get_tabpage_count(void)
|
||||
Integer vim_get_tabpage_count(void)
|
||||
{
|
||||
tabpage_T *tp = first_tabpage;
|
||||
uint64_t rv = 0;
|
||||
|
@@ -31,7 +31,7 @@ Object vim_eval(String str, Error *err);
|
||||
///
|
||||
/// @param str Some text
|
||||
/// @return The number of cells
|
||||
int64_t vim_strwidth(String str);
|
||||
Integer vim_strwidth(String str);
|
||||
|
||||
/// Returns a list of paths contained in 'runtimepath'
|
||||
///
|
||||
@@ -110,7 +110,7 @@ void vim_err_write(String str);
|
||||
/// Gets the number of buffers
|
||||
///
|
||||
/// @return The number of buffers
|
||||
int64_t vim_get_buffer_count(void);
|
||||
Integer vim_get_buffer_count(void);
|
||||
|
||||
/// Return the current buffer
|
||||
///
|
||||
@@ -126,7 +126,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err);
|
||||
/// Gets the number of windows
|
||||
///
|
||||
/// @return The number of windows
|
||||
int64_t vim_get_window_count(void);
|
||||
Integer vim_get_window_count(void);
|
||||
|
||||
/// Return the current window
|
||||
///
|
||||
@@ -141,7 +141,7 @@ void vim_set_current_window(Window window, Error *err);
|
||||
/// Gets the number of tab pages
|
||||
///
|
||||
/// @return The number of tab pages
|
||||
int64_t vim_get_tabpage_count(void);
|
||||
Integer vim_get_tabpage_count(void);
|
||||
|
||||
/// Return the current tab page
|
||||
///
|
||||
|
@@ -56,7 +56,7 @@ void window_set_cursor(Window window, Position pos, Error *err)
|
||||
update_screen(VALID);
|
||||
}
|
||||
|
||||
int64_t window_get_height(Window window, Error *err)
|
||||
Integer window_get_height(Window window, Error *err)
|
||||
{
|
||||
win_T *win = find_window(window, err);
|
||||
|
||||
@@ -67,7 +67,7 @@ int64_t window_get_height(Window window, Error *err)
|
||||
return win->w_height;
|
||||
}
|
||||
|
||||
void window_set_height(Window window, int64_t height, Error *err)
|
||||
void window_set_height(Window window, Integer height, Error *err)
|
||||
{
|
||||
win_T *win = find_window(window, err);
|
||||
|
||||
@@ -83,7 +83,7 @@ void window_set_height(Window window, int64_t height, Error *err)
|
||||
try_end(err);
|
||||
}
|
||||
|
||||
int64_t window_get_width(Window window, Error *err)
|
||||
Integer window_get_width(Window window, Error *err)
|
||||
{
|
||||
win_T *win = find_window(window, err);
|
||||
|
||||
@@ -94,7 +94,7 @@ int64_t window_get_width(Window window, Error *err)
|
||||
return win->w_width;
|
||||
}
|
||||
|
||||
void window_set_width(Window window, int64_t width, Error *err)
|
||||
void window_set_width(Window window, Integer width, Error *err)
|
||||
{
|
||||
win_T *win = find_window(window, err);
|
||||
|
||||
@@ -176,7 +176,7 @@ Tabpage window_get_tabpage(Window window, Error *err)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool window_is_valid(Window window)
|
||||
Boolean window_is_valid(Window window)
|
||||
{
|
||||
Error stub = {.set = false};
|
||||
return find_window(window, &stub) != NULL;
|
||||
|
@@ -32,7 +32,7 @@ void window_set_cursor(Window window, Position pos, Error *err);
|
||||
/// @param window The window handle
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return the height in rows
|
||||
int64_t window_get_height(Window window, Error *err);
|
||||
Integer window_get_height(Window window, Error *err);
|
||||
|
||||
/// Sets the window height. This will only succeed if the screen is split
|
||||
/// horizontally.
|
||||
@@ -40,14 +40,14 @@ int64_t window_get_height(Window window, Error *err);
|
||||
/// @param window The window handle
|
||||
/// @param height the new height in rows
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void window_set_height(Window window, int64_t height, Error *err);
|
||||
void window_set_height(Window window, Integer height, Error *err);
|
||||
|
||||
/// Gets the window width
|
||||
///
|
||||
/// @param window The window handle
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return the width in columns
|
||||
int64_t window_get_width(Window window, Error *err);
|
||||
Integer window_get_width(Window window, Error *err);
|
||||
|
||||
/// Sets the window width. This will only succeed if the screen is split
|
||||
/// vertically.
|
||||
@@ -55,7 +55,7 @@ int64_t window_get_width(Window window, Error *err);
|
||||
/// @param window The window handle
|
||||
/// @param width the new width in columns
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void window_set_width(Window window, int64_t width, Error *err);
|
||||
void window_set_width(Window window, Integer width, Error *err);
|
||||
|
||||
/// Gets a window variable
|
||||
///
|
||||
@@ -109,7 +109,7 @@ Tabpage window_get_tabpage(Window window, Error *err);
|
||||
///
|
||||
/// @param window The window handle
|
||||
/// @return true if the window is valid, false otherwise
|
||||
bool window_is_valid(Window window);
|
||||
Boolean window_is_valid(Window window);
|
||||
|
||||
#endif // NVIM_API_WINDOW_H
|
||||
|
||||
|
Reference in New Issue
Block a user