From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/api/vimscript.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index c75bf21572..25a34f769c 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -15,7 +15,6 @@ #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_docmd.h" -#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/globals.h" #include "nvim/memory.h" -- cgit From a16218d4c6773c474011149661470af6e8c90892 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 7 Dec 2023 13:01:42 +0100 Subject: refactor: object_to_vim() cannot fail Since the parent commit, object_to_vim() can't fail, so callers don't need to check its result. --- src/nvim/api/vimscript.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 25a34f769c..3bca988030 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -207,9 +207,7 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err) typval_T vim_args[MAX_FUNC_ARGS + 1]; size_t i = 0; // also used for freeing the variables for (; i < args.size; i++) { - if (!object_to_vim(args.items[i], &vim_args[i], err)) { - goto free_vim_args; - } + object_to_vim(args.items[i], &vim_args[i], err); } // Initialize `force_abort` and `suppress_errthrow` at the top level. @@ -243,7 +241,6 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err) tv_clear(&rettv); recursive--; -free_vim_args: while (i > 0) { tv_clear(&vim_args[--i]); } @@ -297,9 +294,7 @@ Object nvim_call_dict_function(Object dict, String fn, Array args, Error *err) mustfree = true; break; case kObjectTypeDictionary: - if (!object_to_vim(dict, &rettv, err)) { - goto end; - } + object_to_vim(dict, &rettv, err); break; default: api_set_error(err, kErrorTypeValidation, -- cgit From 0c120307ca1ab613e63865c634d7e10ad67fb0ba Mon Sep 17 00:00:00 2001 From: dundargoc Date: Wed, 20 Dec 2023 14:32:22 +0100 Subject: refactor: eliminate cyclic includes --- src/nvim/api/vimscript.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 3bca988030..6f3f0127d1 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -11,6 +11,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/vimscript.h" #include "nvim/ascii_defs.h" +#include "nvim/buffer_defs.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" -- cgit From c89292fcb7f2ebf06efb7c1d00c28f34c6f68fec Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 28 Dec 2023 13:42:24 +0100 Subject: refactor: follow style guide --- src/nvim/api/vimscript.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 6f3f0127d1..953bd80b0f 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -231,8 +231,8 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err) TRY_WRAP(err, { // call_func() retval is deceptive, ignore it. Instead we set `msg_list` // (see above) to capture abort-causing non-exception errors. - (void)call_func(fn.data, (int)fn.size, &rettv, (int)args.size, - vim_args, &funcexe); + call_func(fn.data, (int)fn.size, &rettv, (int)args.size, + vim_args, &funcexe); }); if (!ERROR_SET(err)) { -- cgit From 1813661a6197c76ea6621284570aca1d56597099 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 4 Jan 2024 15:38:16 +0100 Subject: refactor(IWYU): fix headers Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want. --- src/nvim/api/vimscript.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 953bd80b0f..56541bb8b8 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -14,15 +14,18 @@ #include "nvim/buffer_defs.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_docmd.h" #include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/globals.h" #include "nvim/memory.h" #include "nvim/runtime.h" #include "nvim/vim_defs.h" #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" +#include "nvim/viml/parser/parser_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/vimscript.c.generated.h" -- cgit From d60412b18e4e21f301baa2ac3f3fb7be89655e4b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 12 Feb 2024 20:40:27 +0100 Subject: refactor(eval): use arena when converting typvals to Object Note: this contains two _temporary_ changes which can be reverted once the Arena vs no-Arena distinction in API wrappers has been removed. Both nlua_push_Object and object_to_vim_take_luaref() has been changed to take the object argument as a pointer. This is not going to be necessary once these are only used with arena (or not at all) allocated Objects. The object_to_vim() variant which leaves luaref untouched might need to stay for a little longer. --- src/nvim/api/vimscript.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 56541bb8b8..949356acc6 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -148,7 +148,7 @@ void nvim_command(String command, Error *err) /// @param expr Vimscript expression string /// @param[out] err Error details, if any /// @return Evaluation result or expanded object -Object nvim_eval(String expr, Error *err) +Object nvim_eval(String expr, Arena *arena, Error *err) FUNC_API_SINCE(1) { static int recursive = 0; // recursion depth @@ -179,7 +179,7 @@ Object nvim_eval(String expr, Error *err) api_set_error(err, kErrorTypeException, "Failed to evaluate expression: '%.*s'", 256, expr.data); } else { - rv = vim_to_object(&rettv); + rv = vim_to_object(&rettv, arena, false); } } @@ -196,7 +196,7 @@ Object nvim_eval(String expr, Error *err) /// @param self `self` dict, or NULL for non-dict functions /// @param[out] err Error details, if any /// @return Result of the function call -static Object _call_function(String fn, Array args, dict_T *self, Error *err) +static Object _call_function(String fn, Array args, dict_T *self, Arena *arena, Error *err) { static int recursive = 0; // recursion depth Object rv = OBJECT_INIT; @@ -239,7 +239,7 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err) }); if (!ERROR_SET(err)) { - rv = vim_to_object(&rettv); + rv = vim_to_object(&rettv, arena, false); } tv_clear(&rettv); @@ -260,10 +260,10 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err) /// @param args Function arguments packed in an Array /// @param[out] err Error details, if any /// @return Result of the function call -Object nvim_call_function(String fn, Array args, Error *err) +Object nvim_call_function(String fn, Array args, Arena *arena, Error *err) FUNC_API_SINCE(1) { - return _call_function(fn, args, NULL, err); + return _call_function(fn, args, NULL, arena, err); } /// Calls a Vimscript |Dictionary-function| with the given arguments. @@ -275,7 +275,7 @@ Object nvim_call_function(String fn, Array args, Error *err) /// @param args Function arguments packed in an Array /// @param[out] err Error details, if any /// @return Result of the function call -Object nvim_call_dict_function(Object dict, String fn, Array args, Error *err) +Object nvim_call_dict_function(Object dict, String fn, Array args, Arena *arena, Error *err) FUNC_API_SINCE(4) { Object rv = OBJECT_INIT; @@ -337,7 +337,7 @@ Object nvim_call_dict_function(Object dict, String fn, Array args, Error *err) goto end; } - rv = _call_function(fn, args, self_dict, err); + rv = _call_function(fn, args, self_dict, arena, err); end: if (mustfree) { tv_clear(&rettv); -- cgit From acd9b54f08453bdaa324e95232e166545c04160f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 19 Feb 2024 14:54:20 +0100 Subject: refactor(api): use an arena for nvim_parse_expression --- src/nvim/api/vimscript.c | 237 ++++++++++++----------------------------------- 1 file changed, 60 insertions(+), 177 deletions(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 949356acc6..db32eac3d1 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -429,7 +429,8 @@ typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack; /// - "svalue": String, value for "SingleQuotedString" and /// "DoubleQuotedString" nodes. /// @param[out] err Error details, if any -Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, Error *err) +Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, Arena *arena, + Error *err) FUNC_API_SINCE(4) FUNC_API_FAST { int pflags = 0; @@ -471,82 +472,40 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E + (size_t)(east.err.msg != NULL) // "error" + (size_t)highlight // "highlight" + 0); - Dictionary ret = { - .items = xmalloc(ret_size * sizeof(ret.items[0])), - .size = 0, - .capacity = ret_size, - }; - ret.items[ret.size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ast"), - .value = NIL, - }; - ret.items[ret.size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("len"), - .value = INTEGER_OBJ((Integer)(pstate.pos.line == 1 - ? parser_lines[0].size - : pstate.pos.col)), - }; + + Dictionary ret = arena_dict(arena, ret_size); + PUT_C(ret, "len", INTEGER_OBJ((Integer)(pstate.pos.line == 1 + ? parser_lines[0].size + : pstate.pos.col))); if (east.err.msg != NULL) { - Dictionary err_dict = { - .items = xmalloc(2 * sizeof(err_dict.items[0])), - .size = 2, - .capacity = 2, - }; - err_dict.items[0] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("message"), - .value = CSTR_TO_OBJ(east.err.msg), - }; - if (east.err.arg == NULL) { - err_dict.items[1] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("arg"), - .value = STRING_OBJ(STRING_INIT), - }; - } else { - err_dict.items[1] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("arg"), - .value = STRING_OBJ(((String) { - .data = xmemdupz(east.err.arg, (size_t)east.err.arg_len), - .size = (size_t)east.err.arg_len, - })), - }; - } - ret.items[ret.size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("error"), - .value = DICTIONARY_OBJ(err_dict), - }; + Dictionary err_dict = arena_dict(arena, 2); + PUT_C(err_dict, "message", CSTR_TO_ARENA_OBJ(arena, east.err.msg)); + PUT_C(err_dict, "arg", CBUF_TO_ARENA_OBJ(arena, east.err.arg, (size_t)east.err.arg_len)); + PUT_C(ret, "error", DICTIONARY_OBJ(err_dict)); } if (highlight) { - Array hl = (Array) { - .items = xmalloc(kv_size(colors) * sizeof(hl.items[0])), - .capacity = kv_size(colors), - .size = kv_size(colors), - }; + Array hl = arena_array(arena, kv_size(colors)); for (size_t i = 0; i < kv_size(colors); i++) { const ParserHighlightChunk chunk = kv_A(colors, i); - Array chunk_arr = (Array) { - .items = xmalloc(4 * sizeof(chunk_arr.items[0])), - .capacity = 4, - .size = 4, - }; - chunk_arr.items[0] = INTEGER_OBJ((Integer)chunk.start.line); - chunk_arr.items[1] = INTEGER_OBJ((Integer)chunk.start.col); - chunk_arr.items[2] = INTEGER_OBJ((Integer)chunk.end_col); - chunk_arr.items[3] = CSTR_TO_OBJ(chunk.group); - hl.items[i] = ARRAY_OBJ(chunk_arr); + Array chunk_arr = arena_array(arena, 4); + ADD_C(chunk_arr, INTEGER_OBJ((Integer)chunk.start.line)); + ADD_C(chunk_arr, INTEGER_OBJ((Integer)chunk.start.col)); + ADD_C(chunk_arr, INTEGER_OBJ((Integer)chunk.end_col)); + ADD_C(chunk_arr, CSTR_AS_OBJ(chunk.group)); + + ADD_C(hl, ARRAY_OBJ(chunk_arr)); } - ret.items[ret.size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("highlight"), - .value = ARRAY_OBJ(hl), - }; + PUT_C(ret, "highlight", ARRAY_OBJ(hl)); } kvi_destroy(colors); // Walk over the AST, freeing nodes in process. ExprASTConvStack ast_conv_stack; kvi_init(ast_conv_stack); + Object ast = NIL; kvi_push(ast_conv_stack, ((ExprASTConvStackItem) { .node_p = &east.root, - .ret_node_p = &ret.items[0].value, + .ret_node_p = &ast, })); while (kv_size(ast_conv_stack)) { ExprASTConvStackItem cur_item = kv_last(ast_conv_stack); @@ -573,28 +532,17 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E || node->type == kExprNodeSingleQuotedString) // "svalue" + (node->type == kExprNodeAssignment) // "augmentation" + 0); - Dictionary ret_node = { - .items = xmalloc(items_size * sizeof(ret_node.items[0])), - .capacity = items_size, - .size = 0, - }; + Dictionary ret_node = arena_dict(arena, items_size); *cur_item.ret_node_p = DICTIONARY_OBJ(ret_node); } Dictionary *ret_node = &cur_item.ret_node_p->data.dictionary; if (node->children != NULL) { const size_t num_children = 1 + (node->children->next != NULL); - Array children_array = { - .items = xmalloc(num_children * sizeof(children_array.items[0])), - .capacity = num_children, - .size = num_children, - }; + Array children_array = arena_array(arena, num_children); for (size_t i = 0; i < num_children; i++) { - children_array.items[i] = NIL; + ADD_C(children_array, NIL); } - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("children"), - .value = ARRAY_OBJ(children_array), - }; + PUT_C(*ret_node, "children", ARRAY_OBJ(children_array)); kvi_push(ast_conv_stack, ((ExprASTConvStackItem) { .node_p = &node->children, .ret_node_p = &children_array.items[0], @@ -606,126 +554,60 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E })); } else { kv_drop(ast_conv_stack, 1); - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("type"), - .value = CSTR_TO_OBJ(east_node_type_tab[node->type]), - }; - Array start_array = { - .items = xmalloc(2 * sizeof(start_array.items[0])), - .capacity = 2, - .size = 2, - }; - start_array.items[0] = INTEGER_OBJ((Integer)node->start.line); - start_array.items[1] = INTEGER_OBJ((Integer)node->start.col); - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("start"), - .value = ARRAY_OBJ(start_array), - }; - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("len"), - .value = INTEGER_OBJ((Integer)node->len), - }; + PUT_C(*ret_node, "type", CSTR_AS_OBJ(east_node_type_tab[node->type])); + Array start_array = arena_array(arena, 2); + ADD_C(start_array, INTEGER_OBJ((Integer)node->start.line)); + ADD_C(start_array, INTEGER_OBJ((Integer)node->start.col)); + PUT_C(*ret_node, "start", ARRAY_OBJ(start_array)); + + PUT_C(*ret_node, "len", INTEGER_OBJ((Integer)node->len)); switch (node->type) { case kExprNodeDoubleQuotedString: - case kExprNodeSingleQuotedString: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("svalue"), - .value = STRING_OBJ(((String) { - .data = node->data.str.value, - .size = node->data.str.size, - })), - }; + case kExprNodeSingleQuotedString: { + Object str = CBUF_TO_ARENA_OBJ(arena, node->data.str.value, node->data.str.size); + PUT_C(*ret_node, "svalue", str); + xfree(node->data.str.value); break; + } case kExprNodeOption: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("scope"), - .value = INTEGER_OBJ(node->data.opt.scope), - }; - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ident"), - .value = STRING_OBJ(((String) { - .data = xmemdupz(node->data.opt.ident, - node->data.opt.ident_len), - .size = node->data.opt.ident_len, - })), - }; + PUT_C(*ret_node, "scope", INTEGER_OBJ(node->data.opt.scope)); + PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.opt.ident, + node->data.opt.ident_len)); break; case kExprNodePlainIdentifier: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("scope"), - .value = INTEGER_OBJ(node->data.var.scope), - }; - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ident"), - .value = STRING_OBJ(((String) { - .data = xmemdupz(node->data.var.ident, - node->data.var.ident_len), - .size = node->data.var.ident_len, - })), - }; + PUT_C(*ret_node, "scope", INTEGER_OBJ(node->data.var.scope)); + PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.var.ident, + node->data.var.ident_len)); break; case kExprNodePlainKey: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ident"), - .value = STRING_OBJ(((String) { - .data = xmemdupz(node->data.var.ident, - node->data.var.ident_len), - .size = node->data.var.ident_len, - })), - }; + PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.var.ident, + node->data.var.ident_len)); break; case kExprNodeEnvironment: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ident"), - .value = STRING_OBJ(((String) { - .data = xmemdupz(node->data.env.ident, - node->data.env.ident_len), - .size = node->data.env.ident_len, - })), - }; + PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.env.ident, + node->data.env.ident_len)); break; case kExprNodeRegister: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("name"), - .value = INTEGER_OBJ(node->data.reg.name), - }; + PUT_C(*ret_node, "name", INTEGER_OBJ(node->data.reg.name)); break; case kExprNodeComparison: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("cmp_type"), - .value = CSTR_TO_OBJ(eltkn_cmp_type_tab[node->data.cmp.type]), - }; - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ccs_strategy"), - .value = CSTR_TO_OBJ(ccs_tab[node->data.cmp.ccs]), - }; - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("invert"), - .value = BOOLEAN_OBJ(node->data.cmp.inv), - }; + PUT_C(*ret_node, "cmp_type", CSTR_AS_OBJ(eltkn_cmp_type_tab[node->data.cmp.type])); + PUT_C(*ret_node, "ccs_strategy", CSTR_AS_OBJ(ccs_tab[node->data.cmp.ccs])); + PUT_C(*ret_node, "invert", BOOLEAN_OBJ(node->data.cmp.inv)); break; case kExprNodeFloat: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("fvalue"), - .value = FLOAT_OBJ(node->data.flt.value), - }; + PUT_C(*ret_node, "fvalue", FLOAT_OBJ(node->data.flt.value)); break; case kExprNodeInteger: - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("ivalue"), - .value = INTEGER_OBJ((Integer)(node->data.num.value > API_INTEGER_MAX - ? API_INTEGER_MAX - : (Integer)node->data.num.value)), - }; + PUT_C(*ret_node, "ivalue", INTEGER_OBJ((Integer)(node->data.num.value > API_INTEGER_MAX + ? API_INTEGER_MAX + : (Integer)node->data.num.value))); break; case kExprNodeAssignment: { const ExprAssignmentType asgn_type = node->data.ass.type; - ret_node->items[ret_node->size++] = (KeyValuePair) { - .key = STATIC_CSTR_TO_STRING("augmentation"), - .value = STRING_OBJ(asgn_type == kExprAsgnPlain - ? (String)STRING_INIT - : cstr_to_string(expr_asgn_type_tab[asgn_type])), - }; + String str = (asgn_type == kExprAsgnPlain + ? (String)STRING_INIT : cstr_as_string(expr_asgn_type_tab[asgn_type])); + PUT_C(*ret_node, "augmentation", STRING_OBJ(str)); break; } case kExprNodeMissing: @@ -766,6 +648,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E } } kvi_destroy(ast_conv_stack); + PUT_C(ret, "ast", ast); assert(ret.size == ret.capacity); // Should be a no-op actually, leaving it in case non-nodes will need to be -- cgit From 3cc54586be7760652e8bad88cae82ce74ef9432e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 20 Feb 2024 13:44:50 +0100 Subject: refactor(api): make freeing of return-value opt-in instead of opt out As only a few API functions make use of explicit freeing of the return value, make it opt-in instead. The arena is always present under the hood, so `Arena *arena` arg now doesn't mean anything other than getting access to this arena. Also it is in principle possible to return an allocated value while still using the arena as scratch space for other stuff (unlikely, but there no reason to not allow it). --- src/nvim/api/vimscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index db32eac3d1..7239971c21 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -51,7 +51,7 @@ /// @return Dictionary containing information about execution, with these keys: /// - output: (string|nil) Output if `opts.output` is true. Dictionary nvim_exec2(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *err) - FUNC_API_SINCE(11) + FUNC_API_SINCE(11) FUNC_API_RET_ALLOC { Dictionary result = ARRAY_DICT_INIT; -- cgit From 9beb40a4db5613601fc1a4b828a44e5977eca046 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 15 Feb 2024 17:16:04 +0000 Subject: feat(docs): replace lua2dox.lua Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change). --- src/nvim/api/vimscript.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 7239971c21..8f57e61c76 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -351,9 +351,7 @@ typedef struct { Object *ret_node_p; } ExprASTConvStackItem; -/// @cond DOXYGEN_NOT_A_FUNCTION typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack; -/// @endcond /// Parse a Vimscript expression. /// @@ -387,8 +385,8 @@ typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack; /// - "arg": String, error message argument. /// - "len": Amount of bytes successfully parsed. With flags equal to "" /// that should be equal to the length of expr string. -/// (“Successfully parsed” here means “participated in AST -/// creation”, not “till the first error”.) +/// ("Successfully parsed" here means "participated in AST +/// creation", not "till the first error".) /// - "ast": AST, either nil or a dictionary with these keys: /// - "type": node type, one of the value names from ExprASTNodeType /// stringified without "kExprNode" prefix. -- cgit From ade1b12f49c3b3914c74847d791eb90ea90b56b7 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 8 Mar 2024 12:25:18 +0000 Subject: docs: support inline markdown - Tags are now created with `[tag]()` - References are now created with `[tag]` - Code spans are no longer wrapped --- src/nvim/api/vimscript.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vimscript.c') diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 8f57e61c76..477cbe2428 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -365,8 +365,8 @@ typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack; /// - "l" when needing to start parsing with lvalues for /// ":let" or ":for". /// Common flag sets: -/// - "m" to parse like for ":echo". -/// - "E" to parse like for "=". +/// - "m" to parse like for `":echo"`. +/// - "E" to parse like for `"="`. /// - empty string for ":call". /// - "lm" to parse for ":let". /// @param[in] highlight If true, return value will also include "highlight" @@ -390,7 +390,7 @@ typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack; /// - "ast": AST, either nil or a dictionary with these keys: /// - "type": node type, one of the value names from ExprASTNodeType /// stringified without "kExprNode" prefix. -/// - "start": a pair [line, column] describing where node is "started" +/// - "start": a pair `[line, column]` describing where node is "started" /// where "line" is always 0 (will not be 0 if you will be /// using this API on e.g. ":let", but that is not /// present yet). Both elements are Integers. -- cgit