Commit Graph

948 Commits

Author SHA1 Message Date
glepnir
450ba41436 fix(api): adjust Visual position after nvim_buf_set_text #30690
Problem:
Visual selection could end up in the wrong place after
nvim_buf_set_text or nvim_buf_set_lines. In some delete cases,
Visual.lnum was already clamped before the line shift happened, so the
adjustment got skipped.

Solution:
Split fix_cursor_cols into reusable fix_pos_col logic and reuse it
for Visual updates. Also adjust Visual.lnum before changed_lines so
the shift uses the original position before final clamping.
2026-05-18 13:08:26 -04:00
bfredl
e932d6ff17 fix(api): regressions with lua return values #39837
fixes #39834
fixes #39833
fixes #39851
2026-05-18 09:05:49 -04:00
Justin M. Keyes
846b8b2420 refactor: group nvim_buf_call, nvim_win_call tests #39828 2026-05-17 11:20:54 -04:00
bfredl
0aa7d2f4d5 feat(api): nvim_buf_call, win_call can has multiple return values #39801
from the "because we can and it is not much code" department. (diffcount
excluding tests is actually negative)

fixes https://github.com/neovim/neovim/issues/39636#issuecomment-4397141270
2026-05-17 10:25:22 -04:00
Justin M. Keyes
e572c9c80a feat(api): tab-local option scope #39811
Problem:
2d795face6 added support for tab-local options ('cmdheight')
to `nvim_get_option_value`, but not to:

    nvim_get_option_info2()
    nvim_set_option_value(…, { tab = … })
    gettabwinvar()

Solution:
- Update `options.lua` to model tab-local options. Introduce `kOptScopeTab`.
- Handle tab scope in the options layer so it works for all options APIs.

Note:
- No change to `gettabvar()`. Not sure if needed/wanted.

fix https://github.com/neovim/neovim/issues/31140
2026-05-17 10:24:46 -04:00
Justin M. Keyes
5ba0d28634 refactor(api): tab-local nvim_get_option_value #39810 2026-05-16 11:37:37 -04:00
EliWiegman
2d795face6 fix(api): nvim_get_option_value tab-local 'cmdheight' #39259
Problem:
API clients cannot query the tab-local value of 'cmdheight'.

Solution:
Allow nvim_get_option_value() to accept { tab = <tab-ID> } for 'cmdheight'.
2026-05-16 09:31:05 -04:00
Lewis Russell
9432e6c1e2 test: run Lua harness with nvim -l
Problem:
The Lua test harness still ran through standalone -ll mode, so tests
depended on the low-level Lua path instead of the regular Nvim Lua
environment. That also meant os.exit() coverage had to carry an ASAN
workaround because Lua's raw process exit skipped Nvim teardown and let
LeakSanitizer interfere with the observed exit code.

Solution:
Run the harness and related fixtures with nvim -l. Patch os.exit() in
the main Lua state to exit through getout(), so scripts observe normal
Nvim shutdown while standalone -ll remains available for generator-style
scripts. As a consequence, the startup test can assert os.exit() without
disabling leak detection.

AI-assisted: Codex
2026-05-13 13:14:07 +01:00
zeertzjq
986382069a refactor: make nvim_put() trigger TextPut* with '_' as regname 2026-05-13 06:57:07 +08:00
luukvbaal
ce9f4f0369 fix(messages): reset redirection message column after :echon #39472
Problem:  Message redirection column for captured output is not reset
          after :echon since (4260f73, e63346df).

Solution: Ensure msg_ext_append is set before the kind with :echon.
2026-05-11 15:47:19 -04:00
Justin M. Keyes
80d83d75eb docs: misc, rename "tabpage"
Co-authored-by: michael-grunder <michael.grunder@gmail.com>
Co-authored-by: Olivia Kinnear <git@superatomic.dev>
Co-authored-by: Felipe Matarazzo <felipemps@protonmail.com>
2026-05-07 10:36:48 +02:00
luukvbaal
dda30fdfbb fix(messages): disallow source="nvim" progress msg #39315
Problem:  Internal progress messages use the "nvim" source (since
          ff68fd6b), plugins shouldn't be allowed to set the progress
          message source to "nvim". The message ID used for internal
          progress messages is not identifiable as such.
