392 Commits

Author SHA1 Message Date
Justin M. Keyes
7720e52a0b Merge #37424 $XDG_CONFIG_DIRS with init.lua, $NVIM_APPNAME 2026-02-06 13:28:43 -05:00
Jesse van der Pluijm
5c51b45a82 fix(startup): respect $NVIM_APPNAME in $XDG_CONFIG_DIRS paths
Problem:

$NVIM_APPNAME was not respected when searching $XDG_CONFIG_DIRS for
config files. Nvim hardcoded "nvim" when constructing paths like
`$XDG_CONFIG_DIRS/nvim/init.lua`, ignoring the $NVIM_APPNAME environment
variable.

This meant that config files like `$XDG_CONFIG_DIRS/myapp/init.lua` were
not loaded, even though $NVIM_APPNAME was set to "myapp".

Solution:

Use `get_appname()` instead of hardcoded "nvim" for $XDG_CONFIG_DIRS
paths in `do_system_initialization()` and `do_user_initialization()`.
This makes $XDG_CONFIG_DIRS behave consistently with $XDG_CONFIG_HOME,
which already respected $NVIM_APPNAME.

As documented in `runtime/doc/starting.txt` (L1440-L1441):
"In the help wherever `$XDG_CONFIG_…/nvim` is mentioned it is understood
as `$XDG_CONFIG_…/$NVIM_APPNAME`."

See:
43339dee40/runtime/doc/starting.txt (L1440-L1441)

Relates to #37405
2026-02-06 16:12:01 +01:00
Jesse van der Pluijm
c785d5cdf0 fix(startup): source init.lua from XDG_CONFIG_DIRS
Problem:

`init.lua` files in `$XDG_CONFIG_DIRS` directories were not being sourced during startup, even though the documentation states they should be searched alongside `init.vim`.

See:

e51f5e17e1/runtime/doc/starting.txt (L495-L496)

Solution:

Modify `do_user_initialization()` to search for `init.lua` in each `$XDG_CONFIG_DIRS` directory before falling back to `init.vim`, matching the behavior for `$XDG_CONFIG_HOME`. Also show `E5422` error if both `init.lua` and `init.vim` exist in the same directory.

Fixes #37405
2026-02-06 16:11:22 +01:00
luukvbaal
bf68ba40a0 refactor: rename _extui => _core.ui2 #37692
Problem:
_extui module name is confusing and should eventually end up in _core/.

