Commit Graph

37276 Commits

Author SHA1 Message Date
Barrett Ruth
25439dad7e feat(api): relax contract, opts + rest params are optional #40581
Problem:
|api-contract| allows adding an optional trailing `opts` parameter, but
the dispatch generator still requires every parameter, so `opts` cannot
be omitted.

Solution:
Treat a trailing `Dict(...) *opts` parameter as optional in the generated
RPC and Lua dispatch wrappers.

Co-authored-by: Judit Novak <judit.novak@gmail.com>
2026-07-13 10:28:24 -04:00
Dmytro Meleshko
e18820007f ci: avoid running Coverity in forks #40718
Problem:
If you have this repo forked, the workflow for Coverity Scan creates a lot of
spammy emails about that workflow failing.

Solution:
Check for the presence of `COVERITY_SCAN_TOKEN` and `COVERITY_SCAN_EMAIL` at the
very start of `.github/workflows/coverity.yml`, skip the rest of the workflow if
they are absent. Unfortunately, Github Actions don't offer a straightforward way
of doing that, so using [this workaround](https://github.com/orgs/community/discussions/25280)).
2026-07-13 09:59:31 -04:00
Barrett Ruth
1665b992b7 fix(filetype): trigger FileType after BufReadCmd #40679
Problem:
A successful `BufReadCmd` can leave an existing `filetype` without
rerunning its `FileType` setup, so state cleared during reload may not
be restored.

This also causes `:edit`/reload syntax `directoryDirectory` groups to
not be reapplied.

Solution:
After `BufReadCmd` handles a read, trigger `FileType` for the existing
`filetype` if no `FileType` event fired during the read.
2026-07-13 09:08:09 -04:00
Justin M. Keyes
6ea01d37f8 refactor(core): group insert-mode globals in InsState #40712
Problem:
Insert-mode globals are scattered.

Solution:
Group them into one struct. Besides improving readability and
discoverability, this greatly helps with save/restore of an insert-mode
session.
2026-07-13 09:06:04 -04:00
Justin M. Keyes
07144616ca Merge #40713 from justinmk/fixbuild 2026-07-13 08:44:07 -04:00
Justin M. Keyes
e1c1bd3722 fix(coverity): RESOURCE_LEAK, USE_AFTER_FREE
/src/nvim/ex_docmd.c: 5033             in ex_restart()
    5027         // The address after --listen may be in use by the current server.
    5028         if (i > 0 && strequal(arg, "--listen")) {
    5029           const listitem_T *next_li = li->li_next;
    5030           if (next_li != NULL) {
    5031             const char *addr = tv_get_string(TV_LIST_ITEM_TV(next_li));
    5032             if (strstr(addr, ":") || strstr(addr, "/") || strstr(addr, "\\")) {
    >>>     CID 649201:         Resource leaks  (RESOURCE_LEAK)
    >>>     Overwriting "listen_arg" in "listen_arg = xstrdup(addr)" leaks the storage that "listen_arg" points to.
    5033               listen_arg = TO_SLASH_SAVE(addr);
    5034     #ifdef MSWIN
    5035               // On Windows, don't pass --listen to new server (named pipe can't be reused immediately).
    5036               // Instead pass the address via RPC; new server rebinds after startup.
    5037               li = next_li;
    5038               continue;

    *** CID 649200:         Memory - illegal accesses  (USE_AFTER_FREE)
    /src/nvim/eval/fs.c: 228             in modify_fname()
    222
    223       // ":h" - head, remove "/file_name", can be repeated
    224       // Don't remove the logical root, see `FileInfo`.
    225       while (src[*usedlen] == ':' && src[*usedlen + 1] == 'h') {
    226         valid |= VALID_HEAD;
    227         *usedlen += 2;
    >>>     CID 649200:         Memory - illegal accesses  (USE_AFTER_FREE)
    >>>     Using freed pointer "s".
    228         while (tail > s && after_pathsep(s, tail)) {
    229           MB_PTR_BACK(*fnamep, tail);
    230         }
    231         *fnamelen = tail <= s ? (size_t)(s - *fnamep) : (size_t)(tail - *fnamep);
    232         if (*fnamelen == 0) {
    233           // Result is empty.  Turn it into "." to make ":cd %:h" work.
2026-07-13 05:48:05 +02:00
Justin M. Keyes
3a7989f4f4 docs(shada): outdated docstrings #40711 2026-07-12 22:42:47 -04:00
tao
4a08596314 fix(path): normalize separators (slashes) #39155
Problem:
Continue separators normalization, and try to keep it at the
nvim <-> external boundary, e.g., `fn.xxx`, `api.xxx`, `:xxx`

Solution:
some key changes
- normalize `$HOME-windows`
- normalize entry points of changing directory
  - `nvim_set_current_dir()`, `chdir()`
- normalize the named pipe
  - `--listen` arg, `--server` arg, `:restart`
  - `serverstart()`, `sockconnect()`, `serverstop()`
- make `expand()` respect 'shellslash' again
- clean up `did_set_shellslash`
- replace `forward_slash` with `TO_SLASH`
- remove obsolete `TMP_PATHSEPSTR`
- remove `slash_adjust` in `do_autocmd_dirchanged`?
- make `fnamemodify()` always return `/` (except when substituting
  separators via `:s`, `:gs` ?)

Note:
- these funcs still apply `slash_adjust` on return, as before:
  `:pwd`, `chdir()`, `exepath()`, `getcwd()`
- these funcs alwarys return `/`, unlike before the normalization PRs
  - `getcompletion()`, `finddir()`, `findfile()`

Also
- clean up code, comments, formatting and tests
- move `TO_SLASH` from `f_chdir` to `changedir_func`
- move `TO_SLASH` from `f_bufadd` to `buflist_new`

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2026-07-12 13:23:44 -04:00
Kim A. Brandt
543a96e491 fix(lsp): unclear error on malformed server responses #40422
Problem:
Malformed server responses with `null` (vim.NIL) values, do not show
clear error messages.


Solution:
Assert two known, specific cases, to avoid user confusion.
2026-07-12 12:52:10 -04:00
glepnir
58b6310adc fix(startup): respect enter for windows created in startup scripts #37287
Problem: When a split window is created from the init script using nvim_open_win()
with enter=false, the current window focus is not preserved. The cursor
incorrectly moves into the newly created split during startup.

Solution: Save curwin before the iteration loop in create_windows(), and
restore it after the loop. also update edit_buffers() to use curwin instead
of firstwin.
2026-07-12 12:30:40 -04:00
Justin M. Keyes
17f13ab338 Merge #40473 from janlazo/vimpatch_na_cfuncs
build(vim-patch): detect N/A C files based on diff
2026-07-12 12:13:20 -04:00
Justin M. Keyes
81c4c295ac refactor(insert): rename edit.c => insert.c #40705
Problem:
- `edit.c` is an unnecessarily misleading and less-discoverable name
  than `insert.c`.
- Numerous insert-mode related things are named with a `ins_` prefix.
- There is already a `insexpand.c` module...

Solution:
Rename `edit.c` => `insert.c`.
2026-07-12 11:57:17 -04:00
bfredl
c1e09659b4 Merge pull request #40628 from Rawan10101/wasm-runtime-bundling
build(wasm): bundle runtime files into MEMFS
2026-07-12 17:53:45 +02:00
Justin M. Keyes
ac66c9de03 Merge #40703 from justinmk/fixci 2026-07-12 09:30:57 -04:00
Justin M. Keyes
88b627d72d test(autoread): unreliable "coalesces rapid changes via debouncing"
previous: #40272

    FAILED   …/autoread_spec.lua @ 142: autoread file watcher coalesces rapid changes via debouncing
    Expected values to be equal.
    Expected:
    1
    Actual:
    2
    stack traceback:
    …/autoread_spec.lua:169: in function <…/autoread_spec.lua:142>
2026-07-12 15:15:46 +02:00
Justin M. Keyes
83ced05984 fix(ctx): coverity CHECKED_RETURN
CID 649145:         Error handling issues  CHECKED_RETURN
    /src/nvim/api/window.c: 138             in nvim_win_set_cursor()
    132       // Make sure we stick in this column.
    133       w->w_set_curswant = true;
    134
    135       // make sure cursor is in visible range and
    136       // cursorcolumn and cursorline are updated even if w != curwin
    137       CtxSwitch switchwin;
    >>>     CID 649145:         Error handling issues  (CHECKED_RETURN)
    >>>     Calling "ctx_switch" without checking return value (as is done elsewhere 5 out of 6 times).
    138       ctx_switch(&switchwin, w, NULL, NULL, kCtxNoEvents | kCtxNoDisplay);
    139       update_topline(curwin);
    140       validate_cursor(curwin);
    141       ctx_restore(&switchwin);
    142
    143       redraw_later(w, UPD_VALID);
2026-07-12 15:15:46 +02:00
Justin M. Keyes
d25ae8b8c2 refactor(input): rename getchar.c => input.c #40698
Problem:
`getchar.c` is a quirky name and doesn't align with our existing
`os/input.c` and `tui/input.c` modules, which encompass the same topic
at different layers.

Solution:
Rename `getchar.c` => `input.c` for discoverability.

Introduce `dialog.c` for functionality related to showing confirm
prompts, dialogs, etc.
2026-07-12 08:34:13 -04:00
rawan10101
fde6f72f74 build(wasm): bundle runtime files into MEMFS 2026-07-12 14:51:41 +03:00
Christian Clason
1227148ac3 build(deps): bump tree-sitter to d11d18f74 2026-07-12 12:13:02 +02:00
Barrett Ruth
41294e4253 docs(dir): remove augroup deletion note #40696 2026-07-11 18:20:27 -04:00
Barrett Ruth
67af4141c8 fix(filetype): false positive when matching directory buffer #40695
Problem:
URI buffer names can end with a slash, but slash-ended directory
matching should not preempt URI filetype patterns.

Solution:
Do not use the slash shortcut for names with URI schemes, so those
continue through normal filetype matching.

Co-authored-by: Adam Karafyllidis <akisarou90@gmail.com>
2026-07-11 18:19:44 -04:00
Justin M. Keyes
4349c386db refactor(ctx): drop switch_win/restore_win #40693 2026-07-11 13:29:59 -04:00
Sébastien Hoffmann
5e5cd87aa6 fix(ui2): remove obsolete usages of sc_col
Like `v:echospace`, `sc_col` was used in many places to avoid disruptive
"Press ENTER" prompts. Since those are no longer a problem with ui2, the
complexity of keeping these variables up-to-date and maintaining bespoke
truncation code at the message producers is no longer justified.

Unfortunately, some messages still need to be kept under 1 line to avoid
glitches.

`ru_wid`, `ru_col`, and `sc_col` are now no longer used when ui2 is
enabled, except `ru_col` in the C implementation of the default ruler,
which will be replaced by a default expression.
2026-07-11 18:44:49 +02:00
Sébastien Hoffmann
935a14bb72 docs(ui2): deprecate v:echospace
The purpose of `v:echospace` was to avoid disruptive "Press ENTER"
prompts. Since those are no longer a problem with ui2, the complexity
of maintaining it up-to-date is no longer justified.
2026-07-11 18:44:49 +02:00
Sébastien Hoffmann
0ffd74ae85 fix(ui2): fix ruler on repeated messages
Problem: a long message is cropped to keep the ruler visible. But when
the message is repeated, it can be written over the ruler, while the
repetition indicator "(1)" is still placed just before the ruler, which
ends up somewhere inside the message.

Solution: currently, long messages are only cropped when setting the
'last' virttext. Make sure this happens after a repeated long message.
2026-07-11 18:44:42 +02:00
Sébastien Hoffmann
2473cb62b7 fix(ui2): correctly crop message at multibyte/multicell character 2026-07-11 18:31:54 +02:00
Sébastien Hoffmann
fcc391d89a fix(ui2): clear showcmd virt_text together with search count
Problem: when the search count is displayed, the showcmd virt_text is
set to 11 empty spaces to ensure a consistent distance between search
count and ruler, or screen edge in case of noruler. But when the search
count is removed to make place for a message, the empty dummy showcmd
remains and unnecessarily erases part of the message.

Solution: properly remove showcmd together with search count.
2026-07-11 18:31:54 +02:00
Sébastien Hoffmann
5b455a8aa0 feat(statusline): remove arbitrary item group minwid limit
- with today's screens, the arbitrary 50 cells limit is no longer as
  ample as a few decades ago
- minwid is effectively constrained by the output buffer size anyway, so
  accidentally setting huge numbers introduces no noticeable lag
- restores some backwards compatibility to ui2 for the edge-case where
  the ruler width was set to a number > 50 with the item group syntax
2026-07-11 18:31:54 +02:00
Sébastien Hoffmann
60687ccb6a fix(ui2)!: consistent ruler width inside/outside statusline
Problem: before ui2, the ruler in the last line had a one cell safety
margin on the right because writing in the last column of the last line
"scrolls the screen up on some terminals," according to code comments.
When the ruler is included in the statusline, it aligns on the left with
the normal ruler, but goes all the way to the screen edge on the right,
and is therefore one cell longer.

Since ui2 doesn't have that padding cell, they don't align anymore.

Also, in the future, when the C implementation of the ruler will be
replaced with a default expression that will be included in the default
statusline (currently `%-14.(%l,%c%V%) %P`), the width will naturally be
the same in both places, and the unit tests will need adapting anyway.

Solution: when ui2 is active, increase the ruler width by 1.

BREAKING CHANGE: the default ruler in ui2 is now 1 cell wider.

ref https://github.com/neovim/neovim/issues/40247
2026-07-11 18:31:54 +02:00
Sébastien Hoffmann
c5be331502 fix(ui2)!: don't constrain ruler to ru_wid, fix leading item group
Problem: ui2's ruler is no longer of fixed width, and the internal width
variable `ru_wid` now acts as an arbitrary maximum, which is unnecessary
because the same can now be achieved transparently with an item group.
Furthermore, the old way of setting `ru_wid` with an overloaded subset
of the item group syntax leads to a number of inconsistencies. In
particular, when the configured ruler expression is reused for including
the ruler into the statusline, where the item group syntax is
interpreted in the usual way. The fact that this width is set in the
`minwid` position is more confusing now that it is a de-facto maximum.

Solution: for ui2, constrain the ruler only by half the screen width,
which previously was an additional limit relevant on small screens.
Skip the special-case treatment of the ruler's leading item group spec,
process it like a normal item group.

Example: the current fallback ruler expression in the default statusline
now actually works for `rulerformat` itself:
  set rulerformat=%-14.(%l,%c%V%)\ %P
because the result can naturally expand to 18 cells instead of being
truncated to the default 17 cells, and removing the period after
`minwid` doesn't change the result, whereas before, it would unhelpfully
lead to setting the fixed ruler width to 14 cells.

BREAKING CHANGE: if the user used to set the ruler's fixed width, it
will now be treated as minimum instead of a maximum width, which in
practice increases backwards-compatibility with ui1 and vim. The main
remaining difference is that item groups are right-aligned by default,
but backwards-compatibility can be achieved by setting a negative
`minwid`, which ui1 and vim ignore. To restore the previous fixed width,
specify `maxwid` as well, but this does not work in ui1 and vim.
If `rulerformat` contains a `%=` without enclosing item group, it will
now expand to fill half the screen width. But in that case, it will
already spread out similarly in the new expression-based statusline, so
consistency of the ruler in both positions is increased.
To simulate the previous default behaviour, wrap it in `%-17.17(...%)`.
For best compatibility and reuse with vim, leave out `maxwid` and make
`minwid` negative, e.g. `%-20(...%)`.

fix https://github.com/neovim/neovim/issues/40247
2026-07-11 18:31:54 +02:00
Justin M. Keyes
0f1e0a7900 refactor(ctx): drop aucmd_prepbuf/aucmd_restbuf #40692 2026-07-11 12:04:31 -04:00
Justin M. Keyes
f2d15fc0b0 refactor(input): ungetchars() usage #40685
Repurpose `ins_char_typebuf` to make its usage more obvious.
Rename it and update docs.
2026-07-11 10:53:30 -04:00
Justin M. Keyes
e3b50671ef Merge #40690 from justinmk/fixci
test: unreliable system_spec, vim_spec, tui_spec
2026-07-11 09:14:31 -04:00
Justin M. Keyes
d1b7a39fc3 test: unreliable "TUI split sequences within 'ttimeoutlen'"
FAILED   ...Xtest_xdg_terminal/test/functional/terminal/tui_spec.lua @ 1200: TUI split sequences work within 'ttimeoutlen' time
    .../runner/work/neovim/neovim/test/functional/ui/screen.lua:774: Row 1 did not match.
    Expected:
      |*^                                                  |
      |{100:~                                                 }|
      |{100:~                                                 }|
      |{100:~                                                 }|
      |*{3:[No Name]                                         }|
      |{5:-- INSERT --}                                      |
      |{5:-- TERMINAL --}                                    |
    Actual:
      |*�^                                                 |
      |{100:~                                                 }|
      |{100:~                                                 }|
      |{100:~                                                 }|
      |*{3:[No Name] [+]                                     }|
      |{5:-- INSERT --}                                      |
      |{5:-- TERMINAL --}                                    |
2026-07-11 14:46:48 +02:00
Justin M. Keyes
f2927bd919 test: unreliable "vim.system (async) supports timeout"
FAILED   2 tests, listed below:
    FAILED   …/lua/system_spec.lua:124: …/lua/system_spec.lua @ 44: vim.system (async) supports timeout
    …/lua/system_spec.lua:124: …/lua/system_spec.lua:44: process still exists
    stack traceback:
    D:/a/neovim/neovim/test/functional/testnvim/exec_lua.lua:124: in function 'system'
    …/lua/system_spec.lua:124: in function <…/lua/system_spec.lua:118>
    FAILED   …/lua/system_spec.lua:111: …/lua/system_spec.lua @ 22: vim.system (sync) can set environment with clear_env = true and env = nil
    …/lua/system_spec.lua:111: …/lua/system_spec.lua:22: process still exists
    stack traceback:
    D:/a/neovim/neovim/test/functional/testnvim/exec_lua.lua:124: in function 'system'
    …/lua/system_spec.lua:111: in function <…/lua/system_spec.lua:97>
2026-07-11 14:46:48 +02:00
Justin M. Keyes
141a498cca test: unreliable "API nvim_list_chans, nvim_get_chan_info stream=job :terminal channel"
FAILED   ...vim/build/Xtest_xdg_api/test/functional/api/vim_spec.lua @ 3256: API nvim_list_chans, nvim_get_chan_info stream=job :terminal channel
    Expected values to be equal.
    Expected:
    {
      argv = { "/home/runner/work/neovim/neovim/build/bin/nvim", "-u", "NONE", "-i", "NONE" },
      buf = 2,
      buffer = 2,
      exitcode = 1,
      id = 4,
      mode = "terminal",
      pty = "",
      stream = "job"
    }
    Actual:
    {
      argv = { "/home/runner/work/neovim/neovim/build/bin/nvim", "-u", "NONE", "-i", "NONE" },
      buf = 2,
      buffer = 2,
      exitcode = 129,
      id = 4,
      mode = "terminal",
      pty = "",
      stream = "job",
      <metatable> = {
        __tostring = <function 1>
      }
    }
    stack traceback:
    ...vim/build/Xtest_xdg_api/test/functional/api/vim_spec.lua:3300: in function <...vim/build/Xtest_xdg_api/test/functional/api/vim_spec.lua:3256>
2026-07-11 14:46:48 +02:00
Justin M. Keyes
757800bc64 Merge #40688 from justinmk/fixci 2026-07-11 08:46:39 -04:00
Justin M. Keyes
f1904f2a6c test(dir): "replace - mapping" hangs the Windows CI 2026-07-11 14:09:05 +02:00
Justin M. Keyes
8d51e07fa1 feat(eval): writefile() treats RPC string as "blob"
related: fb6aeaba2d
2026-07-11 13:49:52 +02:00
Justin M. Keyes
0f7bd6a3cd fix(diff): resource leak on :diffput E787 error path #40686
Coverity CID 649080/649081
2026-07-11 07:15:04 -04:00
Justin M. Keyes
eb2e695e40 test: "Failed to start server: address already in use" #40683
Problem:
unreliable test:

    FAILED   …/tui_spec.lua @ 895: TUI mouse events work with right-click menu (escape sequences sent to child)
    D:/a/…/testnvim.lua:144: Vim:Failed to start server: address already in use
    stack traceback:
    D:/a/…/testnvim.lua:144: in function 'eval'
    D:/a/…/testnvim.lua:1015: in function 'new_pipename'
    …/tui_spec.lua:897: in function <…/tui_spec.lua:895>

Solution:
Workaround potential PID reuse.
2026-07-11 06:52:04 -04:00
github-actions[bot]
7e9f384dde docs: update version.c #40609
Co-authored-by: marvim <marvim@users.noreply.github.com>
2026-07-11 04:19:55 -04:00
glepnir
59dbca9b0c fix(api): nvim_cmd() "args" type too narrow #40670
Problem: nvim_cmd() accepts number/boolean in args and converts them
to strings, but the keyset declares ArrayOf(String).

Solution: use ArrayOf(Union(Integer, String, Boolean)) and wrap union
types in parens when generating array annotations.
2026-07-10 20:34:08 -04:00
Barrett Ruth
784765cb73 fix(winbar): update hidden tabpages on global 'winbar' change #40608
Problem:
Changing global 'winbar' only updates window layout state in the current
tabpage. This means existing hidden tabs can keep stale winbar height.

Solution:
Recompute winbar state for all tabpages on global `'winbar'` changes.
2026-07-10 12:49:52 -04:00
Barrett Ruth
3b88a8a65d fix(filetype): ensure directory bufname ends w/ slash sep #40552
Problem:
`vim.filetype.match()` needs a cheap way to recognize directory buffers
without doing filesystem stat work.

Solution:
Ensure full buffer names for directories end in a trailing slash. Now
directory buffers can proceed through the normal 'filetype' path.

Note side-effects: session and ShaDa buffer-list restore behavior must
be compatible, so those + corresponding tests must be updated.
2026-07-10 12:40:13 -04:00
Barrett Ruth
20a4b1bc5e fix(dir): user/plugin can override default "-" mapping #40676 2026-07-10 11:52:24 -04:00
Justin M. Keyes
6a8bb2d62f refactor(ctx): simplify ctx_switch (40674 2026-07-10 09:08:58 -04:00
dependabot[bot]
435734e8db ci: bump the github-actions group across 1 directory with 2 updates
Bumps the github-actions group with 2 updates in the / directory: [actions/checkout](https://github.com/actions/checkout) and [github/codeql-action](https://github.com/github/codeql-action).


Updates `actions/checkout` from 6 to 7
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

Updates `github/codeql-action` from 4.36.2 to 4.36.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v4.36.2...v4.36.3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: github/codeql-action
  dependency-version: 4.36.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-10 14:44:52 +02:00
Justin M. Keyes
d79c787f27 refactor(ctx): ctx_restore_curwin #40667
unify context-switching logic.

1. `prevwin` is now restored for all targets (was buf-only).
   - add a `nvim_win_call` test.
2. The buf-found "restore the shown buffer" dance no longer depends on
   the origin window: it runs even if the callback closed the origin.
2026-07-10 07:58:02 -04:00
bfredl
e684a3dd18 Merge pull request #38546 from dchinmay2/push-pozrrzptmvnv
build(zig): add formatc and lintc steps
2026-07-10 11:18:43 +02:00