Solution: Disallow setting opts->source to "nvim" with nvim_echo().
          Refactor msg_progress() and callees to bypass nvim_echo().
          Prepend message id for internal progress messages with "nvim.".
2026-05-06 12:25:25 -04:00
glepnir
1787965d77 feat(api): nvim_get_commands returns desc #39623
Problem:
Can't get a command's description from nvim_get_commands when
cmd is string.

Solution:
Returns "desc" field in nvim_get_commands.
`definition` is now empty when cmd is function type.
2026-05-06 06:36:39 -04:00
David Balatero
78111e5371 test: flaky terminal channel exitcode check #39580
Problem:
The `nvim_get_chan_info()` terminal channel test used `shell-test INTERACT` to verify that `jobstop()` reports an unhandled `SIGHUP` as exit code `129`.

`INTERACT` reads from stdin with `fgets()`, so closing the PTY could race with `SIGHUP` delivery. If `fgets()` observed EOF first, `shell-test` exited normally with code `0`, causing intermittent failures on slower sanitizer builds.

Solution:
Add a `shell-test HOLD` mode that prints a readiness prompt and then waits without reading stdin. Use it for the `SIGHUP` assertion so PTY EOF cannot make the helper exit normally before the signal path is observed.
2026-05-05 11:45:41 -04:00
tao
7e813c65f7 fix(path): exepath() should respect 'shellslash' #39541
Problem:
`gx` relies on `exepath` to get the fullpath of `cmd.exe`,
and that path must use `\`; otherwise, luv's spawn will fail.

Solution:
Revert `slash_adjust` in `exepath`, so that it still respects 'shellslash'
2026-05-04 12:18:13 -04:00
Justin M. Keyes
7c4845ff46 fix(ui): z=, tselect with async vim.ui.select
Problem:
After 55ceb31,  z= and tselect don't work if `vim.ui.select` is an async
provider (especially terminal buffers).

Solution:
Drop the `vim.wait()` approach, use an async approach.

fix #39506
2026-04-30 19:19:42 +02:00
Barrett Ruth
393f687503 fix(api): leak preview callback LuaRef in nvim_create_user_command #39357
Problem:
Invalid `nvim_create_user_command` calls can leak the
`preview` callback reference after Neovim has taken ownership of it.

1. build with {a,l}san
2. run:
    ```sh
    <path/to/nvim> --headless -u NONE --clean +'lua
    for i = 1, 100 do
      pcall(vim.api.nvim_create_user_command,
        "some very epic stuff" .. i,
        {}, -- NOTE: this is INVALID (not a function or string)
        { preview = function() end })
    end
    vim.cmd("qa!")
    ' +qa
    ```
3. see:
    ```
    100 lua references were leaked!
    ```

Solution:
Clear `preview_luaref` in `err:`.
2026-04-24 14:13:24 -04:00
Barrett Ruth
58aad59e1c fix(api): LuaRef leak in nvim_set_keymap on LHS too long (>=66 bytes) #39351
Problem: `nvim_set_keymap` leaks the `callback` `LuaRef` when the
LHS is too long.

Solution: Make `set_maparg_lhs_rhs` transfer `rhs_lua` to
`MapArguments` up front so the caller always owns the ref.
2026-04-24 14:10:28 -04:00
tao
f130922744 fix(path): normalize path slashes on Windows #37729
Problem:
On Windows, path separators may become inconsistent for various reasons,
which makes normalization quite painful.

Solution:
Normalize paths to `/` at the entry boundaries and always use it
internally, converting back only in rare cases where `\` is really
needed (e.g. cmd.exe/bat scripts?).

This is the first commit in a series of incremental steps.

Note:
* some funcs won't respect shellslash. e.g. `expand/fnamemodify`
* some funcs still respect shellslash, but will be updated in a follow
  PR. e.g. `ex_pwd/f_chdir/f_getcwd`
* uv's built-in funcs always return `\`. e.g. `uv.cwd/uv.exepath`

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2026-04-24 13:20:25 -04:00
Justin M. Keyes
4ceca862fc refactor(test): drop deprecated exc_exec #39242 2026-04-20 14:16:41 -04:00
glepnir
01861c2f95 fix(api): expose fg_indexed/bg_indexed in nvim_get_hl #39210
Problem: fg_indexed/bg_indexed were dropped from nvim_get_hl output due
to a wrong short_keys guard. HL_FG_INDEXED also wasn't cleared in
hl_blend_attrs, and HLATTRS_DICT_SIZE was too small.

Solution: Remove the short_keys guard, clear HL_FG_INDEXED in
hl_blend_attrs, bump HLATTRS_DICT_SIZE to 24, and clarify docs that
these flags mean rgb is an approximation of the cterm palette index.
2026-04-20 05:12:52 -04:00
luukvbaal
fe986e5dd0 feat(options): add 'winpinned' to pin a window #39157
Problem:
- Unable to "pin" a window to prevent closing without specifically
  being targeted.
- :fclose closes hidden windows (even before visible windows).

Solution:
- Add 'winpinned' window-local option. When set, window is skipped by
  :fclose and :only. Pin the ui2 cmdline window (which should always be
  visible), so that it is not closed by :only/fclose.
- Skip over hidden (and pinned) windows with :fclose.

Co-authored-by: glepnir <glephunter@gmail.com>
2026-04-19 20:36:55 -04:00
luukvbaal
68f7acaaae fix(marks): adjust marks when unloading "nofile" buffer #39118
Problem:  Marks are not adjusted unloading a buffer that doesn't exist
          on disk. E.g. extmarks are still valid (and will be beyond the
          end of the buffer if the buffer is reloaded), even though the
          text is lost.
Solution: Adjust marks for a cleared buffer when unloading a buffer that
          doesn't exist on disk.
2026-04-18 06:53:00 -04:00
Evgeni Chasnovski
7219b816ea fix(lsp): limit number of created highlight groups (#39133)
* fix(api): allow silencing "Too many highlight groups" error

Problem: Using Lua's `vim.api.nvim_set_hl(0, 'New', {...})` can fail if
  there are too many existing highlight groups. However, this error can
  not be silenced with `pcall`.

Solution: Make it possible to silence in `nvim_set_hl` and
  `nvim_get_hl_id_by_name`.

* fix(lsp): limit number of groups created by `document_color()`

Problem: A file can contain many string colors that would be highlighted
  by an LSP server. If this number crosses 19999 (maximum number of
  allowed highlight groups), there are general issues with creating
  other highlight groups, which can break functionality outside of
  `vim.lsp.document_color`.

Solution: Limit number of highlight groups that are created by
  `vim.lsp.document_color` to 10000 (half of allowed maximum).
  This is not a 100% solution (since there can exist more than 10000
  other highlight groups), but explicitly checking number of groups is
  slow and 10000 should (hopefully) be enough for most use cases.
2026-04-17 17:16:11 -07:00
zeertzjq
4eaf782bb6 fix(terminal): forward streamed bracketed paste properly (#39152) 2026-04-18 06:33:52 +08:00
Justin M. Keyes
df8d98173c feat(api): rename buffer to buf in retval #38900
In 3a4a66017b, 4d3a67cd62
we renamed "buffer" to "buf" in dict parameters.

This commit also renames such keys in dict return-values.
2026-04-13 12:42:26 -04:00
glepnir
1033739b60 feat(api): nvim_set_hl can set "font" #37668
Problem: Cannot set highlight group fonts via API, only via :highlight
command.

Solution: Add font parameter in nvim_set_hl().
2026-04-12 11:19:40 -04:00
glepnir
49086862fc fix(api): nvim_get_hl drops groups defined with link_global #38492
Problem: hlgroup2dict passes &ns_id to ns_get_hl twice. The first call
(link=true) sets *ns_hl = 0 when link_global is set, so the second call
and the sg_cleared guard both see ns_id == 0 and bail out. The group is
silently dropped from the result.

Solution: use a temporary copy of ns_id for each ns_get_hl call so the
original value is preserved.
2026-04-12 08:38:35 -04:00
glepnir
01567ad4f6 fix(highlight): preserve inherited colors when update=true breaks links #38750
Problem: Breaking a link with update=true loses colors inherited from
the linked group.

Solution: Copy color indices from the linked group so inherited colors
remain visible in :hi output.
2026-04-11 10:14:27 -04:00
Jordan
3a4a66017b feat(api): rename buffer to buf #35330
Problem:
`:help dev-name-common` states that "buf" should be used instead of
"buffer" but there are cases where buffer is mentioned in the lua API.

Solution:
- Rename occurrences of "buffer" to "buf" for consistency with the
  documentation.
- Support (but deprecate) "buffer" for backwards compatibility.

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2026-04-08 20:34:47 -04:00
Sean Dewar
1ff1973269 fix(api)!: nvim_clear_autocmds() "event" handling
Problem: nvim_clear_autocmds() does not type check "event" correctly, and also
treats an empty array "event" like nil.

Solution: fix type checking. Treat empty array "event" as a no-op, like
nvim_exec_autocmds(). Add some extra tests.

Likewise the nil handling change may be considered breaking if anyone
(unintentionally) relied on that. It was also true that integer, function, etc.
"event"s would also be treated like nil!

Note that an empty string "event" is still an error, as that's must be an exact
match on an event name.
2026-04-08 21:48:38 +01:00
Sean Dewar
eaea0c0f9d docs(api): nvim_exec_autocmds() default "pattern"
Problem: nvim_exec_autocmds() documentation incorrectly describes the default
for "pattern" as *, when it's actually the current file name (like :doautocmd).

Solution: correct it. Add a test.
2026-04-08 21:48:38 +01:00
Sean Dewar
446e794a9c fix(api)!: empty non-nil autocmd "pattern" handling
Problem: in autocmd APIs, a non-nil "pattern" containing only empty
'sub'-patterns is silently treated as nil, causing the fallback value to be
unexpectedly used instead.

Solution: for nvim_create_autocmd(), raise a validation error (as no autocmds
would be created). For nvim_{exec,clear}_autocmds(), make it a no-op (as
matching no autocmds is not an error).
2026-04-08 21:48:38 +01:00
zeertzjq
5d66ef188f fix(rpc): trigger UILeave earlier on channel close (#38846)
Problem:
On exit, rpc_free() is called when processing main_loop.events after
libuv calls close callbacks of the channel's stream. However, when there
are no child processes, these libuv callbacks are called in loop_close()
instead of proc_teardown(), and main_loop.events isn't processed after
loop_close(). As a result, calling remote_ui_disconnect() in rpc_free()
causes UILeave to depend on the presence of child processes.

Solution:
Always call remote_ui_disconnect() in rpc_close_event(), and remove the
call in rpc_free().
2026-04-08 05:29:08 +08:00
zeertzjq
f2cdf73afc fix(api): avoid error when parsing invalid expr after :echo (#38695)
Problem:  Parsing :echo followed by invalid expression leads to error.
Solution: Suppress error when skipping over expression.
2026-04-01 23:05:47 +00:00
Justin M. Keyes
64d55b74d8 docs: news #38464 2026-03-28 09:59:54 -04:00
glepnir
9383a096eb fix(api): nvim_set_hl boolean false corrupts underline styles (#38504)
Problem: setting one underline style to false clears bits belonging
to another style. `{underdouble = true, underdashed = false}` results
in undercurl because CHECK_FLAG_WITH_KEY does `m &= ~flag` which
doesn't work for multi-bit encoded values sharing HL_UNDERLINE_MASK.

Solution: use a local variable to derive the correct clear mask from
the flag. Clear the whole HL_UNDERLINE_MASK field instead of individual
bits, and only clear on false when the current style actually matches.
2026-03-28 15:26:46 +08:00
glepnir
4d04d0123d feat(api): nvim_set_hl{update:boolean} #37546
Problem: nvim_set_hl always replaces all attributes.

Solution: Add update field. When true, merge with existing
attributes instead of replacing. Unspecified attributes are preserved.
If highlight group doesn't exist, falls back to reset mode.
2026-03-25 06:01:50 -04:00
zeertzjq
875958c9a1 fix(terminal): don't refresh for sync flush when exiting (#38363)
Fixes the following error log:

    ERR 2026-03-18T20:17:36.920 T281.9357.0 buf_updates_send_changes:258: Disabling buffer updates for dead channel 1
2026-03-19 02:53:52 +00:00
Justin M. Keyes
1b2b715389 fix(messages): disallow user-defined integer message-id #38359
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-18 21:07:17 -04:00
Sean Dewar
6f12663de5 fix(api): nvim_get_option_value FileType autocmd handling #37414
Problem:
nvim_get_option_value with "filetype" set silently returns incorrect
defaults if autocommands are blocked, like when they're already running.

Solution:
Allow its FileType autocommands to nest: `do_filetype_autocmd(force=true)`.
Also error if executing them fails, rather than silently return wrong defaults.

Endless nesting from misbehaving scripts should be prevented by the recursion
limit in apply_autocmds_group, which is 10.
2026-03-18 20:11:59 -04:00
Justin M. Keyes
02ce446510 docs: api, lsp, messages, intro #38327 2026-03-17 17:02:15 -04:00
Justin M. Keyes
680d25e5b3 fix(api): use standard error messages 2026-03-16 14:52:04 +01:00
Sean Dewar
97b064c9ac fix(api): nvim_open_tabpage positional "enter"
Problem: nvim_open_tabpage's "enter" argument is optional, which is inconsistent
with nvim_open_win.

Solution: make it a (non-optional) positional argument, like nvim_open_win.

Also change "enter"'s description to be more like nvim_open_win's doc.
2026-03-16 13:20:45 +00:00
Sean Dewar
0c1ed63c05 fix(api): nvim_open_tabpage "after" like :[count]tab
Problem: "after" in nvim_open_tabpage is inconsistent with how a count works
with :tab, :tabnew, etc. Plus, the name "after" implies it's inserted after that
number.

Solution: internally offset by 1. Allow negative numbers to mean after current.

Hmm, should we even reserve sentinels for after current? Callers can probably
just use nil...
2026-03-16 13:05:47 +00:00
Sean Dewar
cd4c98fded fix: nvim_open_tabpage cleanup, fixes, more tests
- Cleanup, remove redundant comments, add more tests.
- Enhance win_new_tabpage rather than create a new function for !enter, and use
  a different approach that minimizes side-effects. Return the tabpage_T * and
  first win_T * it allocated.
- Disallow during textlock, like other APIs that open windows.
- Remove existing win_alloc_firstwin error handling from win_new_tabpage; it's
  not needed, and looks incorrect. (enter_tabpage is called for curtab, which is
  not the old tabpage! Plus newtp is not freed)
- Fix checks after creating the tabpage:
  - Don't fail if buf wasn't set successfully; the tab page may still be valid
    regardless. Set buffer like nvim_open_win, possibly blocking Enter/Leave
    events. (except BufWinEnter)
  - tp_curwin may not be the initial window opened by win_new_tabpage. Use the
    win_T * it returns instead, which is the real first window it allocated,
    regardless of autocmd shenanigans.
  - Properly check whether tab page was freed; it may have also been freed
    before win_set_buf. Plus, it may not be safe to read its handle!
2026-03-16 13:05:47 +00:00
Will Hopkins
e80d19142b feat(api): add nvim_open_tabpage
Problem: no API function for opening a new tab page and returning its handle, or
to open without entering.

Solution: add nvim_open_tabpage.
2026-03-16 13:05:46 +00:00
Sean Dewar
3115e3d0d1 fix(api): improve external window validation
Problem: "win" is allowed in external window configs in some cases. External
window converted to normal float can't move tabpages in one nvim_win_set_config
call. External window can't be turned into a normal split.

Solution: disallow setting "win" for external windows. Allow external window to
move tabpages, which turns it non-external. Allow external window to be turned
into a (non-external) split.

parse_win_config has more validation issues from not considering the window's
existing config enough (not from this PR). For example, zindex can be set for an
existing split if "split"/"vertical" isn't given, despite intending for that to
be an error. Plus the logic is confusing.

It could do with a refactor at some point...
2026-03-14 20:48:32 +00:00
Sean Dewar
853eea859f fix(api): disallow moving window between tabpages in more cases
Problem: more cases where it may not be safe to move a window between tabpages.

Solution: check them.

Rather speculative... I haven't spend much time looking, but I didn't find
existing code that sets these locks to skip checking win_valid. (what I did find
called it anyway, like in win_close) Still, I think it's a good precaution for
what future code might do.

If the fact that nvim_win_set_config *actually* moves windows between tabpages
causes unforeseen issues, "faking" it like ":wincmd T" may be an alternative:
split a new window, close the old one, but instead also block autocmds, copy the
old window's config, and give it its handle?
2026-03-14 20:48:32 +00:00
Sean Dewar
094b297a3b feat(api): nvim_win_set_config can move split to other tp as floatwin
Problem: not possible for nvim_win_set_config to convert a split to a floatwin,
then move it to another tabpage in one call.

Solution: allow it.
2026-03-14 20:48:32 +00:00