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.
Before calling "attach" a screen object is just a dummy container for
(row, col) values whose purpose is to be sent as part of the "attach"
function call anyway.
Just create the screen in an attached state directly. Keep the complete
(row, col, options) config together. It is still completely valid to
later detach and re-attach as needed, including to another session.
In the api_info() output:
:new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val')
...
{'return_type': 'ArrayOf(Integer, 2)', 'name': 'nvim_win_get_position', 'method': v:true, 'parameters': [['Window', 'window']], 'since': 1}
The `ArrayOf(Integer, 2)` return type didn't break clients when we added
it, which is evidence that clients don't use the `return_type` field,
thus renaming Dictionary => Dict in api_info() is not (in practice)
a breaking change.
- `alter_slashes` belongs in `testutil.lua`, not `testnvim.lua`.
- `alter_slashes` is an unusual name. Rename it to `fix_slashes`.
- invert its behavior, to emphasize that `/` slashes are the preferred,
pervasive convention, not `\` slashes.
Problem:
If $NVIM_APPNAME is a relative dir path, Nvim fails to start its
primary/default server, and `v:servername` is empty.
Root cause is d34c64e342, but this wasn't
noticed until 96128a5076 started reporting the error more loudly.
Solution:
- `server_address_new`: replace slashes "/" in the appname before using
it as a servername.
- `vim_mktempdir`: always prefer the system-wide top-level "nvim.user/"
directory. That isn't intended to be specific to NVIM_APPNAME; rather,
each *subdirectory* ("nvim.user/xxx") is owned by each Nvim instance.
Nvim "apps" can be identified by the server socket(s) stored in those
per-Nvim subdirs.
fix#30256
Problem:
$XDG_RUNTIME_DIR may be broken on WSL, which prevents starting (and even
building) Nvim. #30282
Solution:
- When startup fails, mention the servername in the error message.
- If an autogenerated server address fails, log an error and continue
with an empty `v:servername`. It's only fatal if a user provides a bad
`--listen` or `$NVIM_LISTEN_ADDRESS` address.
Before:
$ nvim --headless --listen ./hello.sock
nvim: Failed to --listen: "address already in use"
$ NVIM_LISTEN_ADDRESS='./hello.sock' ./build/bin/nvim --headless
nvim: Failed to --listen: "address already in use"
After:
$ nvim --headless --listen ./hello.sock
nvim: Failed to --listen: address already in use: "./hello.sock"
$ NVIM_LISTEN_ADDRESS='./hello.sock' ./build/bin/nvim --headless
nvim: Failed $NVIM_LISTEN_ADDRESS: address already in use: "./hello.sock"
Problem:
Since 96128a5076 the test logs have noise from tests that *expect*
failures:
$NVIM_LOG_FILE: /tmp/cirrus-ci-build/build/.nvimlog
(last 100 lines)
ERR 2024-09-04T13:38:45.181 T949.28335.0/c terminfo_start:486: uv_pipe_open failed: no such device or address
ERR 2024-09-04T13:38:45.181 T949.28335.0/c flush_buf:2527: uv_write failed: bad file descriptor
ERR 2024-09-04T13:38:45.181 T949.28335.0/c flush_buf:2527: uv_write failed: bad file descriptor
WRN 2024-09-04T13:43:43.294 ?.35904 server_start:173: Failed to start server: address already in use: /…/Xtest_tmpdir/…/T7159.35895.0
WRN 2024-09-04T13:43:43.314 ?.35907 server_start:173: Failed to start server: illegal operation on a directory: /
ERR 2024-09-04T13:43:43.332 ?.35909 socket_watcher_init:60: Host lookup failed: https://example.com
Solution:
Rewrite the test to use `vim.system()`. Set NVIM_LOG_FILE in the child
process to a "throwaway" logfile.
Problem:
137f98cf64 added the `create` parameter to `tmpname()` but didn't
fully implement it.
Solution:
- Update impl for the `os.tmpname()` codepath.
- Inspect all usages of `tmpname()`, update various tests.
Problem:
`nvim --listen` does not error on EADDRINUSE. #30123
Solution:
Now that `$NVIM_LISTEN_ADDRESS` is deprecated and input *only* (instead
of the old, ambiguous situation where it was both an input *and* an
output), we can be fail fast instead of trying to "recover". This
reverts the "recovery" behavior of
704ba4151e, but that was basically
a workaround for the fragility of `$NVIM_LISTEN_ADDRESS`.
This is a breaking change which will make refactor of typval and shada
code a lot easier. In particular, code that would use or check for
v:msgpack_types.binary in the wild would be broken. This appears to be
rarely used in existing plugins.
Also some cases where v:msgpack_type.string would be used to represent a
binary string of "string" type, we use a BLOB instead, which is
vimscripts native type for binary blobs, and already was used for BIN
formats when necessary.
msgpackdump(msgpackparse(data)) no longer preserves the distinction
of BIN and STR strings. This is very common behavior for
language-specific msgpack bindings. Nvim uses msgpack as a tool to
serialize its data. Nvim is not a tool to bit-perfectly manipulate
arbitrary msgpack data out in the wild.
The changed tests should indicate how behavior changes in various edge
cases.
Problem:
`vim.rpcnotify(0)` and `rpcnotify(0)` are documented as follows:
If {channel} is 0, the event is broadcast to all channels.
But that's not actually true. Channels must call `nvim_subscribe` to
receive "broadcast" events, so it's actually "multicast".
- Assuming there is a use-case for "broadcast", the current model adds
an extra step for broadcasting: all channels need to "subscribe".
- The presence of `nvim_subscribe` is a source of confusion for users,
because its name implies something more generally useful than what it
does.
Presumably the use-case of `nvim_subscribe` is to avoid "noise" on RPC
channels not expected a broadcast notification, and potentially an error
if the channel client reports an unknown event.
Solution:
- Deprecate `nvim_subscribe`/`nvim_unsubscribe`.
- If applications want to multicast, they can keep their own multicast
list. Or they can use `nvim_list_chans()` and `nvim_get_chan_info()`
to enumerate and filter the clients they want to target.
- Always send "broadcast" events to ALL channels. Don't require channels
to "subscribe" to receive broadcasts. This matches the documented
behavior of `rpcnotify()`.
Specifically, functions that are run in the context of the test runner
are put in module `test/testutil.lua` while the functions that are run
in the context of the test session are put in
`test/functional/testnvim.lua`.
Closes https://github.com/neovim/neovim/issues/27004.
- Test maparg() and maplist() in the same test.
- Use matches() instead of string.match().
- Avoid overlong lines and strange spacing in exec_lua().
- Revert code change from last PR as the variable may be needed.
Also close Nvim instance before removing log file, otherwise the Nvim
instance will still write to the log file.
Also adjust log level in libuv_process_spawn(). Ref #27660
Problem: Dialog for file changed outside of Vim not tested.
Solution: Add a test. Move FileChangedShell test. Add 'L' flag to
feedkeys().
5e66b42aae
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This is the first installment of a multi-PR series significantly
refactoring how highlights are being specified.
The end goal is to have a base set of 20 ish most common highlights,
and then specific files only need to add more groups to that as needed.
As a complicating factor, we also want to migrate to the new default
color scheme eventually. But by sharing a base set, that future PR
will hopefully be a lot smaller since a lot of tests will be migrated
just simply by updating the base set in place.
As a first step, fix the anti-pattern than Screen defaults to ignoring
highlights. Highlights are integral part of the screen state, not
something "extra" which we only test "sometimes". For now, we still
allow opt-out via the intentionally ugly
screen._default_attr_ids = nil
The end goal is to get rid of all of these eventually (which will be
easier as part of the color scheme migration)
Problem: Things that temporarily change/restore curwin/buf (e.g:
win_execute, some autocmds) may break assumptions that
curwin/buf is the cmdwin when "cmdwin_type != 0", causing
issues.
Solution: Expose the cmdwin's real win/buf and check that instead. Also
try to ensure these variables are NULL if "cmdwin_type == 0",
allowing them to be used directly in most cases without
checking cmdwin_type. (Sean Dewar)
Reset and save `cmdwin_old_curwin` in a similar fashion.
Apply suitable changes for API functions and add Lua tests.
988f74311c
Problem:
Not all Lua code is checked by stylua. Automating code-style is an
important mechanism for reducing time spent on accidental
(non-essential) complexity.
Solution:
- Enable stylua for entire `test/` directory.
- Exclude these high-churn files until this issue is resolved: https://github.com/JohnnyMorganz/StyLua/issues/829
```
test/functional/ui/decorations_spec.lua | 3560 ++++++++++++++++++++++++++++++++++++----------------
test/functional/ui/float_spec.lua | 5826 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
test/functional/ui/multigrid_spec.lua | 1349 ++++++++++++++------
```
- Make surgical changes to these files (or add `stylua: ignore` in some
small scopes) to improve the result:
```
test/functional/vimscript/msgpack_functions_spec.lua | 1414 +++++++++++++++------
test/functional/api/buffer_spec.lua | 1389 +++++++++++----------
test/functional/api/vim_spec.lua | 2740 +++++++++++++++++++++++-----------------
```
- These "high churn" files are NOT excluded because the changes are
largely an improvement:
```
test/functional/plugin/lsp_spec.lua | 2198 ++++++++++++++++++---------------
test/functional/plugin/shada_spec.lua | 4078 +++++++++++++++++++++++++++++++++++-------------------------
test/functional/ui/cmdline_spec.lua | 1199 +++++++++++-------
test/functional/ui/popupmenu_spec.lua | 1267 +++++++++++--------
test/functional/ui/messages_spec.lua | 1643 +++++++++++++++---------
```
- TODO: how to check "all directories"? With `GLOB_DIRS *` and `/.deps/` (or
`.deps/`) in `.styluaignore`, Lua code in `.deps/` is still checked...
Problem: `functional/vimscript/api_functions_spec` skips a test if the
runtime files are not generated, but this check was broken in a
refactor.
Solution: Since runtime files are now generated for all test targets, do
not skip this test.
This is the command invoked repeatedly to make the changes:
:%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g
Problem:
Since e057b38e70#20757 we support empty key in JSON encode/decode,
but we don't allow it in RPC object => Vim dict conversion. But empty
string is a valid key in Vim dicts and the msgpack spec.
Empty string key was disallowed in 7c01d5ff92 (2014) but that
commit/PR doesn't explicitly discuss it, so presumably it was a "seems
reasonable" decision (or Vimscript didn't allow empty keys until later).
Solution:
Remove the check in `object_to_vim()`. Note that
`tv_dict_item_alloc_len` will invoke `memcpy(…, 0)` but that's allowed
by the C spec: https://stackoverflow.com/a/3751937/152142
Problem:
Empty string is a valid JSON key, but json_decode() treats an object
with empty key as ":help msgpack-special-dict". #20757
:echo json_decode('{"": "1"}')
{'_TYPE': [], '_VAL': [['', '1']]}
Note: vim returns `{'': '1'}`.
Solution:
Allow empty string as an object key.
Note that we still (currently) disallow empty keys in object_to_vim() (since 7c01d5ff92):
f64e4b43e1/src/nvim/api/private/converter.c (L333-L334)Fix#20757
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This reverts commit fe30d8ccef.
The original commit intends to prevent heap-use-after-free with EXITFREE
caused by changedtick_di, which is no longer a problem.
Freeing buffers after freeing variables will cause heap-use-after-free
with EXITFREE when a partial is used as prompt callback.
Problem: Not easy to filter the output of maplist().
Solution: Add mode_bits to the dictionary. (Ernie Rael, closesvim/vim#10356)
d8f5f76621
Co-authored-by: Ernie Rael <errael@raelity.com>
Problem: It is not easy to restore saved mappings.
Solution: Make mapset() accept a dict argument. (Ernie Rael, closesvim/vim#10295)
51d04d16f2
Co-authored-by: Ernie Rael <errael@raelity.com>
Problem: maparg() does not indicate the type of script where it was defined.
Solution: Add "scriptversion".
a9528b39a6
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Problem: Vim9: in script cannot set item in uninitialized list.
Solution: When a list is NULL allocate an empty one. (closesvim/vim#8461)
e65081d1b5
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Problem:
Some tests fail with $SHELL=fish #6172
Related: https://github.com/neovim/neovim/pull/6176
Solution:
Replace "echo -n" with "printf", because "echo" in sh may be provided
as a shell builtin, which does not accept an "-n" flag to avoid a
trailing newline (e.g. on macos). "printf" is more portable (defined by
POSIX) and it does not output a trailing newline by itself.
Fixes#6172
TODO:
Other test failures may be related to "session leader" issue: https://github.com/neovim/neovim/issues/2354
Checked by running `:terminal ./build/bin/tty-test` from Nvim with
`shell=/bin/fish` (inherited from `$SHELL`) and it indeed complains
about "process does not own the terminal". With `shell=sh` it doesn't complain. And
unsetting `$SHELL` seems to make `nvim` to fall back to `shell=sh`.
FAILED test/functional/terminal/tui_spec.lua @ 1017: TUI paste: terminal mode
test/functional/terminal/tui_spec.lua:1024: Row 1 did not match.
Expected:
|*tty ready |
|*{1: } |
|* |
| |
|{5:^^^^^^^ }|
|{3:-- TERMINAL --} |
|{3:-- TERMINAL --} |
Actual:
|*process does not own the terminal |
|* |
|*[Process exited 2]{1: } |
| |
|{5:^^^^^^^ }|
|{3:-- TERMINAL --} |
|{3:-- TERMINAL --} |
To print the expect() call that would assert the current screen state, use
screen:snapshot_util(). In case of non-deterministic failures, use
screen:redraw_debug() to show all intermediate screen states.
stack traceback:
test/functional/ui/screen.lua:622: in function '_wait'
test/functional/ui/screen.lua:352: in function 'expect'
test/functional/terminal/tui_spec.lua:1024: in function <test/functional/terminal/tui_spec.lua:1017>
FAILED test/functional/terminal/tui_spec.lua @ 1551: TUI forwards :term palette colors with termguicolors
test/functional/terminal/tui_spec.lua:1567: Row 1 did not match.
Expected:
|*{1:t}ty ready |
| |
|* |
| |
|{2:^^^^^^^ }|
| |
|{3:-- TERMINAL --} |
Actual:
|*{1:p}rocess does not own the terminal |
| |
|*[Process exited 2] |
| |
|{2:^^^^^^^ }|
| |
|{3:-- TERMINAL --} |
To print the expect() call that would assert the current screen state, use
screen:snapshot_util(). In case of non-deterministic failures, use
screen:redraw_debug() to show all intermediate screen states.
stack traceback:
test/functional/ui/screen.lua:622: in function '_wait'
test/functional/ui/screen.lua:352: in function 'expect'
test/functional/terminal/tui_spec.lua:1567: in function <test/functional/terminal/tui_spec.lua:1551>