mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
Add new files to clint and fix reported errors
This commit is contained in:
@@ -22,3 +22,16 @@ src/os/signal.c
|
|||||||
src/os/signal.h
|
src/os/signal.h
|
||||||
src/os/time.c
|
src/os/time.c
|
||||||
src/os/time.h
|
src/os/time.h
|
||||||
|
src/os/msgpack_rpc.h
|
||||||
|
src/os/msgpack_rpc.c
|
||||||
|
src/api/defs.h
|
||||||
|
src/api/buffer.h
|
||||||
|
src/api/buffer.c
|
||||||
|
src/api/helpers.h
|
||||||
|
src/api/helpers.c
|
||||||
|
src/api/tabpage.h
|
||||||
|
src/api/tabpage.c
|
||||||
|
src/api/window.h
|
||||||
|
src/api/window.c
|
||||||
|
src/api/vim.h
|
||||||
|
src/api/vim.c
|
||||||
|
@@ -101,7 +101,7 @@ StringArray buffer_get_slice(Buffer buffer,
|
|||||||
rv.items = xmalloc(sizeof(String) * rv.size);
|
rv.items = xmalloc(sizeof(String) * rv.size);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < rv.size; i++) {
|
for (uint32_t i = 0; i < rv.size; i++) {
|
||||||
rv.items[i].data = xstrdup((char *)ml_get_buf(buf, start + i, FALSE));
|
rv.items[i].data = xstrdup((char *)ml_get_buf(buf, start + i, false));
|
||||||
rv.items[i].size = strlen(rv.items[i].data);
|
rv.items[i].size = strlen(rv.items[i].data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ static void switch_to_win_for_buf(buf_T *buf,
|
|||||||
tabpage_T *tp;
|
tabpage_T *tp;
|
||||||
|
|
||||||
if (find_win_for_buf(buf, &wp, &tp) == FAIL
|
if (find_win_for_buf(buf, &wp, &tp) == FAIL
|
||||||
|| switch_win(save_curwinp, save_curtabp, wp, tp, TRUE) == FAIL)
|
|| switch_win(save_curwinp, save_curtabp, wp, tp, true) == FAIL)
|
||||||
switch_buffer(save_curbufp, buf);
|
switch_buffer(save_curbufp, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ static void restore_win_for_buf(win_T *save_curwin,
|
|||||||
buf_T *save_curbuf)
|
buf_T *save_curbuf)
|
||||||
{
|
{
|
||||||
if (save_curbuf == NULL) {
|
if (save_curbuf == NULL) {
|
||||||
restore_win(save_curwin, save_curtab, TRUE);
|
restore_win(save_curwin, save_curtab, true);
|
||||||
} else {
|
} else {
|
||||||
restore_buffer(save_curbuf);
|
restore_buffer(save_curbuf);
|
||||||
}
|
}
|
||||||
@@ -390,8 +390,7 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)
|
|||||||
if (curwin->w_cursor.lnum >= hi) {
|
if (curwin->w_cursor.lnum >= hi) {
|
||||||
curwin->w_cursor.lnum += extra;
|
curwin->w_cursor.lnum += extra;
|
||||||
check_cursor_col();
|
check_cursor_col();
|
||||||
}
|
} else if (extra < 0) {
|
||||||
else if (extra < 0) {
|
|
||||||
curwin->w_cursor.lnum = lo;
|
curwin->w_cursor.lnum = lo;
|
||||||
check_cursor();
|
check_cursor();
|
||||||
} else {
|
} else {
|
||||||
|
@@ -87,11 +87,9 @@ Object dict_get_value(dict_T *dict, String key, bool pop, Error *err)
|
|||||||
Object rv;
|
Object rv;
|
||||||
hashitem_T *hi;
|
hashitem_T *hi;
|
||||||
dictitem_T *di;
|
dictitem_T *di;
|
||||||
char k[key.size + 1];
|
char *k = xstrndup(key.data, key.size);
|
||||||
// Convert the key
|
|
||||||
memcpy(k, key.data, key.size);
|
|
||||||
k[key.size] = NUL;
|
|
||||||
hi = hash_find(&dict->dv_hashtab, (uint8_t *)k);
|
hi = hash_find(&dict->dv_hashtab, (uint8_t *)k);
|
||||||
|
free(k);
|
||||||
|
|
||||||
if (HASHITEM_EMPTY(hi)) {
|
if (HASHITEM_EMPTY(hi)) {
|
||||||
set_api_error("Key not found", err);
|
set_api_error("Key not found", err);
|
||||||
@@ -136,10 +134,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (di == NULL) {
|
if (di == NULL) {
|
||||||
uint8_t k[key.size + 1];
|
char *k = xstrndup(key.data, key.size);
|
||||||
memcpy(k, key.data, key.size);
|
di = dictitem_alloc((uint8_t *)k);
|
||||||
k[key.size] = NUL;
|
free(k);
|
||||||
di = dictitem_alloc(k);
|
|
||||||
dict_add(dict, di);
|
dict_add(dict, di);
|
||||||
} else {
|
} else {
|
||||||
rv = vim_to_object(&di->di_tv);
|
rv = vim_to_object(&di->di_tv);
|
||||||
@@ -162,13 +159,12 @@ Object get_option_from(void *from, int type, String name, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return values
|
// Return values
|
||||||
long numval;
|
int64_t numval;
|
||||||
char *stringval = NULL;
|
char *stringval = NULL;
|
||||||
//
|
// copy the option name into 0-delimited string
|
||||||
char key[name.size + 1];
|
char *key = xstrndup(name.data, name.size);
|
||||||
memcpy(key, name.data, name.size);
|
|
||||||
key[name.size] = NUL;
|
|
||||||
int flags = get_option_value_strict(key, &numval, &stringval, type, from);
|
int flags = get_option_value_strict(key, &numval, &stringval, type, from);
|
||||||
|
free(key);
|
||||||
|
|
||||||
if (!flags) {
|
if (!flags) {
|
||||||
set_api_error("invalid option name", err);
|
set_api_error("invalid option name", err);
|
||||||
@@ -203,27 +199,25 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char key[name.size + 1];
|
char *key = xstrndup(name.data, name.size);
|
||||||
memcpy(key, name.data, name.size);
|
|
||||||
key[name.size] = NUL;
|
|
||||||
int flags = get_option_value_strict(key, NULL, NULL, type, to);
|
int flags = get_option_value_strict(key, NULL, NULL, type, to);
|
||||||
|
|
||||||
if (flags == 0) {
|
if (flags == 0) {
|
||||||
set_api_error("invalid option name", err);
|
set_api_error("invalid option name", err);
|
||||||
return;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.type == kObjectTypeNil) {
|
if (value.type == kObjectTypeNil) {
|
||||||
if (type == SREQ_GLOBAL) {
|
if (type == SREQ_GLOBAL) {
|
||||||
set_api_error("unable to unset option", err);
|
set_api_error("unable to unset option", err);
|
||||||
return;
|
goto cleanup;
|
||||||
} else if (!(flags & SOPT_GLOBAL)) {
|
} else if (!(flags & SOPT_GLOBAL)) {
|
||||||
set_api_error("cannot unset option that doesn't have a global value",
|
set_api_error("cannot unset option that doesn't have a global value",
|
||||||
err);
|
err);
|
||||||
return;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
unset_global_local_option(key, to);
|
unset_global_local_option(key, to);
|
||||||
return;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +226,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
if (flags & SOPT_BOOL) {
|
if (flags & SOPT_BOOL) {
|
||||||
if (value.type != kObjectTypeBool) {
|
if (value.type != kObjectTypeBool) {
|
||||||
set_api_error("option requires a boolean value", err);
|
set_api_error("option requires a boolean value", err);
|
||||||
return;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
bool val = value.data.boolean;
|
bool val = value.data.boolean;
|
||||||
set_option_value_for(key, val, NULL, opt_flags, type, to, err);
|
set_option_value_for(key, val, NULL, opt_flags, type, to, err);
|
||||||
@@ -240,7 +234,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
} else if (flags & SOPT_NUM) {
|
} else if (flags & SOPT_NUM) {
|
||||||
if (value.type != kObjectTypeInt) {
|
if (value.type != kObjectTypeInt) {
|
||||||
set_api_error("option requires an integer value", err);
|
set_api_error("option requires an integer value", err);
|
||||||
return;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
int val = value.data.integer;
|
int val = value.data.integer;
|
||||||
@@ -248,12 +242,15 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
} else {
|
} else {
|
||||||
if (value.type != kObjectTypeString) {
|
if (value.type != kObjectTypeString) {
|
||||||
set_api_error("option requires a string value", err);
|
set_api_error("option requires a string value", err);
|
||||||
return;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *val = xstrndup(value.data.string.data, value.data.string.size);
|
char *val = xstrndup(value.data.string.data, value.data.string.size);
|
||||||
set_option_value_for(key, 0, val, opt_flags, type, to, err);
|
set_option_value_for(key, 0, val, opt_flags, type, to, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
free(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object vim_to_object(typval_T *obj)
|
Object vim_to_object(typval_T *obj)
|
||||||
@@ -360,10 +357,9 @@ static bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char k[key.size + 1];
|
char *k = xstrndup(key.data, key.size);
|
||||||
memcpy(k, key.data, key.size);
|
|
||||||
k[key.size] = NUL;
|
|
||||||
dictitem_T *di = dictitem_alloc((uint8_t *)k);
|
dictitem_T *di = dictitem_alloc((uint8_t *)k);
|
||||||
|
free(k);
|
||||||
|
|
||||||
if (!object_to_vim(item.value, &di->di_tv, err)) {
|
if (!object_to_vim(item.value, &di->di_tv, err)) {
|
||||||
// cleanup
|
// cleanup
|
||||||
@@ -503,7 +499,7 @@ static void set_option_value_for(char *key,
|
|||||||
{
|
{
|
||||||
case SREQ_WIN:
|
case SREQ_WIN:
|
||||||
if (switch_win(&save_curwin, &save_curtab, (win_T *)from,
|
if (switch_win(&save_curwin, &save_curtab, (win_T *)from,
|
||||||
win_find_tabpage((win_T *)from), FALSE) == FAIL)
|
win_find_tabpage((win_T *)from), false) == FAIL)
|
||||||
{
|
{
|
||||||
if (try_end(err)) {
|
if (try_end(err)) {
|
||||||
return;
|
return;
|
||||||
@@ -512,7 +508,7 @@ static void set_option_value_for(char *key,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
set_option_value_err(key, numval, stringval, opt_flags, err);
|
set_option_value_err(key, numval, stringval, opt_flags, err);
|
||||||
restore_win(save_curwin, save_curtab, TRUE);
|
restore_win(save_curwin, save_curtab, true);
|
||||||
break;
|
break;
|
||||||
case SREQ_BUF:
|
case SREQ_BUF:
|
||||||
switch_buffer(&save_curbuf, (buf_T *)from);
|
switch_buffer(&save_curbuf, (buf_T *)from);
|
||||||
|
@@ -80,5 +80,5 @@ buf_T *find_buffer(Buffer buffer, Error *err);
|
|||||||
/// @return the window pointer
|
/// @return the window pointer
|
||||||
win_T * find_window(Window window, Error *err);
|
win_T * find_window(Window window, Error *err);
|
||||||
|
|
||||||
#endif /* NEOVIM_API_HELPERS_H */
|
#endif // NEOVIM_API_HELPERS_H
|
||||||
|
|
||||||
|
@@ -38,12 +38,11 @@ void vim_push_keys(String str)
|
|||||||
void vim_command(String str, Error *err)
|
void vim_command(String str, Error *err)
|
||||||
{
|
{
|
||||||
// We still use 0-terminated strings, so we must convert.
|
// We still use 0-terminated strings, so we must convert.
|
||||||
char cmd_str[str.size + 1];
|
char *cmd_str = xstrndup(str.data, str.size);
|
||||||
memcpy(cmd_str, str.data, str.size);
|
|
||||||
cmd_str[str.size] = NUL;
|
|
||||||
// Run the command
|
// Run the command
|
||||||
try_start();
|
try_start();
|
||||||
do_cmdline_cmd((char_u *)cmd_str);
|
do_cmdline_cmd((char_u *)cmd_str);
|
||||||
|
free(cmd_str);
|
||||||
update_screen(VALID);
|
update_screen(VALID);
|
||||||
try_end(err);
|
try_end(err);
|
||||||
}
|
}
|
||||||
@@ -51,13 +50,11 @@ void vim_command(String str, Error *err)
|
|||||||
Object vim_eval(String str, Error *err)
|
Object vim_eval(String str, Error *err)
|
||||||
{
|
{
|
||||||
Object rv;
|
Object rv;
|
||||||
|
char *expr_str = xstrndup(str.data, str.size);
|
||||||
char expr_str[str.size + 1];
|
|
||||||
memcpy(expr_str, str.data, str.size);
|
|
||||||
expr_str[str.size] = NUL;
|
|
||||||
// Evaluate the expression
|
// Evaluate the expression
|
||||||
try_start();
|
try_start();
|
||||||
typval_T *expr_result = eval_expr((char_u *)expr_str, NULL);
|
typval_T *expr_result = eval_expr((char_u *)expr_str, NULL);
|
||||||
|
free(expr_str);
|
||||||
|
|
||||||
if (!try_end(err)) {
|
if (!try_end(err)) {
|
||||||
// No errors, convert the result
|
// No errors, convert the result
|
||||||
@@ -114,9 +111,8 @@ StringArray vim_list_runtime_paths(void)
|
|||||||
|
|
||||||
void vim_change_directory(String dir, Error *err)
|
void vim_change_directory(String dir, Error *err)
|
||||||
{
|
{
|
||||||
char string[dir.size + 1];
|
char string[MAXPATHL];
|
||||||
memcpy(string, dir.data, dir.size);
|
strncpy(string, dir.data, dir.size);
|
||||||
string[dir.size] = NUL;
|
|
||||||
|
|
||||||
try_start();
|
try_start();
|
||||||
|
|
||||||
@@ -127,7 +123,7 @@ void vim_change_directory(String dir, Error *err)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
post_chdir(FALSE);
|
post_chdir(false);
|
||||||
try_end(err);
|
try_end(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -278,7 +278,6 @@ void msgpack_rpc_from_tabpage(Tabpage result, msgpack_packer *res)
|
|||||||
|
|
||||||
void msgpack_rpc_from_object(Object result, msgpack_packer *res)
|
void msgpack_rpc_from_object(Object result, msgpack_packer *res)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (result.type) {
|
switch (result.type) {
|
||||||
case kObjectTypeNil:
|
case kObjectTypeNil:
|
||||||
msgpack_pack_nil(res);
|
msgpack_pack_nil(res);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#ifndef NEOVIM_MSGPACK_RPC_H
|
#ifndef NEOVIM_OS_MSGPACK_RPC_H
|
||||||
#define NEOVIM_MSGPACK_RPC_H
|
#define NEOVIM_OS_MSGPACK_RPC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -103,5 +103,5 @@ void msgpack_rpc_free_array(Array value);
|
|||||||
void msgpack_rpc_free_dictionary(Dictionary value);
|
void msgpack_rpc_free_dictionary(Dictionary value);
|
||||||
|
|
||||||
|
|
||||||
#endif // NEOVIM_MSGPACK_RPC_H
|
#endif // NEOVIM_OS_MSGPACK_RPC_H
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user