summaryrefslogtreecommitdiffstatshomepage
path: root/src/nvim/lua/executor.c
AgeCommit message (Collapse)AuthorFiles
2026-04-23fix(lua): don't strip debuginfo in precompile module #39191phanium1
Problem: debug.getinfo on bytecode module/func don't give you detail source info. Solution: - Use `loadstring`+`string.dump` to replace LUAC_PRG(`luac`/`luajit -b`) - `string.dump(…,false)` to generate non-strip version bytecode - `loadstring(…,fname)` to specify the full source name BEFORE: $ nvim --clean +'=debug.getinfo(vim.fn.maparg("]<Space>", "n", 0, 1).callback, "Sl")' --headless +q { currentline = -1, lastlinedefined = 456, linedefined = 452, short_src = "?", source = "=?", what = "Lua" } AFTER: $ nvim --clean +'=debug.getinfo(vim.fn.maparg("]<Space>", "n", 0, 1).callback, "Sl")' --headless +q { currentline = -1, lastlinedefined = 456, linedefined = 452, short_src = "/home/xx/b/neovim/runtime/lua/vim/_core/defaults.lua", source = "@/home/xx/b/neovim/runtime/lua/vim/_core/defaults.lua", what = "Lua" }
2026-04-22feat(eval): treat Lua string as "blob" in writefile() #39098Barrett Ruth1
Problem: vim.fn.writefile() treats Lua strings as Vimscript strings instead of a "binary clean" string. Solution: Treat Lua-originated strings as blob data.
2026-04-20fix(excmd): nlua_call_excmd require() failure is a "lua_error"Justin M. Keyes1
Although `nlua_call_excmd` is semantically for implementing Ex-commands, the `require()` should never fail, so that's a "Lua error". But if the call itself fails (the later `semsg` call), that's an "Ex cmd" error.
2026-04-20refactor(excmd): migrate ex_terminal to LuaJustin M. Keyes1
2026-04-20refactor(excmd): migrate ex_checkhealth to LuaJustin M. Keyes1
2026-04-18feat(vimfn): use Lua for more excmds/vimfnsJustin M. Keyes1
Problem: Too much boilerplate needed to use Lua to impl an excmd or f_xx function. Solution: - Add `nlua_call_vimfn` which takes the args typval, executes Lua, and returns a typval. - refactor(excmd): lua impl for :log, :lsp
2026-04-17perf(vim.fn): call Lua-implemented vim.fn.xx() directly #39166Justin M. Keyes1
Problem: - Builtin "Vimscript" functions (f_xx) are mostly implemented in C. Partly that's because there is some boilerplate required to call out to Lua. - Calls to `vim.fn.foo()` always marshall over the Lua <=> Vimscript ("typval") bridge, even if `fn.foo()` is implemented entirely in Lua: ``` Lua => typval => Object => Lua => Object => typval => Lua. ``` Solution: Functions declared in eval.lua with `func_lua` are implemented in entirely in Lua (`_core/vimfn.lua`). - `gen_eval.lua` wires `func_lua` entries to `lua_wrapper`, which handles the typval conversion for Vimscript callers (slow path). - `nlua_call()` detects `func_lua` functions and calls the Lua implementation directly. This eliminates all conversion overhead for Lua callers (fast path). - Validate at build-time that `func`, `func_float`, and `func_lua` are mutually exclusive. - Migrate `hostname()` as a toy example, to show the idea.
2026-03-28docs: news #38464Justin M. Keyes1
2026-03-18fix(messages): disallow user-defined integer message-id #38359Justin M. Keyes1
Problem: `nvim_echo(…, {id=…})` accepts user-defined id as a string or integer. Generated ids are always higher than last highest msg-id used. Thus plugins may accidentally advance the integer id "address space", which, at minimum, could lead to confusion when troubleshooting, or in the worst case, could overflow or "exhaust" the id address space. There's no use-case for it, and it could be the mildly confusing, so we should just disallow it. Solution: Disallow *integer* user-defined message-id. Only allow *string* user-defined message-id.
2026-03-11docs: api, messages, lsp, trustJustin M. Keyes1
gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
2026-03-06fix(cmdline): cmdline_block events for :lua debug.debug() #38171luukvbaal1
Problem: :lua debug.debug() is missing cmdline_block events. Solution: Emit cmdline_block_show/append/hide events for :lua debug.debug().
2026-02-13fix: wait() checks condition twice on each interval (#37837)zeertzjq1
Problem: wait() checks condition twice on each interval. Solution: Don't schedule the due callback. Also fix memory leak when Nvim exits while waiting. No test that the condition isn't checked twice, as testing for that can be flaky when there are libuv events from other sources.
2026-02-01fix(lua): close vim.defer_fn() timer if vim.schedule() failed (#37647)zeertzjq1
Problem: Using vim.defer_fn() just before Nvim exit leaks luv handles. Solution: Make vim.schedule() return an error message if scheduling failed. Make vim.defer_fn() close timer if vim.schedule() failed.
2026-01-27fix(ui): textlock still causes issues for UI callbacks #37513luukvbaal1
Problem: There are still ways to run into textlock errors with vim.ui_attach callbacks trying to display a UI event. Solution: Disregard textlock again during vim.ui_attach() callbacks (also when scheduled). Partially revert 3277dc3b; avoiding to flush while textlock is set is still helpful.
2026-01-21fix(lua): correct line number reporting for options set in coroutines (#37463)Tommy Guo1
2025-12-30build: ship "_core/*" as bytecode (built-into Nvim binary)Justin M. Keyes1
Problem: We want to encourage implementing core features in Lua instead of C, but it's clumsy because: - Core Lua code (built into `nvim` so it is available even if VIMRUNTIME is missing/invalid) requires manually updating CMakeLists.txt, or stuffing it into `_editor.lua`. - Core Lua modules are not organized similar to C modules, `_editor.lua` is getting too big. Solution: - Introduce `_core/` where core Lua code can live. All Lua modules added there will automatically be included as bytecode in the `nvim` binary. - Move these core modules into `_core/*`: ``` _defaults.lua _editor.lua _options.lua _system.lua shared.lua ``` TODO: - Move `_extui/ => _core/ui2/`
2025-12-10fix(lua): relax `vim.wait()` timeout validation #36900skewb1k1
Problem: After bc0635a9fc9c15a2423d4eb35f627d127d00fa46 `vim.wait()` rejects floats and NaN values. Solution: Restore the prior behavior, while still supporting `math.huge`. Update tests to cover float case.
2025-12-09fix(lua): vim.wait(math.huge) fails #36885skewb1k1
Problem: `nlua_wait()` uses `luaL_checkinteger()` which doesn't support `math.huge` since it's double type. On PUC Lua this fails with 'number has no integer representation' error and on LuaJIT this overflows int. Solution: Use `luaL_checknumber()` and handle `math.huge`.
2025-10-21feat(vimscript): log function name in "fast" message #32616Matthieu Coudron1
2025-09-23fix(lua): coverity "unreachable" warning #35874Justin M. Keyes1
Problem: CID 584865: Control flow issues (UNREACHABLE) /src/nvim/lua/executor.c: 550 in nlua_wait() >>> CID 584865: Control flow issues (UNREACHABLE) >>> This code cannot be reached: "abort();". 550 abort(); 551 } Solution: The abort() was intended to encourage explicit handling of all cases, to avoid fallthrough to a possible `return x` added at the end. However, this is unlikely so just drop it.
2025-09-10refactor(lua): fix coverity warning from #35536 (#35703)zeertzjq1
2025-09-09perf(highlight): allow decoration providers to skip ranges without databfredl1
Continuing the work of #31400 That PR allowed the provider to be invoked multiple times per line. We want only to do that when there actually is more data later on the line. Additionally, we want to skip over lines which contain no new highlight items. The TS query cursor already tells us what the next position with more data is, so there is no need to reinvoke the range callback before that. NB: this removes the double buffering introduced in #32619 which is funtamentally incompatible with this (nvim core is supposed to keep track of long ranges by itself, without requiring a callback reinvoke blitz). Need to adjust the priorities some other way to fix the same issue.
2025-09-01feat(progress): better default format + history sync #35533Shadman1
Problem: The default progress message doesn't account for message-status. Also, the title and percent sections don't get written to history. And progress percent is hard to find with variable length messages. Solution: Apply highlighting on Title based on status. And sync the formated msg in history too. Also updates the default progress message format to {title}: {percent}% msg
2025-09-01feat(lua): vim.wait() returns callback results #35588Justin M. Keyes1
Problem: The callback passed to `vim.wait` cannot return results directly, it must set upvalues or globals. local rv1, rv2, rv3 local ok = vim.wait(200, function() rv1, rv2, rv3 = 'a', 42, { ok = { 'yes' } } return true end) Solution: Let the callback return values after the first "status" result. local ok, rv1, rv2, rv3 = vim.wait(200, function() return true, 'a', 42, { ok = { 'yes' } } end)
2025-08-31fix(lua): report error in Lua Funcref callback properly (#35555)zeertzjq1
2025-08-27refactor: rename ga_concat_strings_sep() to ga_concat_strings() (#35498)zeertzjq1
This adds a missing change from Vim patch 7.4.279. N/A patch: vim-patch:9.1.1691: over-allocation in ga_concat_strings()
2025-08-26feat(api): nvim_echo can emit Progress messages/events #34846Shadman1
Problem: Nvim does not have a core concept for indicating "progress" of long-running tasks. The LspProgress event is specific to LSP. Solution: - `nvim_echo` can emit `kind="progress"` messages. - Emits a `Progress` event. - Includes new fields (id, status, percent) in the `msg_show` ui-event. - The UI is expected to overwrite any message having the same id. - Messages have a globally unique ID. - `nvim_echo` returns the message ID. - `nvim_echo(… {id=…})` updates existing messages. Example: local grp = vim.api.nvim_create_augroup("Msg", {clear = true}) vim.api.nvim_create_autocmd('Progress', { pattern={"term"}, group = grp, callback = function(ev) print(string.format('event fired: %s', vim.inspect(ev))..'\n') end }) -- require('vim._extui').enable({enable=true, msg={target='msg', timeout=1000}}) vim.api.nvim_echo({{'searching'}}, true, {kind='progress', percent=80, status='running', title="terminal(ripgrep)"}) local id = vim.api.nvim_echo({{'searching'}}, true, {kind='progress', status='running', percent=10, title="terminal(ripgrep)"}) vim.api.nvim_echo({}, true, {id = id, kind='progress', percent=20, status = 'running', title='find tests'}) vim.api.nvim_echo({}, true, {id = id, kind='progress', status='running', percent=70}) vim.api.nvim_echo({{'complete'}}, true, {id = id, kind='progress', status='success', percent=100, title="find tests"}) Followups: - Integrate with 'statusline' by listening to the Progress autocmd event. - Integrate progress ui-event with `vim._extui`.
2025-08-14refactor(build): remove INCLUDE_GENERATED_DECLARATIONS guardsbfredl1
These are not needed after #35129 but making uncrustify still play nice with them was a bit tricky. Unfortunately `uncrustify --update-config-with-doc` breaks strings with backslashes. This issue has been reported upstream, and in the meanwhile auto-update on every single run has been disabled.
2025-06-29fix(exrc): exrc knows its own location (#34638)Yochem van Rosmalen1
fix(exrc): lua exrc files know their location Problem: 'exrc' files are inherently bound to their location / workspace and therefore require to "know" their location on the filesystem. However, currently using `debug.getinfo(1, 'S')` returns `"<nvim>"`. Solution: Include the filepath as chunkname in `loadstring()` and `nlua_exec()`.
2025-06-01fix(api): add missing nargs field to user command Lua callbacks #34210glepnir1
Problem: nvim_create_user_command() Lua callbacks were missing the documented nargs field in the options table passed to the callback function. Solution: Add nargs field derivation from command argument type flags in nlua_do_ucmd(), using the same logic as nvim_parse_cmd().
2025-05-13refactor(treesitter): move functions from executor.c to treesitter.cLewis Russell1
2025-05-04feat(messages): cleanup Lua error messagesJustin M. Keyes1
"Error" in error messages is redundant. Just provide the context, don't say "Error ...".
2025-04-21fix(coverity/530026,530028): free resources on early exit in nlua_exec_file ↵Nathaniel Poppe1
#33502 Problem: The stdin reading path does not close `stdin_dup` or free `sb` upon early exit. Solution: Free the resources before returning false.
2025-04-21feat(ui): avoid setting 'cmdheight' with vim.ui_attach()Luuk van Baal1
Problem: We allow setting 'cmdheight' to 0 with ext_messages enabled since b72931e7. Enabling ext_messages with vim.ui_attach() implicitly sets 'cmdheight' to 0 for BWC. When non-zero 'cmdheight' is wanted, this behavior make it unnecessarily hard to keep track of the user configured value. Solution: Add set_cmdheight to vim.ui_attach() opts table that can be set to false to avoid setting 'cmdheight' to 0.
2025-04-16fix(env.c): drop envmap, free os_getenv() result #32683Judit Novak1
Problem: vim.uv.os_setenv gets "stuck" per-key. #32550 Caused by the internal `envmap` cache. #7920 :echo $FOO <-- prints nothing :lua vim.uv.os_setenv("FOO", "bar") :echo $FOO <-- prints bar (as expected) :lua vim.uv.os_setenv("FOO", "fizz") :echo $FOO <-- prints bar, still (not expected. Should be "fizz") :lua vim.uv.os_unsetenv("FOO") :echo $FOO <-- prints bar, still (not expected. Should be nothing) :lua vim.uv.os_setenv("FOO", "buzz") :echo $FOO <-- prints bar, still (not expected. Should be "buzz") Solution: - Remove the `envmap` cache. - Callers to `os_getenv` must free the result. - Update all call-sites. - Introduce `os_getenv_noalloc`. - Extend `os_env_exists()` the `nonempty` parameter.
2025-03-19fix(messages): incorrect error message splitting and kind #32990luukvbaal1
Problem: Message kind logic for emitting an error message is convoluted and still results in emitting an unfinished message earlier than wanted. Solution: Ensure emsg_multiline() always sets the kind wanted by the caller and doesn't isn't unset to logic for emitting the source message. Caller is responsible for making sure multiple message chunks are not emitted as multiple events by setting `msg_ext_skip_flush`...
2025-03-07docs: OSC 133 shell config #32771Justin M. Keyes1
2025-03-07fix(lua): always use vim.inspect() for :lua= (#32715)zeertzjq1
2025-03-05fix(lua): format errors from luv callbacks using __tostringbfredl1
2025-02-28vim-patch:8.2.4603: sourcing buffer lines is too complicatedzeertzjq1
Problem: Sourcing buffer lines is too complicated. Solution: Simplify the code. Make it possible to source Vim9 script lines. (Yegappan Lakshmanan, closes vim/vim#9974) https://github.com/vim/vim/commit/85b43c6cb7d56919e245622f4e42db6d8bee4194 This commit changes the behavior of sourcing buffer lines to always have a script ID, although sourcing the same buffer always produces the same script ID. vim-patch:9.1.0372: Calling CLEAR_FIELD() on the same struct twice Problem: Calling CLEAR_FIELD() on the same struct twice. Solution: Remove the second CLEAR_FIELD(). Move the assignment of cookie.sourceing_lnum (zeertzjq). closes: vim/vim#14627 https://github.com/vim/vim/commit/f68517c1671dfedcc1555da50bc0b3de6d2842f6 Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2025-02-27fix(lua): wrong script context for option set by func from nvim_exec2 (#32659)zeertzjq1
Problem: Wrong script context for option set by function defined by nvim_exec2 in a Lua script. Solution: Call nlua_set_sctx() after adding SOURCING_LNUM and always set sc_lnum for a Lua script. This is a bug discovered when testing #28486. Not sure if this actually happens in practice, but it's easy to fix and required for #28486.
2025-02-25fix(lua): don't override script ID from :source (#32626)zeertzjq1
Problem: When setting an option, mapping etc. from Lua without -V1, the script ID is set to SID_LUA even if there already is a script ID assigned by :source. Solution: Don't set script ID to SID_LUA if it is already a Lua script. Also add _editor.lua to ignorelist to make script context more useful when using vim.cmd().
2025-02-24fix(lua): SIGSEGV in luv callback with error(nil) #32595phanium1
Problem: luv callback `vim.uv.new_timer():start(0, 0, function() error() end)` causes SIGSEGV, since `xstrdup` gets NULL from `lua_tostring`. Similar to: https://github.com/neovim/neovim/commit/a5b1b83a2693ffa7a5a0a22b3693d36ea60051be Solution: Check NULL before `xstrdup`.
2025-01-24fix(lua): pop retval for fast context LuaRefLuuk van Baal1
Problem: nlua_call_ref_ctx() does not pop the return value in fast context that did not error. Solution: Fall through to end; calling nlua_call_pop_retval().
2025-01-18fix(lua): prevent SIGSEGV when lua error is NULL in libuv_worker林玮 (Jade Lin)1
Problem: Calling `xstrdup` with a NULL pointer causes a SIGSEGV if `lua_tostring` returns NULL in `nlua_luv_thread_common_cfpcall`. Crash stack trace: - `_platform_strlen` → `xstrdup` (memory.c:469) - `nlua_luv_thread_common_cfpcall` (executor.c:281) Solution: Check if `lua_tostring` returns NULL and pass NULL to `event_create` to avoid the crash.
2025-01-09feat(api): add err field to nvim_echo() optsLuuk van Baal1
Problem: We want to deprecate `nvim_err_write(ln)()` but there is no obvious replacement (from Lua). Meanwhile we already have `nvim_echo()` with an `opts` argument. Solution: Add `err` argument to `nvim_echo()` that directly maps to `:echoerr`.
2024-12-23refactor: iwyu #31637Justin M. Keyes1
Result of `make iwyu` (after some "fixups").
2024-11-17fix(messages): proper multiline Lua print() messages #31205luukvbaal1
Problem: Separate message emitted for each newline present in Lua print() arguments. Solution: Make msg_multiline() handle NUL bytes. Refactor print() to use msg_multiline(). Refactor vim.print() to use print().
2024-11-14fix(messages)!: vim.ui_attach message callbacks are unsafeLuuk van Baal1
Problem: Lua callbacks for "msg_show" events with vim.ui_attach() are executed when it is not safe. Solution: Disallow non-fast API calls for "msg_show" event callbacks. Automatically detach callback after excessive errors. Make sure fast APIs do not modify Nvim state.
2024-11-02fix(lua): show stacktrace for error in vim.on_key() callback (#31021)zeertzjq1