From 6942528a54eacbcdcb5b40fa27f9e37ae9e80915 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 25 Feb 2023 21:04:52 +0100 Subject: refactor(ui): ui_log() can now just be a function --- src/nvim/generators/gen_api_ui_events.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua index 827097f69d..bbc6252f14 100755 --- a/src/nvim/generators/gen_api_ui_events.lua +++ b/src/nvim/generators/gen_api_ui_events.lua @@ -120,7 +120,6 @@ for i = 1, #events do if ev.remote_only then call_output:write(' Array args = call_buf;\n') write_arglist(call_output, ev) - call_output:write(' UI_LOG('..ev.name..');\n') call_output:write(' ui_call_event("'..ev.name..'", args);\n') elseif ev.compositor_impl then call_output:write(' ui_comp_'..ev.name) -- cgit From 1b3c1f6c06d73e881bfc2a46e5ee3e0b24ba96d8 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 27 Feb 2023 19:37:43 +0100 Subject: refactor(build): graduate HAVE_LOCALE_H feature Merge locale.h into os/lang.h Having a source file with the same name as a system header we use is considered an anti-pattern. --- src/nvim/generators/gen_ex_cmds.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index 0c1051b04e..935d7b333e 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -66,7 +66,6 @@ defsfile:write(string.format([[ #include "nvim/ex_session.h" #include "nvim/help.h" #include "nvim/indent.h" -#include "nvim/locale.h" #include "nvim/lua/executor.h" #include "nvim/mapping.h" #include "nvim/mark.h" @@ -75,6 +74,7 @@ defsfile:write(string.format([[ #include "nvim/message.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/os/lang.h" #include "nvim/profile.h" #include "nvim/quickfix.h" #include "nvim/runtime.h" -- cgit From 2ba224e1526681c1a0b1b2b095b1ef2b0874db48 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 Feb 2023 12:51:03 +0100 Subject: refactor(log): reduce compile time LOG_LEVEL granularity --- src/nvim/generators/gen_api_dispatch.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 35f6bf8455..a0a67af78d 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -257,9 +257,8 @@ for i = 1, #functions do output:write('Object handle_'..fn.name..'(uint64_t channel_id, Array args, Arena* arena, Error *error)') output:write('\n{') - output:write('\n#if MIN_LOG_LEVEL <= LOGLVL_DBG') - output:write('\n logmsg(LOGLVL_DBG, "RPC: ", NULL, -1, true, "ch %" PRIu64 ": invoke ' - ..fn.name..'", channel_id);') + output:write('\n#ifdef NVIM_LOG_DEBUG') + output:write('\n DLOG("RPC: ch %" PRIu64 ": invoke '..fn.name..'", channel_id);') output:write('\n#endif') output:write('\n Object ret = NIL;') -- Declare/initialize variables that will hold converted arguments -- cgit From 674e23f19c509381e2476a3990e21272e362e3a4 Mon Sep 17 00:00:00 2001 From: Michal Liszcz Date: Sat, 11 Mar 2023 04:22:22 +0100 Subject: vim-patch:9.0.0244: cannot easily get the list of sourced scripts (#22596) Problem: Cannot easily get the list of sourced scripts. Solution: Add the getscriptinfo() function. (Yegappan Lakshmanan, closes vim/vim#10957) https://github.com/vim/vim/commit/f768c3d19c518822d89dec4cc3947ddeea249316 Cherry-pick usr_41.txt change from a later runtime update. Co-authored-by: Yegappan Lakshmanan --- src/nvim/generators/gen_eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index baed6a74c2..fb1dd82a26 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -48,6 +48,7 @@ hashpipe:write([[ #include "nvim/menu.h" #include "nvim/move.h" #include "nvim/quickfix.h" +#include "nvim/runtime.h" #include "nvim/search.h" #include "nvim/sign.h" #include "nvim/testing.h" -- cgit From 4cba53e09e6e9d9cf06e87431146b9707347bcd6 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 20 Mar 2023 16:16:15 +0100 Subject: feat(lua): use vim.empty_dict() for empty return value in new api functions (#22737) --- src/nvim/generators/gen_api_dispatch.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index a0a67af78d..8aa1829364 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -619,9 +619,10 @@ local function process_function(fn) } ]], return_type)) else + local special = (fn.since ~= nil and fn.since < 11) write_shifted_output(output, string.format([[ - nlua_push_%s(lstate, ret, true); - ]], return_type)) + nlua_push_%s(lstate, ret, %s); + ]], return_type, tostring(special))) end write_shifted_output(output, string.format([[ -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- src/nvim/generators/gen_ex_cmds.lua | 2 +- src/nvim/generators/gen_options.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index 935d7b333e..26edd33604 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -41,7 +41,7 @@ static const uint16_t cmdidxs1[%u] = { -- Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they -- fit in a byte. local cmdidxs2_out = string.format([[ -static const char_u cmdidxs2[%u][%u] = { +static const uint8_t cmdidxs2[%u][%u] = { /* a b c d e f g h i j k l m n o p q r s t u v w x y z */ ]], a_to_z, a_to_z) diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index edb7dae159..54b97c5286 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -139,7 +139,7 @@ local dump_option = function(i, o) w(get_cond(o.enable_if)) end if o.varname then - w(' .var=(char_u *)&' .. o.varname) + w(' .var=(char *)&' .. o.varname) elseif #o.scope == 1 and o.scope[1] == 'window' then w(' .var=VAR_WIN') end -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- src/nvim/generators/gen_eval.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index fb1dd82a26..a86dc4233e 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -94,12 +94,12 @@ for _, name in ipairs(neworder) do end local base = def.base or "BASE_NONE" local func = def.func or ('f_' .. name) - local data = def.data or "{ .nullptr = NULL }" + local data = def.data or "{ .null = NULL }" local fast = def.fast and 'true' or 'false' hashpipe:write((' { "%s", %s, %s, %s, %s, &%s, %s },\n') :format(name, args[1], args[2], base, fast, func, data)) end -hashpipe:write(' { NULL, 0, 0, BASE_NONE, false, NULL, { .nullptr = NULL } },\n') +hashpipe:write(' { NULL, 0, 0, BASE_NONE, false, NULL, { .null = NULL } },\n') hashpipe:write("};\n\n") hashpipe:write(hashfun) hashpipe:close() -- cgit From efb0896f21e03f64e3a14e7c09994e81956f47b9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 3 Apr 2023 15:21:24 +0200 Subject: refactor(api): make typed dicts appear as types in the source code problem: can we have Serde? solution: we have Serde at home This by itself is just a change of notation, that could be quickly merged to avoid messy merge conflicts, but upcoming changes are planned: - keysets no longer need to be defined in one single file. `keysets.h` is just the initial automatic conversion of the previous `keysets.lua`. keysets just used in a single api/{scope}.h can be moved to that file, later on. - Typed dicts will have more specific types than Object. this will enable most of the existing manual typechecking boilerplate to be eliminated. We will need some annotation for missing value, i e a boolean will need to be represented as a TriState (none/false/true) in some cases. - Eventually: optional parameters in form of a `Dict opts` final parameter will get added in some form to metadata. this will require a discussion/desicion about type forward compatibility. --- src/nvim/generators/c_grammar.lua | 8 +- src/nvim/generators/gen_api_dispatch.lua | 140 +++++++++++++++++++++++-------- src/nvim/generators/gen_keysets.lua | 80 ------------------ 3 files changed, 113 insertions(+), 115 deletions(-) delete mode 100644 src/nvim/generators/gen_keysets.lua (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua index 3e89b60b4a..17a224fd22 100644 --- a/src/nvim/generators/c_grammar.lua +++ b/src/nvim/generators/c_grammar.lua @@ -55,5 +55,11 @@ local c_proto = Ct( fill * P(';') ) -local grammar = Ct((c_proto + c_comment + c_preproc + ws) ^ 1) +local c_field = Ct(Cg(c_id, 'type') * ws * Cg(c_id, 'name') * fill * P(';') * fill) +local c_keyset = Ct( + P('typedef') * ws * P('struct') * fill * P('{') * fill * + Cg(Ct(c_field ^ 1), 'fields') * + P('}') * fill * P('Dict') * fill * P('(') * Cg(c_id, 'keyset_name') * fill * P(')') * P(';')) + +local grammar = Ct((c_proto + c_comment + c_preproc + ws + c_keyset) ^ 1) return {grammar=grammar, typed_container=typed_container} diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 8aa1829364..f292c265ec 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -8,6 +8,7 @@ if arg[1] == '--help' then print(' 3: functions metadata output file (funcs_metadata.generated.h)') print(' 4: API metadata output file (api_metadata.mpack)') print(' 5: lua C bindings output file (lua_api_c_bindings.generated.c)') + print(' 6: keyset definitions output file (keysets_defs.generated.h)') print(' rest: C files where API functions are defined') end assert(#arg >= 4) @@ -32,6 +33,7 @@ local funcs_metadata_outputf = arg[3] -- output metadata mpack file, for use by other build scripts local mpack_outputf = arg[4] local lua_c_bindings_outputf = arg[5] +local keysets_outputf = arg[6] -- set of function names, used to detect duplicates local function_names = {} @@ -42,8 +44,57 @@ local function startswith(String,Start) return string.sub(String,1,string.len(Start))==Start end +local function add_function(fn) + local public = startswith(fn.name, "nvim_") or fn.deprecated_since + if public and not fn.noexport then + functions[#functions + 1] = fn + function_names[fn.name] = true + if #fn.parameters >= 2 and fn.parameters[2][1] == 'Array' and fn.parameters[2][2] == 'uidata' then + -- function receives the "args" as a parameter + fn.receives_array_args = true + -- remove the args parameter + table.remove(fn.parameters, 2) + end + if #fn.parameters ~= 0 and fn.parameters[1][2] == 'channel_id' then + -- this function should receive the channel id + fn.receives_channel_id = true + -- remove the parameter since it won't be passed by the api client + table.remove(fn.parameters, 1) + end + if #fn.parameters ~= 0 and fn.parameters[#fn.parameters][1] == 'error' then + -- function can fail if the last parameter type is 'Error' + fn.can_fail = true + -- remove the error parameter, msgpack has it's own special field + -- for specifying errors + fn.parameters[#fn.parameters] = nil + end + if #fn.parameters ~= 0 and fn.parameters[#fn.parameters][1] == 'arena' then + -- return value is allocated in an arena + fn.arena_return = true + fn.parameters[#fn.parameters] = nil + end + if #fn.parameters ~= 0 and fn.parameters[#fn.parameters][1] == 'lstate' then + fn.has_lua_imp = true + fn.parameters[#fn.parameters] = nil + end + end +end + +local keysets = {} + +local function add_keyset(val) + local keys = {} + for _,field in ipairs(val.fields) do + if field.type ~= 'Object' then + error 'not yet implemented: types other than Object' + end + table.insert(keys, field.name) + end + table.insert(keysets, {val.keyset_name, keys}) +end + -- read each input file, parse and append to the api metadata -for i = 6, #arg do +for i = 7, #arg do local full_path = arg[i] local parts = {} for part in string.gmatch(full_path, '[^/]+') do @@ -55,39 +106,11 @@ for i = 6, #arg do local tmp = c_grammar.grammar:match(input:read('*all')) for j = 1, #tmp do - local fn = tmp[j] - local public = startswith(fn.name, "nvim_") or fn.deprecated_since - if public and not fn.noexport then - functions[#functions + 1] = tmp[j] - function_names[fn.name] = true - if #fn.parameters >= 2 and fn.parameters[2][1] == 'Array' and fn.parameters[2][2] == 'uidata' then - -- function receives the "args" as a parameter - fn.receives_array_args = true - -- remove the args parameter - table.remove(fn.parameters, 2) - end - if #fn.parameters ~= 0 and fn.parameters[1][2] == 'channel_id' then - -- this function should receive the channel id - fn.receives_channel_id = true - -- remove the parameter since it won't be passed by the api client - table.remove(fn.parameters, 1) - end - if #fn.parameters ~= 0 and fn.parameters[#fn.parameters][1] == 'error' then - -- function can fail if the last parameter type is 'Error' - fn.can_fail = true - -- remove the error parameter, msgpack has it's own special field - -- for specifying errors - fn.parameters[#fn.parameters] = nil - end - if #fn.parameters ~= 0 and fn.parameters[#fn.parameters][1] == 'arena' then - -- return value is allocated in an arena - fn.arena_return = true - fn.parameters[#fn.parameters] = nil - end - if #fn.parameters ~= 0 and fn.parameters[#fn.parameters][1] == 'lstate' then - fn.has_lua_imp = true - fn.parameters[#fn.parameters] = nil - end + local val = tmp[j] + if val.keyset_name then + add_keyset(val) + else + add_function(val) end end input:close() @@ -195,6 +218,7 @@ funcs_metadata_output:close() -- start building the dispatch wrapper output local output = io.open(dispatch_outputf, 'wb') +local keysets_defs = io.open(keysets_outputf, 'wb') -- =========================================================================== -- NEW API FILES MUST GO HERE. @@ -224,6 +248,52 @@ output:write([[ ]]) +for _,keyset in ipairs(keysets) do + local name, keys = unpack(keyset) + local special = {} + local function sanitize(key) + if special[key] then + return key .. "_" + end + return key + end + + for i = 1,#keys do + if vim.endswith(keys[i], "_") then + keys[i] = string.sub(keys[i],1, #(keys[i]) - 1) + special[keys[i]] = true + end + end + local neworder, hashfun = hashy.hashy_hash(name, keys, function (idx) + return name.."_table["..idx.."].str" + end) + + keysets_defs:write("extern KeySetLink "..name.."_table[];\n") + + output:write("KeySetLink "..name.."_table[] = {\n") + for _, key in ipairs(neworder) do + output:write(' {"'..key..'", offsetof(KeyDict_'..name..", "..sanitize(key)..")},\n") + end + output:write(' {NULL, 0},\n') + output:write("};\n\n") + + output:write(hashfun) + + output:write([[ +Object *KeyDict_]]..name..[[_get_field(void *retval, const char *str, size_t len) +{ + int hash = ]]..name..[[_hash(str, len); + if (hash == -1) { + return NULL; + } + + return (Object *)((char *)retval + ]]..name..[[_table[hash].ptr_off); +} + +]]) + keysets_defs:write("#define api_free_keydict_"..name.."(x) api_free_keydict(x, "..name.."_table)\n") +end + local function real_type(type) local rv = type local rmatch = string.match(type, "Dict%(([_%w]+)%)") @@ -475,6 +545,7 @@ output:write([[ #include "nvim/func_attr.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" +#include "nvim/api/private/dispatch.h" #include "nvim/lua/converter.h" #include "nvim/lua/executor.h" #include "nvim/memory.h" @@ -670,3 +741,4 @@ output:write([[ ]]) output:close() +keysets_defs:close() diff --git a/src/nvim/generators/gen_keysets.lua b/src/nvim/generators/gen_keysets.lua deleted file mode 100644 index b1c1f3e2d8..0000000000 --- a/src/nvim/generators/gen_keysets.lua +++ /dev/null @@ -1,80 +0,0 @@ -local nvimsrcdir = arg[1] -local shared_file = arg[2] -local funcs_file = arg[3] -local defs_file = arg[4] - -_G.vim = loadfile(shared_file)() - -if nvimsrcdir == '--help' then - print([[ -Usage: - lua gen_keyset.lua TODOFIXUPDATETHIS - -Will generate build/src/nvim/auto/keyset.generated.h with definition of functions -static const array. -]]) - os.exit(0) -end - - -package.path = nvimsrcdir .. '/?.lua;' .. package.path -local hashy = require'generators.hashy' - -local funcspipe = io.open(funcs_file, 'wb') -local defspipe = io.open(defs_file, 'wb') - -local keysets = require'api.keysets' - -local keywords = { - register = true; - default = true; -} - -local function sanitize(key) - if keywords[key] then - return key .. "_" - end - return key -end - -for _, v in ipairs(keysets) do - local name = v[1] - local keys = v[2] - local neworder, hashfun = hashy.hashy_hash(name, keys, function (idx) - return name.."_table["..idx.."].str" - end) - - defspipe:write("typedef struct {\n") - for _, key in ipairs(neworder) do - defspipe:write(" Object "..sanitize(key)..";\n") - end - defspipe:write("} KeyDict_"..name..";\n\n") - - defspipe:write("extern KeySetLink "..name.."_table[];\n") - - funcspipe:write("KeySetLink "..name.."_table[] = {\n") - for _, key in ipairs(neworder) do - funcspipe:write(' {"'..key..'", offsetof(KeyDict_'..name..", "..sanitize(key)..")},\n") - end - funcspipe:write(' {NULL, 0},\n') - funcspipe:write("};\n\n") - - funcspipe:write(hashfun) - - funcspipe:write([[ -Object *KeyDict_]]..name..[[_get_field(void *retval, const char *str, size_t len) -{ - int hash = ]]..name..[[_hash(str, len); - if (hash == -1) { - return NULL; - } - - return (Object *)((char *)retval + ]]..name..[[_table[hash].ptr_off); -} - -]]) - defspipe:write("#define api_free_keydict_"..name.."(x) api_free_keydict(x, "..name.."_table)\n") -end - -funcspipe:close() -defspipe:close() -- cgit From 1e60e8c0406f6b4b51c51abb5f53e25bd52fee5e Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 15 Apr 2023 12:23:45 +0200 Subject: refactor(build): use vendored versions of mpack and luabitop --- src/nvim/generators/gen_api_dispatch.lua | 45 ++++++++++--------------------- src/nvim/generators/gen_api_ui_events.lua | 18 +++++-------- src/nvim/generators/gen_eval.lua | 29 +++++--------------- src/nvim/generators/gen_events.lua | 12 ++------- src/nvim/generators/gen_ex_cmds.lua | 20 +++----------- src/nvim/generators/gen_options.lua | 10 +------ src/nvim/generators/preload.lua | 9 +++++++ 7 files changed, 44 insertions(+), 99 deletions(-) create mode 100644 src/nvim/generators/preload.lua (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index f292c265ec..ad7018e385 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -1,40 +1,23 @@ local mpack = require('mpack') --- we need at least 4 arguments since the last two are output files -if arg[1] == '--help' then - print('Usage: genmsgpack.lua args') - print('Args: 1: source directory') - print(' 2: dispatch output file (dispatch_wrappers.generated.h)') - print(' 3: functions metadata output file (funcs_metadata.generated.h)') - print(' 4: API metadata output file (api_metadata.mpack)') - print(' 5: lua C bindings output file (lua_api_c_bindings.generated.c)') - print(' 6: keyset definitions output file (keysets_defs.generated.h)') - print(' rest: C files where API functions are defined') -end -assert(#arg >= 4) -local functions = {} - -local nvimdir = arg[1] -package.path = nvimdir .. '/?.lua;' .. package.path +local hashy = require'generators.hashy' -_G.vim = loadfile(nvimdir..'/../../runtime/lua/vim/shared.lua')() -_G.vim.inspect = loadfile(nvimdir..'/../../runtime/lua/vim/inspect.lua')() +assert(#arg >= 5) +-- output h file with generated dispatch functions (dispatch_wrappers.generated.h) +local dispatch_outputf = arg[1] +-- output h file with packed metadata (funcs_metadata.generated.h) +local funcs_metadata_outputf = arg[2] +-- output metadata mpack file, for use by other build scripts (api_metadata.mpack) +local mpack_outputf = arg[3] +local lua_c_bindings_outputf = arg[4] -- lua_api_c_bindings.generated.c +local keysets_outputf = arg[5] -- keysets_defs.generated.h -local hashy = require'generators.hashy' +local functions = {} -- names of all headers relative to the source root (for inclusion in the -- generated file) local headers = {} --- output h file with generated dispatch functions -local dispatch_outputf = arg[2] --- output h file with packed metadata -local funcs_metadata_outputf = arg[3] --- output metadata mpack file, for use by other build scripts -local mpack_outputf = arg[4] -local lua_c_bindings_outputf = arg[5] -local keysets_outputf = arg[6] - -- set of function names, used to detect duplicates local function_names = {} @@ -94,7 +77,7 @@ local function add_keyset(val) end -- read each input file, parse and append to the api metadata -for i = 7, #arg do +for i = 6, #arg do local full_path = arg[i] local parts = {} for part in string.gmatch(full_path, '[^/]+') do @@ -210,7 +193,7 @@ end -- serialize the API metadata using msgpack and embed into the resulting -- binary for easy querying by clients local funcs_metadata_output = io.open(funcs_metadata_outputf, 'wb') -local packed = mpack.pack(exported_functions) +local packed = mpack.encode(exported_functions) local dump_bin_array = require("generators.dump_bin_array") dump_bin_array(funcs_metadata_output, 'funcs_metadata', packed) funcs_metadata_output:close() @@ -514,7 +497,7 @@ output:write(hashfun) output:close() local mpack_output = io.open(mpack_outputf, 'wb') -mpack_output:write(mpack.pack(functions)) +mpack_output:write(mpack.encode(functions)) mpack_output:close() local function include_headers(output_handle, headers_to_include) diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua index bbc6252f14..c6a5d1d2a3 100755 --- a/src/nvim/generators/gen_api_ui_events.lua +++ b/src/nvim/generators/gen_api_ui_events.lua @@ -1,19 +1,15 @@ local mpack = require('mpack') -local nvimdir = arg[1] -package.path = nvimdir .. '/?.lua;' .. package.path - -assert(#arg == 6) -local input = io.open(arg[2], 'rb') -local call_output = io.open(arg[3], 'wb') -local remote_output = io.open(arg[4], 'wb') -local metadata_output = io.open(arg[5], 'wb') -local client_output = io.open(arg[6], 'wb') +assert(#arg == 5) +local input = io.open(arg[1], 'rb') +local call_output = io.open(arg[2], 'wb') +local remote_output = io.open(arg[3], 'wb') +local metadata_output = io.open(arg[4], 'wb') +local client_output = io.open(arg[5], 'wb') local c_grammar = require('generators.c_grammar') local events = c_grammar.grammar:match(input:read('*all')) -_G.vim = loadfile(nvimdir..'/../../runtime/lua/vim/shared.lua')() local hashy = require'generators.hashy' local function write_signature(output, ev, prefix, notype) @@ -194,7 +190,7 @@ for _,ev in ipairs(events) do end end -local packed = mpack.pack(exported_events) +local packed = mpack.encode(exported_events) local dump_bin_array = require("generators.dump_bin_array") dump_bin_array(metadata_output, 'ui_events_metadata', packed) metadata_output:close() diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index a86dc4233e..15e4c6540a 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -1,28 +1,13 @@ local mpack = require('mpack') -local nvimsrcdir = arg[1] -local shared_file = arg[2] -local autodir = arg[3] -local metadata_file = arg[4] -local funcs_file = arg[5] - -_G.vim = loadfile(shared_file)() - -if nvimsrcdir == '--help' then - print([[ -Usage: - lua gen_eval.lua src/nvim build/src/nvim/auto - -Will generate build/src/nvim/auto/funcs.generated.h with definition of functions -static const array. -]]) - os.exit(0) -end - -package.path = nvimsrcdir .. '/?.lua;' .. package.path +local autodir = arg[1] +local metadata_file = arg[2] +local funcs_file = arg[3] local funcsfname = autodir .. '/funcs.generated.h' +--Will generate funcs.generated.h with definition of functions static const array. + local hashy = require'generators.hashy' local hashpipe = io.open(funcsfname, 'wb') @@ -63,7 +48,7 @@ for _, func in pairs(funcs) do end end -local metadata = mpack.unpack(io.open(metadata_file, 'rb'):read("*all")) +local metadata = mpack.decode(io.open(metadata_file, 'rb'):read("*all")) for _,fun in ipairs(metadata) do if fun.eval then funcs[fun.name] = { @@ -77,7 +62,7 @@ end local func_names = vim.tbl_keys(funcs) table.sort(func_names) local funcsdata = io.open(funcs_file, 'w') -funcsdata:write(mpack.pack(func_names)) +funcsdata:write(mpack.encode(func_names)) funcsdata:close() local neworder, hashfun = hashy.hashy_hash("find_internal_func", func_names, function (idx) diff --git a/src/nvim/generators/gen_events.lua b/src/nvim/generators/gen_events.lua index 8db7f22452..27cec40b03 100644 --- a/src/nvim/generators/gen_events.lua +++ b/src/nvim/generators/gen_events.lua @@ -1,13 +1,5 @@ -if arg[1] == '--help' then - print('Usage: gen_events.lua src/nvim enum_file event_names_file') - os.exit(0) -end - -local nvimsrcdir = arg[1] -local fileio_enum_file = arg[2] -local names_file = arg[3] - -package.path = nvimsrcdir .. '/?.lua;' .. package.path +local fileio_enum_file = arg[1] +local names_file = arg[2] local auevents = require('auevents') local events = auevents.events diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index 26edd33604..76b372eac2 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -1,20 +1,8 @@ -local nvimsrcdir = arg[1] -local includedir = arg[2] -local autodir = arg[3] +local includedir = arg[1] +local autodir = arg[2] -if nvimsrcdir == '--help' then - print ([[ -Usage: - lua genex_cmds.lua src/nvim build/include build/src/nvim/auto - -Will generate files build/include/ex_cmds_enum.generated.h with cmdidx_T -enum and build/src/nvim/auto/ex_cmds_defs.generated.h with main Ex commands -definitions. -]]) - os.exit(0) -end - -package.path = nvimsrcdir .. '/?.lua;' .. package.path +-- Will generate files ex_cmds_enum.generated.h with cmdidx_T enum +-- and ex_cmds_defs.generated.h with main Ex commands definitions. local enumfname = includedir .. '/ex_cmds_enum.generated.h' local defsfname = autodir .. '/ex_cmds_defs.generated.h' diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 54b97c5286..35302e1222 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -1,12 +1,4 @@ -if arg[1] == '--help' then - print('Usage: genoptions.lua src/nvim options_file') - os.exit(0) -end - -local nvimsrcdir = arg[1] -local options_file = arg[2] - -package.path = nvimsrcdir .. '/?.lua;' .. package.path +local options_file = arg[1] local opt_fd = io.open(options_file, 'w') diff --git a/src/nvim/generators/preload.lua b/src/nvim/generators/preload.lua new file mode 100644 index 0000000000..e5c8bd545b --- /dev/null +++ b/src/nvim/generators/preload.lua @@ -0,0 +1,9 @@ +local srcdir = table.remove(arg, 1) +local nlualib = table.remove(arg, 1) +package.path = srcdir .. '/src/nvim/?.lua;' ..srcdir .. '/runtime/lua/?.lua;' .. package.path +_G.vim = require'vim.shared' +_G.vim.inspect = require 'vim.inspect' +package.cpath = package.cpath .. ';' .. nlualib + +arg[0] = table.remove(arg, 1) +return loadfile(arg[0])() -- cgit From ffaf74f1477d3182ffc70bcc9913effc44c90ea7 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 20 Apr 2023 14:41:47 +0200 Subject: fix(build): distinguish vim.mpack from global require'mpack' problem: the api of vim.mpack is not compatible with a system provided mpack solution: don't require 'mpack' directly from the system path --- src/nvim/generators/gen_api_dispatch.lua | 2 +- src/nvim/generators/gen_api_ui_events.lua | 2 +- src/nvim/generators/gen_eval.lua | 2 +- src/nvim/generators/preload.lua | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index ad7018e385..244921de31 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -1,4 +1,4 @@ -local mpack = require('mpack') +local mpack = vim.mpack local hashy = require'generators.hashy' diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua index c6a5d1d2a3..e2af5f8d44 100755 --- a/src/nvim/generators/gen_api_ui_events.lua +++ b/src/nvim/generators/gen_api_ui_events.lua @@ -1,4 +1,4 @@ -local mpack = require('mpack') +local mpack = vim.mpack assert(#arg == 5) local input = io.open(arg[1], 'rb') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index 15e4c6540a..e574efdf99 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -1,4 +1,4 @@ -local mpack = require('mpack') +local mpack = vim.mpack local autodir = arg[1] local metadata_file = arg[2] diff --git a/src/nvim/generators/preload.lua b/src/nvim/generators/preload.lua index e5c8bd545b..4b7fde2c39 100644 --- a/src/nvim/generators/preload.lua +++ b/src/nvim/generators/preload.lua @@ -4,6 +4,7 @@ package.path = srcdir .. '/src/nvim/?.lua;' ..srcdir .. '/runtime/lua/?.lua;' .. _G.vim = require'vim.shared' _G.vim.inspect = require 'vim.inspect' package.cpath = package.cpath .. ';' .. nlualib +require 'nlua0' arg[0] = table.remove(arg, 1) return loadfile(arg[0])() -- cgit From 702892270dec627acb3dd585495ee0950f690bde Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 21 Apr 2023 16:46:35 +0200 Subject: refactor(build): move the last generator from scripts/ to src/nvim/generators This one generates a runtime/ file instead of a source file. But otherwise it works the same like all other generators. It has the same prerequisites (shared and mpack modules, etc), and, importantly, it uses results from the source generators. The odd location makes it easy to overlook when refactoring generators (like I did last time, lol) --- src/nvim/generators/gen_vimvim.lua | 148 +++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/nvim/generators/gen_vimvim.lua (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_vimvim.lua b/src/nvim/generators/gen_vimvim.lua new file mode 100644 index 0000000000..09a7cab0c6 --- /dev/null +++ b/src/nvim/generators/gen_vimvim.lua @@ -0,0 +1,148 @@ +local mpack = vim.mpack + +local syntax_file = arg[1] +local funcs_file = arg[2] + +local lld = {} +local syn_fd = io.open(syntax_file, 'w') +lld.line_length = 0 +local function w(s) + syn_fd:write(s) + if s:find('\n') then + lld.line_length = #(s:gsub('.*\n', '')) + else + lld.line_length = lld.line_length + #s + end +end + +local options = require('options') +local auevents = require('auevents') +local ex_cmds = require('ex_cmds') + +local function cmd_kw(prev_cmd, cmd) + if not prev_cmd then + return cmd:sub(1, 1) .. '[' .. cmd:sub(2) .. ']' + else + local shift = 1 + while cmd:sub(shift, shift) == prev_cmd:sub(shift, shift) do + shift = shift + 1 + end + if cmd:sub(1, shift) == 'def' then + shift = shift + 1 + end + if shift >= #cmd then + return cmd + else + return cmd:sub(1, shift) .. '[' .. cmd:sub(shift + 1) .. ']' + end + end +end + +-- Exclude these from the vimCommand keyword list, they are handled specially +-- in syntax/vim.vim (vimAugroupKey, vimAutoCmd, vimGlobal, vimSubst). #9327 +local function is_special_cased_cmd(cmd) + return (cmd == 'augroup' + or cmd == 'autocmd' + or cmd == 'doautocmd' + or cmd == 'doautoall' + or cmd == 'global' + or cmd == 'substitute') +end + +local vimcmd_start = 'syn keyword vimCommand contained ' +w(vimcmd_start) +local prev_cmd = nil +for _, cmd_desc in ipairs(ex_cmds.cmds) do + if lld.line_length > 850 then + w('\n' .. vimcmd_start) + end + local cmd = cmd_desc.command + if cmd:match('%w') and cmd ~= 'z' and not is_special_cased_cmd(cmd) then + w(' ' .. cmd_kw(prev_cmd, cmd)) + end + if cmd == 'delete' then + -- Add special abbreviations of :delete + w(' ' .. cmd_kw('d', 'dl')) + w(' ' .. cmd_kw('del', 'dell')) + w(' ' .. cmd_kw('dele', 'delel')) + w(' ' .. cmd_kw('delet', 'deletl')) + w(' ' .. cmd_kw('delete', 'deletel')) + w(' ' .. cmd_kw('d', 'dp')) + w(' ' .. cmd_kw('de', 'dep')) + w(' ' .. cmd_kw('del', 'delp')) + w(' ' .. cmd_kw('dele', 'delep')) + w(' ' .. cmd_kw('delet', 'deletp')) + w(' ' .. cmd_kw('delete', 'deletep')) + end + prev_cmd = cmd +end + +local vimopt_start = 'syn keyword vimOption contained ' +w('\n\n' .. vimopt_start) + +for _, opt_desc in ipairs(options.options) do + if not opt_desc.varname or opt_desc.varname:sub(1, 7) ~= 'p_force' then + if lld.line_length > 850 then + w('\n' .. vimopt_start) + end + w(' ' .. opt_desc.full_name) + if opt_desc.abbreviation then + w(' ' .. opt_desc.abbreviation) + end + if opt_desc.type == 'bool' then + w(' inv' .. opt_desc.full_name) + w(' no' .. opt_desc.full_name) + if opt_desc.abbreviation then + w(' inv' .. opt_desc.abbreviation) + w(' no' .. opt_desc.abbreviation) + end + end + end +end + +w('\n\nsyn case ignore') +local vimau_start = 'syn keyword vimAutoEvent contained ' +w('\n\n' .. vimau_start) + +for _, au in ipairs(auevents.events) do + if not auevents.nvim_specific[au] then + if lld.line_length > 850 then + w('\n' .. vimau_start) + end + w(' ' .. au) + end +end +for au, _ in pairs(auevents.aliases) do + if not auevents.nvim_specific[au] then + if lld.line_length > 850 then + w('\n' .. vimau_start) + end + w(' ' .. au) + end +end + +local nvimau_start = 'syn keyword nvimAutoEvent contained ' +w('\n\n' .. nvimau_start) + +for au, _ in vim.spairs(auevents.nvim_specific) do + if lld.line_length > 850 then + w('\n' .. nvimau_start) + end + w(' ' .. au) +end + +w('\n\nsyn case match') +local vimfun_start = 'syn keyword vimFuncName contained ' +w('\n\n' .. vimfun_start) +local funcs = mpack.decode(io.open(funcs_file, 'rb'):read("*all")) +for _, name in ipairs(funcs) do + if name then + if lld.line_length > 850 then + w('\n' .. vimfun_start) + end + w(' ' .. name) + end +end + +w('\n') +syn_fd:close() -- cgit From 907018e547c9b989781667d2cf951e1abf99ab9d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Apr 2023 00:23:11 +0800 Subject: vim-patch:8.2.3139: functions for string manipulation are spread out (#23316) Problem: Functions for string manipulation are spread out. Solution: Move string related functions to a new source file. (Yegappan Lakshmanan, closes vim/vim#8470) https://github.com/vim/vim/commit/a2438132a675be4dde3acbdf03ba1fdb2f09427c Co-authored-by: Yegappan Lakshmanan --- src/nvim/generators/gen_eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index e574efdf99..7d531bc228 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -35,6 +35,7 @@ hashpipe:write([[ #include "nvim/quickfix.h" #include "nvim/runtime.h" #include "nvim/search.h" +#include "nvim/strings.h" #include "nvim/sign.h" #include "nvim/testing.h" -- cgit From 55793bcfa17ccc6f5a3566664ba1e522f74fb50c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Apr 2023 13:38:30 +0800 Subject: build: revert accidental permission changes (#23319) Revert the permission changes in 794d2744f33562326172801ddd729853e7135347. --- src/nvim/generators/gen_api_ui_events.lua | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/nvim/generators/gen_api_ui_events.lua (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua old mode 100755 new mode 100644 -- cgit From 45bcf8386918bbb475fbe20c48b508aa89ed0624 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 20 Apr 2023 13:19:38 +0200 Subject: refactor(build): include lpeg as a library --- src/nvim/generators/c_grammar.lua | 2 +- src/nvim/generators/gen_declarations.lua | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) mode change 100755 => 100644 src/nvim/generators/gen_declarations.lua (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua index 17a224fd22..d83658e977 100644 --- a/src/nvim/generators/c_grammar.lua +++ b/src/nvim/generators/c_grammar.lua @@ -1,4 +1,4 @@ -local lpeg = require('lpeg') +local lpeg = vim.lpeg -- lpeg grammar for building api metadata from a set of header files. It -- ignores comments and preprocessor commands and parses a very small subset diff --git a/src/nvim/generators/gen_declarations.lua b/src/nvim/generators/gen_declarations.lua old mode 100755 new mode 100644 index 4097ff7dc5..7ed0624b05 --- a/src/nvim/generators/gen_declarations.lua +++ b/src/nvim/generators/gen_declarations.lua @@ -1,12 +1,9 @@ -#!/usr/bin/lua - local fname = arg[1] local static_fname = arg[2] local non_static_fname = arg[3] local preproc_fname = arg[4] - -local lpeg = require('lpeg') +local lpeg = vim.lpeg local fold = function (func, ...) local result = nil -- cgit From 1cb60405548e79f1ec63921540e1c3ebb3ddcc01 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:25:08 +0200 Subject: perf(events): store autocommands in flat vectors (#23256) Instead of nested linked lists, store autocommands in a flat, contiguous kvec_t, with one kvec_t per event type. Previously patterns were stored in each node of the outer linked list, so they can be matched only once on repeating patterns. They are now reference counted and referenced in each autocommand, and matching is skipped if the pattern repeats. Speeds up creation and deletion, execution is not affected. Co-authored-by: ii14 --- src/nvim/generators/gen_events.lua | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_events.lua b/src/nvim/generators/gen_events.lua index 27cec40b03..0eb231f012 100644 --- a/src/nvim/generators/gen_events.lua +++ b/src/nvim/generators/gen_events.lua @@ -35,27 +35,24 @@ names_tgt:write('\n {0, NULL, (event_T)0},') enum_tgt:write('\n} event_T;\n') names_tgt:write('\n};\n') -local gen_autopat_events = function(name) - names_tgt:write(string.format('\nstatic AutoPat *%s[NUM_EVENTS] = {\n ', name)) +do + names_tgt:write('\nstatic AutoCmdVec autocmds[NUM_EVENTS] = {\n ') local line_len = 1 for _ = 1,((#events) - 1) do - line_len = line_len + #(' NULL,') + line_len = line_len + #(' KV_INITIAL_VALUE,') if line_len > 80 then names_tgt:write('\n ') - line_len = 1 + #(' NULL,') + line_len = 1 + #(' KV_INITIAL_VALUE,') end - names_tgt:write(' NULL,') + names_tgt:write(' KV_INITIAL_VALUE,') end - if line_len + #(' NULL') > 80 then - names_tgt:write('\n NULL') + if line_len + #(' KV_INITIAL_VALUE') > 80 then + names_tgt:write('\n KV_INITIAL_VALUE') else - names_tgt:write(' NULL') + names_tgt:write(' KV_INITIAL_VALUE') end names_tgt:write('\n};\n') end -gen_autopat_events("first_autopat") -gen_autopat_events("last_autopat") - enum_tgt:close() names_tgt:close() -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/generators/gen_options.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 35302e1222..ecb1a0c11b 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -154,6 +154,9 @@ local dump_option = function(i, o) table.insert(defines, { 'PV_' .. varname:sub(3):upper() , pv_name}) w(' .indir=' .. pv_name) end + if o.cb then + w(' .opt_did_set_cb=' .. o.cb) + end if o.enable_if then w('#else') w(' .var=NULL') -- cgit From 86c9d8b53cd9c2713eb2f7fa07732ca9a65a4afb Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Tue, 2 May 2023 16:16:52 +0900 Subject: fix(gen_vimvim): correctly add aliases to vimAutoEvent (#23429) close #23424 --- src/nvim/generators/gen_vimvim.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_vimvim.lua b/src/nvim/generators/gen_vimvim.lua index 09a7cab0c6..29355d3cda 100644 --- a/src/nvim/generators/gen_vimvim.lua +++ b/src/nvim/generators/gen_vimvim.lua @@ -112,13 +112,12 @@ for _, au in ipairs(auevents.events) do w(' ' .. au) end end -for au, _ in pairs(auevents.aliases) do - if not auevents.nvim_specific[au] then - if lld.line_length > 850 then - w('\n' .. vimau_start) - end - w(' ' .. au) +for _, au in pairs(auevents.aliases) do + if lld.line_length > 850 then + w('\n' .. vimau_start) end + -- au[1] is aliased to au[2] + w(' ' .. au[1]) end local nvimau_start = 'syn keyword nvimAutoEvent contained ' -- cgit From b441dafdf53e367c7d43177274bd781c5c73e6e0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 16:46:38 +0800 Subject: vim-patch:8.2.2344: using inclusive index for slice is not always desired Problem: Using inclusive index for slice is not always desired. Solution: Add the slice() method, which has an exclusive index. (closes vim/vim#7408) https://github.com/vim/vim/commit/6601b62943a19d4f8818c3638440663d67a17b6a Cherry-pick a line in docs added later. Co-authored-by: Bram Moolenaar --- src/nvim/generators/gen_eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index 7d531bc228..e93e9a8d02 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -17,6 +17,7 @@ hashpipe:write([[ #include "nvim/cmdexpand.h" #include "nvim/cmdhist.h" #include "nvim/digraph.h" +#include "nvim/eval.h" #include "nvim/eval/buffer.h" #include "nvim/eval/funcs.h" #include "nvim/eval/typval.h" -- cgit From 677e02be4e1255435a39d25a4b12ecbed4fff37b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 May 2023 18:11:03 +0800 Subject: refactor: fix clang/PVS warnings (#23731) --- src/nvim/generators/gen_ex_cmds.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index 76b372eac2..b9fae7d0fe 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -55,6 +55,7 @@ defsfile:write(string.format([[ #include "nvim/help.h" #include "nvim/indent.h" #include "nvim/lua/executor.h" +#include "nvim/lua/secure.h" #include "nvim/mapping.h" #include "nvim/mark.h" #include "nvim/match.h" -- cgit From 3681b7bb3bb942462c4261ab477e8912ae35b1a9 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 20 Jun 2023 13:09:06 +0600 Subject: refactor(option): use `void *` for pointer to option value Option related code uses `char *` for pointer to option value, which is not the best way of representing a type-agnostic pointer. Solution: Make pointers to option value use `void *` instead. --- src/nvim/generators/gen_options.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index ecb1a0c11b..03b1fbec8a 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -108,7 +108,7 @@ local value_dumpers = { } local get_value = function(v) - return '(char *) ' .. value_dumpers[type(v)](v) + return '(void *) ' .. value_dumpers[type(v)](v) end local get_defaults = function(d,n) @@ -131,7 +131,7 @@ local dump_option = function(i, o) w(get_cond(o.enable_if)) end if o.varname then - w(' .var=(char *)&' .. o.varname) + w(' .var=&' .. o.varname) elseif #o.scope == 1 and o.scope[1] == 'window' then w(' .var=VAR_WIN') end -- cgit From 77118d0da8badc4135be430f4cbb15bc95bc760f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 20 Apr 2023 21:17:25 +0100 Subject: fix(api): use text_locked() to check textlock Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in #22634 that made functions checking textlock usable in `` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK. --- src/nvim/generators/c_grammar.lua | 3 ++- src/nvim/generators/gen_api_dispatch.lua | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua index d83658e977..f33da452ff 100644 --- a/src/nvim/generators/c_grammar.lua +++ b/src/nvim/generators/c_grammar.lua @@ -47,7 +47,8 @@ local c_proto = Ct( (fill * Cg((P('FUNC_API_NOEXPORT') * Cc(true)), 'noexport') ^ -1) * (fill * Cg((P('FUNC_API_REMOTE_ONLY') * Cc(true)), 'remote_only') ^ -1) * (fill * Cg((P('FUNC_API_LUA_ONLY') * Cc(true)), 'lua_only') ^ -1) * - (fill * Cg((P('FUNC_API_CHECK_TEXTLOCK') * Cc(true)), 'check_textlock') ^ -1) * + (fill * (Cg(P('FUNC_API_TEXTLOCK_ALLOW_CMDWIN') * Cc(true), 'textlock_allow_cmdwin') + + Cg(P('FUNC_API_TEXTLOCK') * Cc(true), 'textlock')) ^ -1) * (fill * Cg((P('FUNC_API_REMOTE_IMPL') * Cc(true)), 'remote_impl') ^ -1) * (fill * Cg((P('FUNC_API_COMPOSITOR_IMPL') * Cc(true)), 'compositor_impl') ^ -1) * (fill * Cg((P('FUNC_API_CLIENT_IMPL') * Cc(true)), 'client_impl') ^ -1) * diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 244921de31..bf211f5273 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -210,10 +210,11 @@ local keysets_defs = io.open(keysets_outputf, 'wb') -- so that the dispatcher can find the C functions that you are creating! -- =========================================================================== output:write([[ +#include "nvim/ex_docmd.h" +#include "nvim/ex_getln.h" #include "nvim/log.h" #include "nvim/map.h" #include "nvim/msgpack_rpc/helpers.h" -#include "nvim/vim.h" #include "nvim/api/autocmd.h" #include "nvim/api/buffer.h" @@ -389,8 +390,13 @@ for i = 1, #functions do args[#args + 1] = converted end - if fn.check_textlock then - output:write('\n if (textlock != 0) {') + if fn.textlock then + output:write('\n if (text_locked()) {') + output:write('\n api_set_error(error, kErrorTypeException, "%s", get_text_locked_msg());') + output:write('\n goto cleanup;') + output:write('\n }\n') + elseif fn.textlock_allow_cmdwin then + output:write('\n if (textlock != 0 || expr_map_locked()) {') output:write('\n api_set_error(error, kErrorTypeException, "%s", e_textlock);') output:write('\n goto cleanup;') output:write('\n }\n') @@ -525,6 +531,8 @@ output:write([[ #include #include +#include "nvim/ex_docmd.h" +#include "nvim/ex_getln.h" #include "nvim/func_attr.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" @@ -565,9 +573,16 @@ local function process_function(fn) ]], fn.name)) end - if fn.check_textlock then + if fn.textlock then + write_shifted_output(output, [[ + if (text_locked()) { + api_set_error(&err, kErrorTypeException, "%s", get_text_locked_msg()); + goto exit_0; + } + ]]) + elseif fn.textlock_allow_cmdwin then write_shifted_output(output, [[ - if (textlock != 0) { + if (textlock != 0 || expr_map_locked()) { api_set_error(&err, kErrorTypeException, "%s", e_textlock); goto exit_0; } -- cgit From b8b77820371978a5f937ccc0db356574ae33371b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Jul 2023 15:18:09 +0800 Subject: vim-patch:partial:8.1.1981: the evalfunc.c file is too big (#24490) Problem: The evalfunc.c file is too big. Solution: Move undo functions to undo.c. Move cmdline functions to ex_getln.c. Move some container functions to list.c. https://github.com/vim/vim/commit/08c308aeb5e7dfa18fa61f261b0bff79517a4883 Undo functions only. Cmdline functions have already been moved. A lot of container functions have been added to eval/funcs.c instead of list.c in previously ported Vim 8.2.x patches, so deal with that later. Co-authored-by: Bram Moolenaar --- src/nvim/generators/gen_eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index e93e9a8d02..6858fbc917 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -39,6 +39,7 @@ hashpipe:write([[ #include "nvim/strings.h" #include "nvim/sign.h" #include "nvim/testing.h" +#include "nvim/undo.h" ]]) -- cgit From 42333ea98dfcd2994ee128a3467dfe68205154cd Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 28 Jul 2023 14:48:41 +0100 Subject: feat(docs): generate builtin.txt (#24493) - eval.lua is now the source of truth. - Formatting is much more consistent. - Fixed Lua type generation for polymorphic functions (get(), etc). - Removed "Overview" section from builtin.txt - Can generate this if we really want it. - Moved functions from sign.txt and testing.txt into builtin.txt. - Removed the *timer* *timers* tags since libuv timers via vim.uv should be preferred. - Removed the temp-file-name tag from tempname() - Moved lueval() from lua.txt to builtin.txt. * Fix indent * fixup! * fixup! fixup! * fixup! better tag formatting * fixup: revert changes no longer needed * fixup! CI --------- Co-authored-by: zeertzjq --- src/nvim/generators/gen_eval.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index 6858fbc917..c7978f0d19 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -10,7 +10,7 @@ local funcsfname = autodir .. '/funcs.generated.h' local hashy = require'generators.hashy' -local hashpipe = io.open(funcsfname, 'wb') +local hashpipe = assert(io.open(funcsfname, 'wb')) hashpipe:write([[ #include "nvim/arglist.h" @@ -62,16 +62,22 @@ for _,fun in ipairs(metadata) do end end -local func_names = vim.tbl_keys(funcs) +local func_names = vim.tbl_filter(function(name) + return name:match('__%d*$') == nil +end, vim.tbl_keys(funcs)) + table.sort(func_names) -local funcsdata = io.open(funcs_file, 'w') + +local funcsdata = assert(io.open(funcs_file, 'w')) funcsdata:write(mpack.encode(func_names)) funcsdata:close() local neworder, hashfun = hashy.hashy_hash("find_internal_func", func_names, function (idx) return "functions["..idx.."].name" end) + hashpipe:write("static const EvalFuncDef functions[] = {\n") + for _, name in ipairs(neworder) do local def = funcs[name] local args = def.args or 0 -- cgit From 48d533272e57e91e4d14c93b26d4922957f40cd7 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 1 Aug 2023 14:20:44 +0100 Subject: feat(lua-types): types for vim.api.* (#24523) --- src/nvim/generators/gen_api_dispatch.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index bf211f5273..1b0565d9b6 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -71,7 +71,7 @@ local function add_keyset(val) if field.type ~= 'Object' then error 'not yet implemented: types other than Object' end - table.insert(keys, field.name) + table.insert(keys, {field.name, field.type}) end table.insert(keysets, {val.keyset_name, keys}) end @@ -242,13 +242,16 @@ for _,keyset in ipairs(keysets) do return key end + local key_names = {} for i = 1,#keys do - if vim.endswith(keys[i], "_") then - keys[i] = string.sub(keys[i],1, #(keys[i]) - 1) - special[keys[i]] = true + local kname = keys[i][1] + if vim.endswith(kname, "_") then + kname = string.sub(kname,1, #kname - 1) + special[kname] = true end + key_names[i] = kname end - local neworder, hashfun = hashy.hashy_hash(name, keys, function (idx) + local neworder, hashfun = hashy.hashy_hash(name, key_names, function (idx) return name.."_table["..idx.."].str" end) @@ -502,6 +505,7 @@ output:write(hashfun) output:close() +functions.keysets = keysets local mpack_output = io.open(mpack_outputf, 'wb') mpack_output:write(mpack.encode(functions)) mpack_output:close() -- cgit From c01e624b0762b24a4988bf9474a57d5b6278d180 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 23:19:17 +0200 Subject: feat(lua): more specific error messages for vim.api type checking --- src/nvim/generators/gen_api_dispatch.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 1b0565d9b6..fe63cb883e 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -558,6 +558,7 @@ local function process_function(fn) static int %s(lua_State *lstate) { Error err = ERROR_INIT; + char *err_param = 0; if (lua_gettop(lstate) != %i) { api_set_error(&err, kErrorTypeValidation, "Expected %i argument%s"); goto exit_0; @@ -605,6 +606,7 @@ local function process_function(fn) extra = "true, " end local errshift = 0 + local seterr = '' if string.match(param_type, '^KeyDict_') then write_shifted_output(output, string.format([[ %s %s = { 0 }; nlua_pop_keydict(lstate, &%s, %s_get_field, %s&err);]], param_type, cparam, cparam, param_type, extra)) @@ -613,11 +615,13 @@ local function process_function(fn) else write_shifted_output(output, string.format([[ const %s %s = nlua_pop_%s(lstate, %s&err);]], param[1], cparam, param_type, extra)) + seterr = [[ + err_param = "]]..param[2]..[[";]] end write_shifted_output(output, string.format([[ - if (ERROR_SET(&err)) { + if (ERROR_SET(&err)) {]]..seterr..[[ goto exit_%u; } @@ -661,9 +665,14 @@ local function process_function(fn) exit_0: if (ERROR_SET(&err)) { luaL_where(lstate, 1); + if (err_param) { + lua_pushstring(lstate, "param '"); + lua_pushstring(lstate, err_param); + lua_pushstring(lstate, "': "); + } lua_pushstring(lstate, err.msg); api_clear_error(&err); - lua_concat(lstate, 2); + lua_concat(lstate, err_param ? 5 : 2); return lua_error(lstate); } ]] -- cgit From 6fa17da39b270bf230764859a9537124b18d3ed5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 4 Aug 2023 21:26:53 +0100 Subject: docs(options): take ownership of options.txt (#24528) * docs(options): take ownership of options.txt - `src/nvim/options.lua` is now the source of truth - generate runtime/lua/vim/_meta/options.lua * fixup! zeer comments * fixup! zeer comments (2) * fixup! re-enable luacheck * fixup! regen --- src/nvim/generators/gen_options.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 03b1fbec8a..cb6f9b6af9 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -1,6 +1,6 @@ local options_file = arg[1] -local opt_fd = io.open(options_file, 'w') +local opt_fd = assert(io.open(options_file, 'w')) local w = function(s) if s:match('^ %.') then @@ -10,6 +10,7 @@ local w = function(s) end end +--- @module 'nvim.options' local options = require('options') local cstr = options.cstr @@ -38,7 +39,10 @@ local list_flags={ flagscomma='P_COMMA|P_FLAGLIST', } -local get_flags = function(o) +--- @param o vim.option_meta +--- @return string +local function get_flags(o) + --- @type string[] local ret = {type_flags[o.type]} local add_flag = function(f) ret[1] = ret[1] .. '|' .. f @@ -81,8 +85,10 @@ local get_flags = function(o) return ret[1] end -local get_cond -get_cond = function(c, base_string) +--- @param c string|string[] +--- @param base_string? string +--- @return string +local function get_cond(c, base_string) local cond_string = base_string or '#if ' if type(c) == 'table' then cond_string = cond_string .. get_cond(c[1], '') @@ -118,9 +124,12 @@ local get_defaults = function(d,n) return get_value(d) end +--- @type {[1]:string,[2]:string}[] local defines = {} -local dump_option = function(i, o) +--- @param i integer +--- @param o vim.option_meta +local function dump_option(i, o) w(' [' .. ('%u'):format(i - 1) .. ']={') w(' .fullname=' .. cstr(o.full_name)) if o.abbreviation then -- cgit From 7bc93e0e2f246dd78026a3472d929a0fe450f70d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 14:01:19 +0200 Subject: refactor(api): use typed keysets Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata --- src/nvim/generators/gen_api_dispatch.lua | 87 ++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 33 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index fe63cb883e..9c15597fcc 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -67,13 +67,27 @@ local keysets = {} local function add_keyset(val) local keys = {} - for _,field in ipairs(val.fields) do + local types = {} + local is_set_name = 'is_set__' .. val.keyset_name .. '_' + local has_optional = false + for i,field in ipairs(val.fields) do if field.type ~= 'Object' then - error 'not yet implemented: types other than Object' + types[field.name] = field.type + end + if field.name ~= is_set_name and field.type ~= 'OptionalKeys' then + table.insert(keys, field.name) + else + if i > 1 then + error("'is_set__{type}_' must be first if present") + elseif field.name ~= is_set_name then + error(val.keyset_name..": name of first key should be "..is_set_name) + elseif field.type ~= 'OptionalKeys' then + error("'"..is_set_name.."' must have type 'OptionalKeys'") + end + has_optional = true end - table.insert(keys, {field.name, field.type}) end - table.insert(keysets, {val.keyset_name, keys}) + table.insert(keysets, {name=val.keyset_name, keys=keys, types=types, has_optional=has_optional}) end -- read each input file, parse and append to the api metadata @@ -232,53 +246,60 @@ output:write([[ ]]) -for _,keyset in ipairs(keysets) do - local name, keys = unpack(keyset) - local special = {} - local function sanitize(key) - if special[key] then - return key .. "_" - end - return key - end +for _,k in ipairs(keysets) do + local c_name = {} - local key_names = {} - for i = 1,#keys do - local kname = keys[i][1] - if vim.endswith(kname, "_") then - kname = string.sub(kname,1, #kname - 1) - special[kname] = true + for i = 1,#k.keys do + -- some keys, like "register" are c keywords and get + -- escaped with a trailing _ in the struct. + if vim.endswith(k.keys[i], "_") then + local orig = k.keys[i] + k.keys[i] = string.sub(k.keys[i],1, #(k.keys[i]) - 1) + c_name[k.keys[i]] = orig + k.types[k.keys[i]] = k.types[orig] end - key_names[i] = kname end - local neworder, hashfun = hashy.hashy_hash(name, key_names, function (idx) - return name.."_table["..idx.."].str" + + local neworder, hashfun = hashy.hashy_hash(k.name, k.keys, function (idx) + return k.name.."_table["..idx.."].str" end) - keysets_defs:write("extern KeySetLink "..name.."_table[];\n") + keysets_defs:write("extern KeySetLink "..k.name.."_table[];\n") - output:write("KeySetLink "..name.."_table[] = {\n") - for _, key in ipairs(neworder) do - output:write(' {"'..key..'", offsetof(KeyDict_'..name..", "..sanitize(key)..")},\n") + local function typename(type) + if type ~= nil then + return "kObjectType"..type + else + return "kObjectTypeNil" + end + end + + output:write("KeySetLink "..k.name.."_table[] = {\n") + for i, key in ipairs(neworder) do + local ind = -1 + if k.has_optional then + ind = i + keysets_defs:write("#define KEYSET_OPTIDX_"..k.name.."__"..key.." "..ind.."\n") + end + output:write(' {"'..key..'", offsetof(KeyDict_'..k.name..", "..(c_name[key] or key).."), "..typename(k.types[key])..", "..ind.."},\n") end - output:write(' {NULL, 0},\n') + output:write(' {NULL, 0, kObjectTypeNil, -1},\n') output:write("};\n\n") output:write(hashfun) output:write([[ -Object *KeyDict_]]..name..[[_get_field(void *retval, const char *str, size_t len) +KeySetLink *KeyDict_]]..k.name..[[_get_field(const char *str, size_t len) { - int hash = ]]..name..[[_hash(str, len); + int hash = ]]..k.name..[[_hash(str, len); if (hash == -1) { return NULL; } - - return (Object *)((char *)retval + ]]..name..[[_table[hash].ptr_off); + return &]]..k.name..[[_table[hash]; } ]]) - keysets_defs:write("#define api_free_keydict_"..name.."(x) api_free_keydict(x, "..name.."_table)\n") + keysets_defs:write("#define api_free_keydict_"..k.name.."(x) api_free_keydict(x, "..k.name.."_table)\n") end local function real_type(type) @@ -666,7 +687,7 @@ local function process_function(fn) if (ERROR_SET(&err)) { luaL_where(lstate, 1); if (err_param) { - lua_pushstring(lstate, "param '"); + lua_pushstring(lstate, "Invalid '"); lua_pushstring(lstate, err_param); lua_pushstring(lstate, "': "); } -- cgit From 6c0812d92e0c7937b913175b8856064cb45f55c2 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 23:35:34 +0200 Subject: feat(lua): specific error messages for type checking `opts` params --- src/nvim/generators/gen_api_dispatch.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 9c15597fcc..02648e6c99 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -630,7 +630,7 @@ local function process_function(fn) local seterr = '' if string.match(param_type, '^KeyDict_') then write_shifted_output(output, string.format([[ - %s %s = { 0 }; nlua_pop_keydict(lstate, &%s, %s_get_field, %s&err);]], param_type, cparam, cparam, param_type, extra)) + %s %s = { 0 }; nlua_pop_keydict(lstate, &%s, %s_get_field, &err_param, &err);]], param_type, cparam, cparam, param_type)) cparam = '&'..cparam errshift = 1 -- free incomplete dict on error else -- cgit From 64ccfdaafef56b451e3a5eed94367fad93978ec8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 11:22:25 +0800 Subject: vim-patch:8.1.2047: cannot check the current state Problem: Cannot check the current state. Solution: Add the state() function. https://github.com/vim/vim/commit/0e57dd859ecb1e8a3b91509d2f4343e839340eb8 Co-authored-by: Bram Moolenaar --- src/nvim/generators/gen_eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index c7978f0d19..0433894465 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -36,6 +36,7 @@ hashpipe:write([[ #include "nvim/quickfix.h" #include "nvim/runtime.h" #include "nvim/search.h" +#include "nvim/state.h" #include "nvim/strings.h" #include "nvim/sign.h" #include "nvim/testing.h" -- cgit From cc35352f65f823259675f84a915ee03d2423913e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 15:23:32 +0800 Subject: vim-patch:8.1.2062: the mouse code is spread out (#24817) Problem: The mouse code is spread out. Solution: Move all the mouse code to mouse.c. (Yegappan Lakshmanan, closes vim/vim#4959) https://github.com/vim/vim/commit/b20b9e14ddd8db111e886ad0494e15b955159426 Also move getmousepos() there. N/A patches for version.c: vim-patch:8.1.2070: mouse code is spread out Problem: Mouse code is spread out. Solution: Move mouse terminal code parsing to mouse.c. (Yegappan Lakshmanan, closes vim/vim#4966) https://github.com/vim/vim/commit/b8ff5c271ee5dcef6f63436b77e228e062ff9a0e Co-authored-by: Bram Moolenaar --- src/nvim/generators/gen_eval.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index 0433894465..7b272c337e 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -32,6 +32,7 @@ hashpipe:write([[ #include "nvim/match.h" #include "nvim/mbyte.h" #include "nvim/menu.h" +#include "nvim/mouse.h" #include "nvim/move.h" #include "nvim/quickfix.h" #include "nvim/runtime.h" -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/generators/gen_options.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index cb6f9b6af9..6605f936fe 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -188,7 +188,22 @@ local function dump_option(i, o) w(' },') end -w('static vimoption_T options[] = {') +w([[ +#include "nvim/ex_cmds.h" +#include "nvim/ex_getln.h" +#include "nvim/insexpand.h" +#include "nvim/mapping.h" +#include "nvim/ops.h" +#include "nvim/option.h" +#include "nvim/optionstr.h" +#include "nvim/quickfix.h" +#include "nvim/runtime.h" +#include "nvim/spell.h" +#include "nvim/spellfile.h" +#include "nvim/tag.h" +#include "nvim/window.h" + +static vimoption_T options[] = {]]) for i, o in ipairs(options.options) do dump_option(i, o) end -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/generators/gen_options.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 6605f936fe..0932a1357f 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -189,7 +189,6 @@ local function dump_option(i, o) end w([[ -#include "nvim/ex_cmds.h" #include "nvim/ex_getln.h" #include "nvim/insexpand.h" #include "nvim/mapping.h" @@ -198,8 +197,6 @@ w([[ #include "nvim/optionstr.h" #include "nvim/quickfix.h" #include "nvim/runtime.h" -#include "nvim/spell.h" -#include "nvim/spellfile.h" #include "nvim/tag.h" #include "nvim/window.h" -- cgit From f06af5e66981095f3244f67d1587ce7e9853eb4c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 08:13:58 +0800 Subject: vim-patch:9.0.1958: cannot complete option values Problem: cannot complete option values Solution: Add completion functions for several options Add cmdline tab-completion for setting string options Add tab-completion for setting string options on the cmdline using `:set=` (along with `:set+=` and `:set-=`). The existing tab completion for setting options currently only works when nothing is typed yet, and it only fills in with the existing value, e.g. when the user does `:set diffopt=` it will be completed to `set diffopt=internal,filler,closeoff` and nothing else. This isn't too useful as a user usually wants auto-complete to suggest all the possible values, such as 'iblank', or 'algorithm:patience'. For set= and set+=, this adds a new optional callback function for each option that can be invoked when doing completion. This allows for each option to have control over how completion works. For example, in 'diffopt', it will suggest the default enumeration, but if `algorithm:` is selected, it will further suggest different algorithm types like 'meyers' and 'patience'. When using set=, the existing option value will be filled in as the first choice to preserve the existing behavior. When using set+= this won't happen as it doesn't make sense. For flag list options (e.g. 'mouse' and 'guioptions'), completion will take into account existing typed values (and in the case of set+=, the existing option value) to make sure it doesn't suggest duplicates. For set-=, there is a new `ExpandSettingSubtract` function which will handle flag list and comma-separated options smartly, by only suggesting values that currently exist in the option. Note that Vim has some existing code that adds special handling for 'filetype', 'syntax', and misc dir options like 'backupdir'. This change preserves them as they already work, instead of converting to the new callback API for each option. closes: vim/vim#13182 https://github.com/vim/vim/commit/900894b09a95398dfc75599e9f0aa2ea25723384 Co-authored-by: Yee Cheng Chin --- src/nvim/generators/gen_options.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 0932a1357f..05def71caa 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -35,6 +35,8 @@ local redraw_flags={ local list_flags={ comma='P_COMMA', onecomma='P_ONECOMMA', + commacolon='P_COMMA|P_COLON', + onecommacolon='P_ONECOMMA|P_COLON', flags='P_FLAGLIST', flagscomma='P_COMMA|P_FLAGLIST', } @@ -166,6 +168,9 @@ local function dump_option(i, o) if o.cb then w(' .opt_did_set_cb=' .. o.cb) end + if o.expand_cb then + w(' .opt_expand_cb=' .. o.expand_cb) + end if o.enable_if then w('#else') w(' .var=NULL') -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/generators/gen_ex_cmds.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index b9fae7d0fe..61767583ec 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -102,7 +102,7 @@ for _, cmd in ipairs(defs) do end local preview_func if cmd.preview_func then - preview_func = string.format("(ex_preview_func_T)&%s", cmd.preview_func) + preview_func = string.format("&%s", cmd.preview_func) else preview_func = "NULL" end -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/generators/gen_options.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 05def71caa..c9878bf3b0 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -112,7 +112,7 @@ local value_dumpers = { string=cstr, boolean=function(v) return v and 'true' or 'false' end, number=function(v) return ('%iL'):format(v) end, - ['nil']=function(_) return '0L' end, + ['nil']=function(_) return '0' end, } local get_value = function(v) -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/generators/gen_api_dispatch.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 02648e6c99..6cdcf56783 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -550,8 +550,6 @@ end output = io.open(lua_c_bindings_outputf, 'wb') output:write([[ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include #include #include -- cgit From 6343d414369de1f3b259e51438cd4f666d82d3d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 11:17:04 +0800 Subject: refactor: move autocmd types to autocmd_defs.h (#26239) --- src/nvim/generators/gen_events.lua | 5 ++++- src/nvim/generators/gen_ex_cmds.lua | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_events.lua b/src/nvim/generators/gen_events.lua index 0eb231f012..4763a2f463 100644 --- a/src/nvim/generators/gen_events.lua +++ b/src/nvim/generators/gen_events.lua @@ -8,7 +8,10 @@ local aliases = auevents.aliases local enum_tgt = io.open(fileio_enum_file, 'w') local names_tgt = io.open(names_file, 'w') -enum_tgt:write('typedef enum auto_event {') +enum_tgt:write([[ +// IWYU pragma: private, include "nvim/autocmd_defs.h" + +typedef enum auto_event {]]) names_tgt:write([[ static const struct event_name { size_t len; diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua index 61767583ec..ae8c952648 100644 --- a/src/nvim/generators/gen_ex_cmds.lua +++ b/src/nvim/generators/gen_ex_cmds.lua @@ -34,6 +34,8 @@ static const uint8_t cmdidxs2[%u][%u] = { ]], a_to_z, a_to_z) enumfile:write([[ +// IWYU pragma: private, include "nvim/ex_cmds_defs.h" + typedef enum CMD_index { ]]) defsfile:write(string.format([[ -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/generators/gen_declarations.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_declarations.lua b/src/nvim/generators/gen_declarations.lua index 7ed0624b05..f9e9c6b0a8 100644 --- a/src/nvim/generators/gen_declarations.lua +++ b/src/nvim/generators/gen_declarations.lua @@ -171,7 +171,7 @@ static functions into static.h and declarations for non-static functions into non-static.h. File `definitions.i' should contain an already preprocessed version of definitions.c and it is the only one which is actually parsed, definitions.c is needed only to determine functions from which file out of all -functions found in definitions.i are needed. +functions found in definitions.i are needed and to generate an IWYU comment. Additionally uses the following environment variables: @@ -224,6 +224,18 @@ local non_static = header .. [[ local static = header +if fname:find('.*/src/nvim/.*%.c$') then + -- Add an IWYU pragma comment if the corresponding .h file exists. + local header_fname = fname:sub(1, -3) .. '.h' + local header_f = io.open(header_fname, 'r') + if header_f ~= nil then + header_f:close() + non_static = ([[ +// IWYU pragma: private, include "%s" +]]):format(header_fname:gsub('.*/src/nvim/', 'nvim/')) .. non_static + end +end + local filepattern = '^#%a* (%d+) "([^"]-)/?([^"/]+)"' local init = 1 @@ -241,12 +253,7 @@ while init ~= nil do curfile = file is_needed_file = (curfile == neededfile) declline = tonumber(line) - 1 - local curdir_start = dir:find('src/nvim/') - if curdir_start ~= nil then - curdir = dir:sub(curdir_start + #('src/nvim/')) - else - curdir = dir - end + curdir = dir:gsub('.*/src/nvim/', '') else declline = declline - 1 end @@ -308,7 +315,7 @@ F = io.open(static_fname, 'w') F:write(static) F:close() --- Before generating the non-static headers, check if the current file(if +-- Before generating the non-static headers, check if the current file (if -- exists) is different from the new one. If they are the same, we won't touch -- the current version to avoid triggering an unnecessary rebuilds of modules -- that depend on this one -- cgit From 3a3474371b6b87e630e7aa217e7860e9154cd563 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 28 Nov 2023 06:15:26 +0600 Subject: refactor(options): replace `p_force_(on|off)` with `immutable` (#26209) Problem: We use the `p_force_on` and `p_force_off` variables to check if a variable is immutable and what its default value is. This is not only hacky and unintuitive, but also is limited to only boolean options. Solution: Replace `p_force_on` and `p_force_off` with an `immutable` property for options, which indicates if an option is immutable. Immutable options cannot be changed from their default value. Ref: #25672. --- src/nvim/generators/gen_options.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index c9878bf3b0..26ade2745d 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -143,9 +143,13 @@ local function dump_option(i, o) end if o.varname then w(' .var=&' .. o.varname) + -- Immutable options should directly point to the default value + elseif o.immutable then + w((' .var=&options[%u].def_val'):format(i - 1)) elseif #o.scope == 1 and o.scope[1] == 'window' then w(' .var=VAR_WIN') end + w(' .immutable=' .. (o.immutable and 'true' or 'false')) if #o.scope == 1 and o.scope[1] == 'global' then w(' .indir=PV_NONE') else -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/generators/gen_api_dispatch.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/generators') diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 6cdcf56783..9720cca477 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -227,7 +227,7 @@ output:write([[ #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/log.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/api/autocmd.h" -- cgit