refactor(lua): add integer coercion helpers
Add vim._tointeger() and vim._ensure_integer(), including optional base
support, and switch integer-only tonumber()/assert call sites in the Lua
runtime to use them.
This also cleans up related integer parsing in LSP, health, loader, URI,
tohtml, and Treesitter code.
supported by AI
Problem:
In autocmd examples, using "args" as the event-object name is vague and
may be confused with a user-command.
Solution:
Use "ev" as the conventional event-object name.
Problem:
If NVIM_LOG_FILE, or the default fallback, is inaccessible (e.g.
directory is owned by root), users get confused.
Solution:
Show a warning when $NVIM_LOG_FILE or $XDG_STATE_HOME are inaccessible.
Also fix a latent memory leak: `os_mkdir_recurse` returns a uv error
code (int), but it was stored as `bool`, causing `os_strerror` to
receive an invalid error code and leak memory.
See: https://docs.libuv.org/en/v1.x/errors.html#c.uv_strerror
Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Problem:
In aec3d7915c Vim changed prompt-buffers
to respect 'modified' so the termdebug plugin can "control closing the
window". But for most use-cases (REPL, shell, AI "chat", …),
prompt-buffers are in practice always "modified", and no way to "save"
them, so *implicitly* setting 'modified' is noisy and annoying.
Solution:
Don't implicitly set 'modified' when a prompt-buffer is updated.
Plugins/users can still explicitly set 'modified', which will then
trigger the "E37: No write since last change" warning.
Problem:
No completionItem/resolve handler.
Solution:
If completeopt=popup is set, invoke completionItem/resolve when
a completion item is selected. Show resolved documentation in popup next
to the completion menu.
Problem:
When a terminal process exits, "[Process Exited]" text is added
to the buffer contents.
Solution:
- Return `exitcode` field from `nvim_get_chan_info`.
- Show it in the default 'statusline'.
- Show exitcode as virtual text in the terminal buffer.
Problem
The logic that clears codelenses beyond the buffer also removes the codelenses on the last line.
Solution
Do not clear the codelens on the last line.
Problem:
There is an inconsistency between extmarks/highlights regarding the
`end_col` param.
Solution:
Allow end_col=-1 to mean "end of line" (if strict=false).
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Problem: Documentation of `vim.pack.update()` contains a lot of text
inside nested list. This might be a bit confusing to parse for humans
and definitely confusing to parse for neovim.io.
The description of `vim.pack` directory is not correct for Windows.
Solution: Move description of confirmation buffer in a separate
"subsection".
Use '"data" standard path' instead of '$XDG_DATA_HOME/nvim' when
documenting directory. Also use `|standard-path|` tag to link to
standard path section instead of `|stdpath()|`.
Problem: Expanded cmdline is left open after entering the cmdline again
without entering a command that emits another message (after 301c7065).
Solution: Wait for msg_show to reinstate the vim.on_key() handler.
If there was no message close the expanded cmdline.
Problem: Prompts and message text (in block mode) in the cmdline are
parsed and highlighted as if it is Vimscript.
Entering the cmdline while it is expanded can work more like
it does with UI1, where the press enter prompt is replaced
and previous messages stay on the message grid, while
subsequent messages are placed below it.
Solution: Highlight manually with string parser on lines starting with ':'.
Spoof cmdline block mode when the cmdline is entered while it
is expanded.
Problem: Previous tests for this relied on other events opening the
targets, which are not guaranteed to happen.
Solution: Open target windows when entering a new tabpage.
Problem: nightly builds were always compared against HEAD, causing
false outdated warnings.
Solution: fetch both HEAD and refs/tags/nightly, match local commit
against HEAD first, fall back to nightly if no match.
Fix#38141
Hyphenated language names are silently dropped when used as injections
(see #38132).
This combines the normalization of language aliases into `resolve_lang`,
and also adds the normalization of hyphens to underscores, which allows
for handling of injected language tags with hyphens in their names.
Fixes#38132.
Problem: Unable to immediately open a typed command in the pager.
Solution: Support mapping msg_show "typed_cmd" trigger in
cfg.msg.targets (e.g. `targets = { typed_cmd = 'pager' }`).
Problem: During initial "bootstrap" via lockfile synchronization, the
whole plugin specification is reconstructed from the lockfile data,
ignoring potential user changes added in the first `vim.pack.add()`.
This is enough in most situations since it is the only data needed
for actual installation.
However, this affects specification passed to `PackChanged[Pre]`
events. In particular, `data` field is missing which can be a problem
if there is a `PackChanged kind=install` hook that uses that field
(like with some kind of `build` method used during install).
And there might be different `version` set in `vim.pack.add()`.
Solution: Pass the `specs` input of the first `vim.pack.add()` down to
lockfile synchronization and use it to reconstruct plugin
specification for the to-be-installed plugin. If present among the
user's `specs`, it is used but with forced `src` from the lockfile (as
it is the one used during installation).
Note that this still has a caveat when using separate
`vim.pack.add()`, as only the specs from the first input (when the
lockfile synchronization happens) is taken into account.
Problem: nvim_win_get_config() does not return a window's "style".
Solution: always include it, and document `style=""`.
Always included so it can be used reciprocally with nvim_open_win() or
nvim_win_set_config(). (otherwise the config of a window with kWinStyleUnused
will not unset the kWinStyleMinimal style of another window if passed to
nvim_win_set_config, for example)
Problem: cannot display tabs for indentation
Solution: Add the "leadtab" value to the 'listchars' option to
distinguish between tabs used for indentation and tabs used
for alignment (HarshK97).
closes: vim/vim#190948526d32647
Co-authored-by: HarshK97 <harshkapse1234@gmail.com>
Problem:
The DSR wait warning causes any test that involves Nvim TUI to become
flaky on Windows. Example:
FAILED test/functional/terminal/cursor_spec.lua @ 367: :terminal cursor can be positioned arbitrarily
test/functional/terminal\cursor_spec.lua:377: Row 1 did not match.
Expected:
|*^ |
|*~ |
|*~ |
|*~ |
|*~ |
|* |
|{5:-- TERMINAL --} |
Actual:
|* |
|* |
|*{2: }|
|*{103:defaults.lua: Did not detect DSR response from ter}|
|*{103:minal. This results in a slower startup time. }|
|*{UNEXPECTED foreground = tonumber('0x000006'):Press ENTER or type command to continue^ }|
|{5:-- TERMINAL --} |
Solution:
Don't show the DSR wait warning when running tests.
Problem: Color completion items display as plain text without visual preview
Solution: Parse RGB/hex colors from documentation and render with colored symbol ■
Problem: Unable to configure message targets based on message kind.
Solution: Add cfg.msg.targets mapping message kinds to "cmd/msg/pager".
Check the configured target when writing the message.
cfg.msg = { target = 'cmd', targets = { progress = 'msg', list_cmd = 'pager' } }
will for example use the 'msg' target for progress messages,
immediately open the pager for 'list_cmd' and use the cmdline
for all other message kinds.
Problem:
Descriptions of plugins often contain taglinks which are generally
concealed. This misaligns them by 2 characters with descriptions that
don't have a taglink in them.
Solution:
Don't count "bar" characters (`|`) for the description width.
Example:
Actual buffer content:
```
myplugin.txt |lsp| is cool
myplugin.txt this is a nice plugin
```
Rendered as:
```
myplugin.txt lsp is cool
myplugin.txt this is a nice plugin
```
Problem:
vim.fs.joinpath treats empty string as a path segment
(it adds a path separator for each empty item):
print(vim.fs.joinpath('', 'after/lsp', '')) -- '/after/lsp/'
print(vim.fs.joinpath('', '')) -- '/'
Especially problematic if the empty segment is the first segment, as
that converts the path to an absolute path.
Solution:
Ignore empty (length of 0) path segments.
Benchmark:
local function test(func)
local t = vim.uv.hrtime()
for _ = 1, 100000, 1 do
func('', 'this/is', 'a/very/long/path', '', 'it', 'really', 'is')
end
print(math.floor((vim.uv.hrtime() - t) / 1e6), 'ms')
end
- with Iter():filter() --> 370 ms
- building new segments table --> 208 ms
- with vim.tbl_filter --> 232 ms
- Instead of gsub split on `/` in all parts --> 1870 ms
Problem:
Automatic background detection sets the background option too late,
which loads colorschemes twice and causes problems when the user's
terminal background doesn't match the default (#32109, #36211, #36416).
Solution:
Use a DA1 query to determine whether the TTY supports OSC 11. Wait for
background detection and setting to complete before processing user
config.
Note: To preserve the existing behavior as much as possible, this triggers
OptionSet manually on VimEnter (since it won't trigger automatically if
we set bg during startup). However, I'm unsure if this behavior is
truly desired given that the documentation says OptionSet is triggered
"After setting an option (except during |startup|)."
Also fixes flickering issue #28667. To check for flickering:
nvim --clean --cmd "set termguicolors" --cmd "echo \"foo\"" --cmd "sleep 10"
On master, this gives me a black screen for 10 seconds, but on this
branch, the background is dark or light depending on the terminal
background (since the option is now set during startup rather than after
VimEnter).
Problem:
Regression from b99cdd0:
Pull diagnostics (from `textDocument/diagnostic`) and push diagnostics
(from `textDocument/publishDiagnostics`) use the same namespace, which
is a problem when using language servers that publish two different sets
of diagnostics on push vs pull, like rust-analyzer (see
https://github.com/rust-lang/rust-analyzer/issues/18709#issuecomment-2551394047).
Solution:
Rename `is_pull` to `pull_id` which accepts a pull namespace instead of
just a boolean.
Problem: Not possible to know when a session will be loaded.
Solution: Add the SessionLoadPre autocommand (Colin Kennedy).
fixes: vim/vim#19084closes: vim/vim#193061c0d468d72
Co-authored-by: Colin Kennedy <colinvfx@gmail.com>
Problem:
If a server is slow with catching up, there can be stale diagnostics
for deleted lines. Then if a user uses `jump` it can error like:
E5108: Lua: ...runtime/lua/vim/diagnostic.lua:670: attempt to index a nil value
stack traceback:
...runtime/lua/vim/diagnostic.lua:670: in function 'get_logical_pos'
...runtime/lua/vim/diagnostic.lua:687: in function 'diagnostic_lines'
...runtime/lua/vim/diagnostic.lua:1122: in function 'next_diagnostic'
...runtime/lua/vim/diagnostic.lua:1665: in function 'jump'
Solution:
Fallback to diagnostic location. That's better than the failure.
Problem: Timer removing a message from the msg buffer does not remove
empty lines if window is closed (col([ui.wins.msg]) fails).
Solution: Use nvim_buf_get_text() to check if line is empty.