Solution:
Move it there and name it ui2.
2026-02-05 07:45:45 -05:00
zeertzjq
19eb75831b ci(test): bump Windows runners to windows-2025 and unskip tests (#37666)
Bumping to windows-2025 seems to fix at least one case of spaces having
wrong attributes in TUI tests, which allow unskipping dozens of tests.
2026-02-03 03:03:41 +08:00
zeertzjq
19a3b67789 fix(process): avoid unexpected behavior when PTY chdir failed (#37614)
Problem:  Unexpected behavior after PTY child process fails to chdir(),
          as it then thinks it's the parent process.
Solution: Exit the child process instead of returning.
2026-01-29 22:02:24 +08:00
zeertzjq
1f0dbfea2f fix(tui): log chdir failure properly #37591 2026-01-28 05:44:17 -05:00
zeertzjq
6291256868 fix(process): avoid buffering unnecessary UI event with PTY CWD (#37582)
Problem:
Calling os_chdir() to change the child processes' CWD may cause some
unnecessary UI events to be buffered. These UI events don't go anywhere
as execvp() is called before flushing the UI buffer.

Solution:
Use uv_chdir() instead of os_chdir(). Also fix getting error string
incorrectly. Add test for the current behavior.
2026-01-28 06:50:49 +08:00
zeertzjq
d3aae6172a test: fix flaky tests (#37478)
* test(core/channels_spec): fix flaky test

Always use expect_stdout() to check PTY output.

* test(autocmd/termxx_spec): fix flaky test

Usually the Ctrl-C cancels the following :qa!, but sometimes it doesn't,
and Nvim exits before feed() returns. Instead make sure that :qa! always
reaches Nvim and use expect_exit().
2026-01-21 08:41:00 +08:00
zeertzjq
15b9118ac0 test: fail CI if .nvimlog is not empty (#37470)
This will prevent adding passing tests which logs errors in .nvimlog.

Close #28323
Related: https://github.com/neovim/neovim/pull/27660#issuecomment-2035738597

Co-authored-by: dundargoc <gocdundar@gmail.com>
2026-01-20 20:56:06 +08:00
zeertzjq
6da968dd7f test(core/server_spec): check error in logfile (#37469) 2026-01-20 06:57:10 +00:00
James Fotherby
bfe9fa0f8e fix(socket): remove stale socket files (#37378)
Problem:
Crashed Nvim leaves socket files. Subsequent starts fail with "address already in use".

Solution:
On bind failure, test socket liveness via connect(). Remove if stale, retry bind().

Fixes #36581
2026-01-20 13:59:43 +08:00
zeertzjq
8133760c98 test: add tests for #14379 2026-01-20 07:09:15 +08:00
Justin M. Keyes
994444571e test: remove non-actionable tests from "pending" list #37384
Problem:
`t.skip()` adds to the "pending" list. If there is no path to fixing
a pending test, it adds noise to the pending list.

Solution:
Return early instead of using `t.skip()`.
2026-01-14 19:25:11 -05:00
bfredl
5581a53437 fix(shell): ceci n'est pas une pipe
On linux /dev/stdin is defined as a symlink to /proc/self/fd/0
This in turn is defined as a "magic" symlink which is allowed to point
to internal kernel objects which really does not have a file
name. As a glaring inconsistency, fopen("/proc/self/fd/0", "r")
works if fd was originally opened using pipe() but not using
socketpair(). As it happens UV_CREATE_PIPE does not create pipes
but creates socket pairs. These two unfortunate conditions
means that using /dev/stdin and similar does not work in
shell commands in nvim on linux. as a work around, override
libuv's descicion and create an actual pipe pair.

This change is not needed on BSD:s but done unconditionally for simplicity,
except for on windows where it is not done for stdout because of windows

fixes #35984
2026-01-13 09:41:51 +01:00
zeertzjq
4399250e90 fix(channel): unreference list after callback finishes (#37358) 2026-01-12 00:33:19 +00:00
Justin M. Keyes
1d70c96e5b build: move shared.lua to _core/ 2025-12-30 01:44:52 -05:00
Justin M. Keyes
20e77c5d88 build: ship "_core/*" as bytecode (built-into Nvim binary)
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-30 01:44:24 -05:00
Justin M. Keyes
2eb11f21eb test(messages): skip os_delay during tests
Problem:
Tests that trigger `os_delay` messages may take 1-3 seconds, wasting
build/CI time, since this serves no purpose in tests.

Solution:
- Introduce `msg_delay` for cases where `os_delay` is being used as
  a "UI feature".
- Skip `msg_delay` in tests.
2025-12-20 18:38:11 -05:00
zeertzjq
c08139d790 fix(lua): don't remove first char of non-file stacktrace source (#37008) 2025-12-18 08:09:16 +08:00
zeertzjq
592582ba48 fix(input): don't exit on EOF when peeking for input with -es (#36948)
Only exit on EOF when doing a blocking wait for input.
2025-12-15 08:00:40 +08:00
benarcher2691
7f2d5d6883 fix(msgpack): use fixstr encoding for strings of length 20-31 #36737
Problem:
MessagePack fixstr format supports string lengths 0-31, but mpack_str()
only used fixstr for lengths < 20. Strings of 20-31 bytes were
incorrectly encoded as str8 (2-byte header) instead of fixstr (1-byte
header).

Solution:
Change the condition from `len < 20` to `len < 32` to match the
MessagePack specification.

This fix affects message timing which exposed a pre-existing race
condition in the channels_spec PTY test. The test now uses a helper
function to accumulate partial PTY reads, making it more robust.

Fixes #32784
2025-12-01 13:16:44 -05:00
zeertzjq
d077a24f5c fix(socket): avoid stack-use-after-return after timeout (#36405)
Problem:
In socket_connect(), if connecting to the given TCP address times out,
libuv is still trying to connect to the address, and connect_cb may be
called when running the libuv event loop after the `status` variable
referenced by `req.data` goes out of scope.

Solution:
Close the uv_tcp_t handle and wait for connect_cb to be called before
retrying or failing in socket_connect(). This also avoid leaking libuv
handles.

The tests added here only check that the non-timeout case still works,
as checking the timeout case is very hard without modifications to the
code. Removing the first LOOP_PROCESS_EVENT_UNTIL() in socket_connect()
(the one with the timeout) is a way to check that manually.

Also add a comment about the cause of the ASAN error in #34586.
2025-11-01 08:20:46 +08:00
phanium
eaa9aca130 fix(jobs): jobstart(term=true) accepts width/height #33904
Problem: when create a hidden terminal job with `nvim_buf_call`+
`jobstart(…,{term=true})`, program like `lazygit` cannot figure out the
correct width and height.

Solution: `jobstart(…,{term=true})` accepts `width`/`height`
2025-10-14 21:42:02 -07:00
zeertzjq
eb7c12d3e3 test: remove a few more redundant clear() calls (#35903) 2025-09-24 14:25:54 +08:00
Cameron Ring
0f64f0f5b6 fix(startup): crash in read_stdin #35699
Problem:
Crash on startup in some situations due to call to `set_curbuf`
with the current value of `cur_buf`.

Solution:
Switch buffers before doing the wipeout of the stdin buffer.
Use cmdline cmds instead of raw buffer pointers to avoid lifetime issues.
2025-09-10 21:37:42 -07:00
Siddhant Agarwal
7a71235399 fix(server): serverlist({peer=true}) does not find peer servers #35506 2025-08-28 06:41:31 -07:00
zeertzjq
0b8a9bde0e fix(diff): set default diff flags properly (#35450) 2025-08-24 14:42:10 +08:00
Cameron Ring
30dae87de4 fix(startup): file buf is lost if stdin is empty and "-" is last #35402
Problem:
Running `echo dummy | nvim file1 file2` closes the file1 buffer if
file1 doesn't exist.

Solution:
Logic changed in 43e8ec9 such that stdin buffer may now be created *after*
file args. Handle that case.
2025-08-20 20:34:49 -07:00
Justin M. Keyes
dc3a30cfbb fix(messages): 'exrc' / secure messages 2025-07-28 22:00:25 -04:00
Justin M. Keyes
56a4ef3c21 docs: lsp, ui events, dev guidance, osc7
fix #34981
2025-07-28 22:00:25 -04:00
nyngwang
dc67ba948e feat(exrc): user must view and explicitly run ":trust" #35069
Problem:
It's relatively easy to mispress key `a` to (a)llow arbitrary execution
of 'exrc' files. #35050

Solution:
- For exrc files (not directories), remove "allow" menu item.
  Require the user to "view" and then explicitly `:trust` the file.
2025-07-28 13:11:58 -07:00
Siddhant Agarwal
5151f635ca feat: serverlist({peer=true}) returns peer addresses #34806
Problem:
serverlist() only lists servers that were started by the current Nvim.

Solution:
Look for other Nvim servers in stdpath("run").
2025-07-27 21:40:04 -07:00
luukvbaal
e946951f6a test(tui_spec): flakiness, global highlight definitions #34958 2025-07-16 18:54:22 -07:00
Yochem van Rosmalen
99873296be test(exrc): lua exrc knows its location #34713
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2025-07-01 03:51:48 -07:00
luukvbaal
c8c78b531b fix(startup): make startup windows if there are only floating windows (#34349)
Problem:  If user init creates a floating window, startup windows
          (e.g. to accomodate arglist files) are no longer created.
Solution: Check that firstwin->w_next is not floating when deciding
          whether to make startup windows.
2025-06-07 11:24:51 +02:00
luukvbaal
981d4ba45e fix(eval): winnr('$') counts non-current hidden/unfocusable windows #34207
Problem:  Non-visible/focusable windows are assigned a window number,
          whereas commands that use this window number skip over them.

Solution: Skip over non-visible/focusable windows when computing
          the window number, unless it is made the current window
          through the API in which case an identifiable window number
          is still useful. This also ensures it matches the window
          number of the window entered by `<winnr>wincmd w` since
          403fcacf.
2025-06-01 15:12:12 -07:00
Yochem van Rosmalen
8d397fa458 feat(exrc): stop searching in parent directories by unsetting 'exrc'
Problem:
No way for a user to limit 'exrc' search in parent directories (compare
editorconfig.root).

Solution:
A configuration file can unset 'exrc', disabling the search for its
parent directories.
2025-05-20 00:03:14 +02:00
Yochem van Rosmalen
23bf4c0531 feat(exrc): search in parent directories (#33889)
feat(exrc): search exrc in parent directories

Problem:
`.nvim.lua` is only loaded from current directory, which is not flexible
when working from a subfolder of the project.

Solution:
Also search parent directories for configuration file.
2025-05-11 11:00:51 -05:00
Justin M. Keyes
fc2dee1736 feat(messages): cleanup Lua error messages
"Error" in error messages is redundant. Just provide the context, don't
say "Error ...".
2025-05-04 11:22:57 -04:00
Justin M. Keyes
52a4bc4548 docs: lsp, emoji, startup #33446
Co-authored-by: Maria José Solano <majosolano99@gmail.com>
2025-04-27 13:40:46 -07:00
Au.
44f1dbee0d fix(spell): save spell files to stdpath('data')/site/spell #33528 2025-04-18 08:56:20 -07:00
Judit Novak
fd973c0a4e fix(env.c): drop envmap, free os_getenv() result #32683
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-04-16 03:36:07 -07:00
Yochem van Rosmalen
b10cb0296a feat(defaults): store spellfile in stdpath('data') #33048
Problem:
First rtp directory is unpredictable and not in line with XDG
base spec.

Solution:
Use stdpath('data')/spell as directory if 'spellfile' is not set.

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2025-04-04 05:21:57 -07:00
Justin M. Keyes
7333c39e6c docs: misc #32959 2025-03-18 06:18:37 -07:00
zeertzjq
dbd76c2c41 test: reduce flakiness in blocking wait tests (#32868) 2025-03-13 00:42:02 +00:00
zeertzjq
f05a6666cf fix(events): always allow some events to be nested (#32706)
Always allow the following four events to be nested, as they may contain
important information, and are triggered on the event loop, which may be
processed by a blocking call inside another autocommand.

- ChanInfo
- ChanOpen
- TermRequest
- TermResponse

There are some other events that are triggered on the event loop, but
they are mostly triggered by user actions in a UI client, and therefore
not very likely to happen during another autocommand, so leave them
unchanged for now.
2025-03-08 07:29:45 +08:00
zeertzjq
6750d00fe9 vim-patch:8.2.4603: sourcing buffer lines is too complicated
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)

85b43c6cb7

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

f68517c167

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2025-02-28 18:21:08 +08:00
Justin M. Keyes
ac768996b2 refactor(tests): drop os_kill #32401
Also change job tests to use `nvim` instead of random programs like `ping`.
2025-02-11 07:19:46 -08:00
Justin M. Keyes
4b0e2605ea feat(ui): UI :detach command
Problem:
Cannot detach the current UI.

Solution:
- Introduce `:detach`.
- Introduce `Channel.detach`.

Co-authored-by: bfredl <bjorn.linse@gmail.com>
2025-02-10 18:56:11 +01:00