Commit Graph

622 Commits

Author SHA1 Message Date
zeertzjq
e3d46a6337 test: start test runners in Xtest_xdg dir (#37964)
This is a better way to prevent parallel tests from interfering with
each other, as there are many ways files can be created and deleted in
tests, so enforcing different file names is hard.

Using $TMPDIR can also work in most cases, but 'backipskip' etc. have
special defaults for $TMPDIR.

Symlink runtime/, src/, test/ and README.md to Xtest_xdg dir to make
tests more convenient (and symlinking test/ is required for busted).

Also, use README.md instead of test/README.md in the Ex mode inccommand
test, as test/README.md no longer contains 'N' char.
2026-02-20 06:53:33 +08:00
zeertzjq
f0137bf443 test(terminal/channel_spec): fix test still flaky on Windows (#37968)
FAILED   1 test, listed below:
FAILED   test/functional/terminal/channel_spec.lua @ 133: chansend sends lines to terminal channel in proper order
test/functional/terminal\channel_spec.lua:141: retry() attempts: 3
test/functional/terminal\channel_spec.lua:143: Failed to match any screen lines.
Expected (anywhere): "echo "hello".*echo "world""
Actual:
  |^PowerShell 7.4.13                                                                                   |
  |PS D:\a\neovim\neovim> {UNEXPECTED foreground = tonumber('0xffff40'), fg_indexed = true:echo }{UNEXPECTED foreground = tonumber('0x00e0e0'), fg_indexed = true:"hello"}                                                                 |
  |hello                                                                                               |
  |PS D:\a\neovim\neovim> {UNEXPECTED foreground = tonumber('0xffff40'), fg_indexed = true:echo }{UNEXPECTED foreground = tonumber('0x00e0e0'), fg_indexed = true:"world"}                                                                 |
  |{UNEXPECTED foreground = Screen.colors.Gray88, fg_indexed = true:>> }                                                                                                 |
  |world                                                                                               |
  |PS D:\a\neovim\neovim> {UNEXPECTED foreground = tonumber('0xffff40'), fg_indexed = true:echo }{UNEXPECTED foreground = tonumber('0x00e0e0'), fg_indexed = true:"hello"}                                                                 |
  |{UNEXPECTED foreground = Screen.colors.Gray88, fg_indexed = true:>> }                                                                                                 |
  |hello                                                                                               |
  |PS D:\a\neovim\neovim> {UNEXPECTED foreground = tonumber('0xffff40'), fg_indexed = true:echo }{UNEXPECTED foreground = tonumber('0x00e0e0'), fg_indexed = true:"world"}                                                                 |
  |{UNEXPECTED foreground = Screen.colors.Gray88, fg_indexed = true:>> }                                                                                                 |
  |world                                                                                               |
  |PS D:\a\neovim\neovim> {UNEXPECTED foreground = tonumber('0xffff40'), fg_indexed = true:echo }{UNEXPECTED foreground = tonumber('0x00e0e0'), fg_indexed = true:"hello"}                                                                 |
  |{UNEXPECTED foreground = Screen.colors.Gray88, fg_indexed = true:>> }                                                                                                 |
  |hello                                                                                               |
  |PS D:\a\neovim\neovim> {UNEXPECTED foreground = tonumber('0xffff40'), fg_indexed = true:echo }{UNEXPECTED foreground = tonumber('0x00e0e0'), fg_indexed = true:"world"}                                                                 |
  |{UNEXPECTED foreground = Screen.colors.Gray88, fg_indexed = true:>> }                                                                                                 |
  |world                                                                                               |
  |{1:term://D:\a\neovim\neovim//9056:pwsh.exe -nop [-]                                                   }|
  |                                                                                                    |
2026-02-19 19:31:33 +08:00
zeertzjq
2605ce9377 test: fix flaky tests in terminal/{buffer,channel}_spec.lua (#37966)
In buffer_spec.lua, wait for a bit more than the refresh delay.
In channel_spec.lua, retry sending lines on Windows.
2026-02-19 17:57:02 +08:00
zeertzjq
a520d9c4ea test: fix test failure causing following tests to fail (#37932) 2026-02-18 17:08:08 +08:00
zeertzjq
f3feae0bbf fix(terminal): crash after deleting buffer lines (#37921)
Problem:  Terminal crashes after deleting buffer lines.
Solution: Don't insert lines above lines 0.
2026-02-17 13:00:13 +00:00
glepnir
bd12aef784 fix(highlight): refresh highlight attrs before message output #25737
Problem:
When MsgArea highlight is changed, the next message may flash
and disappear because msg_start() renders with stale highlight attributes.

msg_puts_len() uses HL_ATTR(HLF_MSG) to render message text, which
happens before update_screen() calls highlight_changed().
So the message is rendered with outdated attrs.

Solution:
Call highlight_changed() in msg_start().
2026-02-17 07:59:07 -05:00
zeertzjq
b614c15392 refactor(terminal): don't put cursor at bottom-left in Normal mode (#37873)
When the terminal process is suspended, putting cursor at bottom-left
hints that pressing a key will change the suspended state. However, when
returning to Normal mode, the user is more likely to interact with the
actual terminal output (e.g. copying it), so it's better to put cursor
at the old position which should be closer to the output.

Also, using is_focused() to check for mode is confusing. Just check
`State & MODE_TERMINAL` instead.
2026-02-15 17:25:22 +08:00
Justin M. Keyes
0864939cc5 fix(restart): append -c <cmd> at end, drop -- [files…] #37846
Problem:
- `:restart <cmd>` prepends `-c <cmd>` before the original `-c` args (if
  any). So the original `-c` args may "override" it, which is
  surprising.
- Confusing logic: `v:argv` is partially prepared in `ex_docmd.c`, and
  then later `ui.c` skips other parts of it.

Current behavior is nonsense, for example this sequence:

    :restart echo "Hello"
    :restart +qall echo "Hello" | echo "World"

results in this v:argv:

    [
      'nvim'
      '-c'
      'echo "Hello" | echo "World"'
      '--embed'
      '-c'
      'echo "Hello"'
      ...
    ]

Whereas after this commit, v:argv is:

    [
      'nvim'
      '--embed'
      ...
      '-c'
      'echo "Hello" | echo "World"'
    ]

Solution:
- Append `-c <cmd>` at the _end_ of `v:argv`, not the start.
- Use a dummy placeholder `+:::` to mark where the "restart command"
  appears in `v:argv`.
- Do all `v:argv` preparation in `ex_docmd.c`. This simplifies `ui.c`.
- Drop `-- [files…]` from `v:argv` since it is probably more annoying
  than useful. (Users can use sessions to restore files on restart.)
2026-02-14 05:34:30 -05:00
zeertzjq
1a1a60bd05 fix(terminal): resuming doesn't work with command in fish (#37857)
Problem:  Resuming terminal process doesn't work with command in fish.
Solution: Send SIGCONT to the entire process group.

Use killpg() like what bash and zsh do on `fg`:
https://cgit.git.savannah.gnu.org/cgit/bash.git/tree/jobs.c?id=637f5c8696a6adc9b4519f1cd74aa78492266b7f#n3928
77045ef899/tree/Src/jobs.c (l2674)
77045ef899/tree/Src/signals.c (l538)

Install fish on CI to test this.
2026-02-14 10:49:39 +08:00
zeertzjq
9cbc430cfb fix(terminal): missing refresh with partial mappings (#37839)
Problem:  Terminal buffers are not refreshed when processing keys that
          trigger partial mappings.
Solution: Process due terminal refreshes before redrawing.
2026-02-14 08:00:27 +08:00
zeertzjq
6bc0b8ae87 feat(terminal): detect suspended PTY process (#37845)
Problem:  Terminal doesn't detect if the PTY process is suspended or
          offer a convenient way for the user to resume the process.
Solution: Detect suspended PTY process on SIGCHLD and show virtual text
          "[Process suspended]" at the bottom-left. Resume the process
          when the user presses a key.
2026-02-13 13:49:08 +00:00
glepnir
a7a7cdbcda fix(cmd): filter stdin file "-" from v:argv on :restart #37165
Problem:
restart hangs when nvim was started with stdin input, "-" marker stays
in v:argv, causing the restarted instance to block reading from stdin.

Solution:
filter out the "-" argument when rebuilding v:argv during restart.
Stdin content is ephemeral and shouldn't be re-read after restart.
2026-02-13 06:29:48 -05:00
zeertzjq
cc7022c544 fix(terminal): scrollback may still be wrong on height increase (#37835)
Problem:  Terminal scrollback may be wrong when increasing height after
          outputting lines with full scrollback.
Solution: Ensure enough number of scrollback lines have been deleted.
2026-02-13 01:06:23 +00:00
zeertzjq
16da47f474 fix(terminal): changing height may lead to wrong scrollback (#37824)
Problem:  Changing terminal height immediately after outputting lines
          may lead to wrong scrollback.
Solution: Insert pending scrollback lines before the old window height.
2026-02-12 20:10:02 +08:00
zeertzjq
54468c1c3c fix(terminal): wrong scrollback with nvim_open_term() on buffer (#37791)
Problem:  Wrong scrollback when passing a buffer with many lines to
          nvim_open_term().
Solution: Delete all buffer lines before opening the terminal.

I tried to use buf_clear(), but it crashes inside deleted_lines_mark(),
so I'll just use deleted_lines_buf() for now. The behavior of marks can
be decided later.
2026-02-10 06:30:02 +08:00
Sean Dewar
1b627f6c59 fix(terminal): set b_locked when setting &buftype (#37787)
Problem: heap use-after-free if OptionSet autocommands from setting a terminal's
&buftype wipe the buffer.

Solution: set b_locked during OptionSet for &buftype.
2026-02-09 12:51:04 +00:00
zeertzjq
e254688016 fix(terminal): handle ED 3 (clear scrollback) properly (#21412)
Problem:  Terminal doesn't handle ED 3 (clear scrollback) properly.
Solution: Add vterm callback for sb_clear().

Also fix another problem that scrollback lines may be duplicated when
pushing to scrollback immediately after reducing window height, as can
be seen in the changes to test/functional/terminal/window_spec.lua.
2026-02-09 11:28:00 +00:00
Sean Dewar
19379d1255 fix(autocmd): deferred TermResponse lacks "data", may not fire (#37778)
Problem: TermResponse deferred due to blocked autocommands lacks "data" payload.
Also, it may not fire if a new v:termresponse reuses the same string address.

Solution: add it. Use the value of v:termresponse for "data.sequence". Replace
pointer comparisons with a flag.

The removal of "old_termresponse" comparisons is required to pass the test on
the CI, or locally for me when compiled in RelWithDebInfo.
2026-02-08 21:43:50 +00:00
Sean Dewar
1519a34e43 fix(terminal): autocmds leave terminal open to wiped buffer
Problem: if buf_free_all autocommands open a terminal, it will remain open after
the buffer is freed.

Solution: close terminals again later, this time while blocking autocommands.

Did consider terminal_open checking stuff like b_locked_split instead, but
that's set during BufHidden, etc., which doesn't mean the buffer's being wiped.
2026-02-08 16:12:00 +00:00
Sean Dewar
da8de99d0b fix(window): use real last buffer of closed window
Problem: close_buffer autocmds may switch buffers at the last moment when
closing a window, causing terminal_check_size to prefer the size of a closed
window, or TabClosed to set an old <abuf>.

Solution: use the actual last buffer, similar to what TabClosed did before.

NOTE: If buffer was unloaded/deleted (not wiped), then TabClosed's <abuf> may
not use it. (w_buffer = NULL) Maybe odd, but it's how it worked before anyhow.

Relies on close_buffer reliably setting w_buffer to NULL if freed, otherwise
buf_valid is better. Only concern I see is if the window wasn't in the window
list after closing the buffer (close_buffer won't set it to NULL then), but then
win_close{_othertab} should've returned earlier.
2026-02-08 16:12:00 +00:00
Sean Dewar
5c156fdc64 fix(terminal): update size after closing window
Problem: terminal's size may not update after one of its windows close.

Solution: call terminal_check_size after closing a window.

Disable test for Windows, as for some reason it only shows a few lines...
2026-02-08 16:12:00 +00:00
Sean Dewar
c90593ed5f test(terminal): skip flaky test on Windows (#37774)
Ref: https://github.com/neovim/neovim/pull/37758#discussion_r2778065203
2026-02-08 02:27:30 +00:00
horrifyingHorse
ba6440c106 fix(terminal): reset w_leftcol after resizing terminal
Problem: windows may scroll horizontally upon resize using the old terminal
size, which may be unnecessary and cause the content to be partially out-of-view.

Solution: reset the horizontal scroll after resizing.
2026-02-06 15:50:05 +00:00
zeertzjq
b95e0a8d20 test(terminal/cursor_spec): fix flaky test (#37715)
Problem:  Cursor visibility test may fail if the :sleep lasts too long.
Solution: Wait for the TermLeave autocommand to finish.
2026-02-05 14:27:15 +08:00
zeertzjq
814f2629cb fix(terminal): handle split composing chars at right edge (#37694)
Problem:
Recombining composing chars in terminal doesn't work at right edge.

Solution:
Check for the case where printing the previous char didn't advance the
cursor. Reset at_phantom when returning to combine_pos.
2026-02-05 00:19:11 +00:00
zeertzjq
70b1b15144 test(tui_spec): check that 'ttimeoutlen' works (#37702) 2026-02-05 06:26:59 +08:00
zeertzjq
379e307148 fix(terminal): also don't propagate $COLORTERM on Windows (#37699)
The same reason in #26440 applies to Windows as well.
2026-02-04 23:07:47 +08:00
zeertzjq
16680e57ba fix(tui): use 0x7f as Backspace on Windows with VT input (#37679)
Problem:  0x08 is treated as Backspace instead of Ctrl-H on Windows.
Solution: Treat 0x7f as Backspace if VT input is enabled, so that 0x08
          is treated as Ctrl-H.

Ref: https://github.com/microsoft/terminal/issues/4949
2026-02-03 21:40:40 +08:00
zeertzjq
963162b338 test(terminal/cursor_spec): fix flaky test (#37681) 2026-02-03 05:08:34 +00:00
zeertzjq
af4115ce2b test(tty-test): enable VTI and VTP on Windows (#37677) 2026-02-03 08:50:27 +08: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
1355640d6a test(tui_spec): fix overwriting environment on Windows (#37651) 2026-02-01 08:16:09 +00:00
zeertzjq
77162a717a test: wait for uv.pipe_connect() callback (#37640)
Problem:
On Windows, writing to a pipe doesn't work if the pipe isn't connected
yet. This causes an RPC request to a session newly created by connect()
to hang, as it's waiting for a response to a request that never reaches
the server.

Solution:
Wait for uv.pipe_connect() callback to be called when using connect().
2026-02-01 08:14:12 +08:00
zeertzjq
484f455402 test(terminal): status is -1 in TermClose if buffer is deleted (#37609) 2026-01-29 08:29:49 +00:00
zeertzjq
97d9b85bf9 fix(terminal): wrong scrollback with BufFile* autocommand (#37601)
Problem:  Wrong terminal scrollback if BufFile* autocommand drains PTY
          output but doesn't process the pending refresh.
Solution: Refresh scrollback before refreshing screen in terminal_open()
          if scrollback has been allocated.
2026-01-28 23:32:58 +08:00
zeertzjq
1f0dbfea2f fix(tui): log chdir failure properly #37591 2026-01-28 05:44:17 -05:00
zeertzjq
df21ac729c fix(terminal): losing output if BufFile* poll for events (#37580)
Problem:  Terminal loses output if a BufFilePre or BufFilePost autocmd
          polls for events.
Solution: Rename the buffer after allocating the terminal instance. Also
          fix buffer getting wrong name if BufFilePre uses NameBuff.
2026-01-28 06:21:28 +08:00
zeertzjq
b88b7f9591 fix(terminal): wrong colors with nvim_open_term() in non-curbuf (#37579)
Problem:  Wrong colors with nvim_open_term() in non-current buffer.
Solution: Pass the buffer to get_config_string().
2026-01-27 06:59:23 +00:00
zeertzjq
9540e7470b fix(terminal): possible heap-use-after-free during Nvim exit
Usually, terminal_close() calls refresh_terminal(), which allocates the
scrollback buffer, and term_may_alloc_scrollback() in terminal_open()
won't dereference the buffer. However, refresh_terminal() is not called
during Nvim exit, in which case a heap-use-after-free may happen if
TermOpen wipes buffer. Check for non-NULL buf_handle to avoid that.
2026-01-27 13:12:15 +08:00
zeertzjq
b4039ec0b0 fix(terminal): don't allow b:term_title watcher to delete buffer 2026-01-27 12:45:49 +08:00
zeertzjq
b6befc7b03 fix(terminal): losing scrollback when TermOpen polls for events (#37573)
Problem:  When TermOpen polls for enough events to use the scrollback
          buffer, scrollback is lost until the next terminal refresh.
Solution: Allocate the scrollback buffer when it's needed.
2026-01-27 03:46:54 +00:00
zeertzjq
196df35cca fix(terminal): <Ignore> should be no-op (#37494) 2026-01-22 09:26:22 +08:00
zeertzjq
25ce44845d fix(terminal): restore options properly when switching buffer (#37485) 2026-01-21 18:42:47 +08:00
zeertzjq
1883fe39bd test: fix some type warnings (#37483) 2026-01-21 15:11:47 +08:00
zeertzjq
1949452bd3 fix(tui): avoid using uv_pipe_t as uv_tty_t (#37479)
Check tui->out_isatty before accessing tui->output_handle.tty.
2026-01-21 11:53:18 +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
8133760c98 test: add tests for #14379 2026-01-20 07:09:15 +08:00
zeertzjq
e051718908 fix(process): don't limit PTY master remaining data size 2026-01-15 09:32:10 +08:00
zeertzjq
295fb3fdb2 fix(terminal): :edit should respect 'bufhidden' with exited job (#37301) 2026-01-10 08:25:49 +08:00
zeertzjq
681d006549 vim-patch:9.1.2066: :wqall! doesn't close a terminal like :qall! does (#37314)
Problem:  :wqall! doesn't close a terminal buffer like :qall! does
          (after 8.0.1525).
Solution: Check eap->forceit (zeertzjq).

Ref: https://github.com/vim/vim/issues/2654#issuecomment-366803932

related: vim/vim#2654
related: neovim/neovim#14061
closes:  vim/vim#19129

d8558fdf4f
2026-01-08 23:36:47 +00:00