Problem:
- With `clipboard=unnamed[plus]`, per-cursor yanks are joined into '"'
on exit, but not the clipboard.
- Multicursor `"+yy` calls the clipboard provider per-cursor, behaving
as "last wins".
Solution:
- Never cascade to/from the clipboard provider.
- Implicit clipboard (`clipboard=unnamed[plus]`) uses the cursor-local
unnamed register, so the cascade needs no `start_batch_changes()`. On
exit, the clipboard gets the same joined result as the `"` register.
- Operations that reference the explicit clipboard registers `"+` / `"*`
while multicursor is active, use the cached (primary) clipboard value.
Problem: Watcher failures are reported inconsistently, and callers
cannot detect when a watcher is no longer usable.
Solution: Route startup and event failures and unexpected inotifywait
exits through an optional on_error callback. Log to nvim-watch.log by
default. Ignore disappearing child directories and exits caused by
cancellation. Let LSP log failures and notify once per message, using
INFO for missing roots and ERROR otherwise, without interrupting
registration.
AI-assisted
Problem: In Virtual Replace mode, backspacing over a character that
replaced several multi-byte characters deletes the padding
that follows it, so the text after the cursor loses its
alignment.
Solution: In replace_do_bs() advance by the length of the character at
the current offset instead of always measuring the first
restored character (Volodymyr Chernetskyi).
After the original characters are restored, replace_do_bs() adds up
their screen width so it knows how much of the alignment padding to drop
again. The loop advanced "i" by mb_ptr2len(p) - 1, which always returns
the length of the *first* restored character rather than the length of
the character at the offset being looked at.
One backspace can restore more than one character, because a wide
character may have replaced several narrow ones. When those characters
do not all have the same byte length the index lands in the middle of a
character: chartabsize() then measures a trailing byte, counts it as an
unprintable <xx> worth four cells, and the inflated width makes the
following loop delete padding spaces that should have been kept.
call setline(1, 'aé xyz')
call feedkeys("gR\u4e00\<BS>\e", 'xt')
leaves "aéxyz" instead of restoring the original line. Going the other
way round ('éa') happens to work, since there the first character is the
longer one.
This has been wrong since the loop was added in Vim 7.0.
closes: vim/vim#212115d934b1bdb
Co-authored-by: Volodymyr Chernetskyi <19735328+chernetskyi@users.noreply.github.com>
Problem: vim_strbyte() can be improved
Solution: Replace the byte-by-byte scan in vim_strbyte() with strchr(),
preserving its byte-range and NUL behavior (Yasuhiro Matsumoto).
closes: vim/vim#21240df4ef959d5
Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Problem:
A Visual-mode mapping that creates cursors (`xmap I Q0i`) replays its
commands only if cursors already existed when it started.
Solution:
Always collect `composite`. Consumers are still decided per frame
(`CmdFrame.consumers`) and at emit/cascade.
- call-non-callable
- missing-fields
- redefined-label
- redefined-local
- undefined-field
- unreachable-code
Promote redefined-local and unreachable-code to warnings.
Fix DOS line-ending handling for multiline semantic tokens, and support
intersection types in the help parser.
AI-assisted
Problem: matchfuzzypos() can be improved
Solution: Compute the uppercase character once per character in
has_match(), instead of repeating the conversion while
scanning each candidate (Yasuhiro Matsumoto).
closes: vim/vim#21241c0c3fbd967
Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Problem: CursorLineFold and CursorLineSign are only applied when
'cursorlineopt' contains "number" or is "both"
(Evgeni Chasnovski).
Solution: Apply those groups whenever 'cursorline' is set, independent
of 'cursorlineopt' (Vrushali Zampalkar).
fixes: vim/vim#20480closes: vim/vim#211121f8d3c44c5
Co-authored-by: Vrushali-Z <zampalkarvasu@gmail.com>
Problem: Netrw raises E46 when changing directory fails.
Solution: Remove unused assignments to the read-only directory argument
and cover both error-handling branches with a regression test
(Qiming zhao).
When :lcd fails with E472, s:NetrwLcd() assigns to a:newdir instead of
returning -1. The fallback assignment also refers to dirname, which is
undefined on this path. Neither assignment can update the caller's
directory variable. Keep the existing option restoration and failure
return while removing the invalid assignments.
Supported by AI.
closes: vim/vim#212262f72e4c72f
Co-authored-by: Qiming zhao <chemzqm@gmail.com>
Problem: With 'regexpengine' set to 1 a case-insensitive match against
a literal string fails when the string starts with a
multi-byte character that is longer than a character following
it, so the two regexp engines disagree (after v9.1.0645).
Solution: In cstrncmp() advance by the length of the character at the
current position instead of always measuring the first
character of "s1" (Volodymyr Chernetskyi).
cstrncmp() walks "s1" to find how many characters make up "*n" bytes, so
that it can measure out the same number of characters in "s2". The loop
decremented the remaining byte count by mb_ptr2len(s1), which always
returns the length of the *first* character, rather than the length of
the character at the current position "p".
When the first character is longer than a later one the byte count runs
out too early, the character count comes up short, and MB_STRNICMP2() is
handed a length for "s2" that is too small, so the comparison fails. For
example matching "\cüber" against "Überraschung": "über" is five bytes,
but each iteration subtracts two (the length of "ü"), so the loop runs
three times instead of four.
:set regexpengine=1
echo matchstr('Überraschung', '\cüber')
returns an empty string, while 'regexpengine' set to 2 correctly returns
"Über". The default value of 0 uses the NFA engine and is unaffected.
related: vim/vim#14756
closes: vim/vim#212124e5ac0d68a
This is a bit more boilerplate because of painful impedance mismatch (is
augroup names the root source of truth? is ids the source of truth? who
knows? what does truth even mean?), but show an error reflecting what
the caller actually tried (they passed in an invalid id, not a null
string)
context: vim_snprintf provides a "portable" replacement for a system
vsnprintf(). However we rely on system vsnprintf() in places. This
is quite arbitrary. I want to use system vsnprintf() only, and
reduce the machinery in string.c for typval printf only, which will
delet a lot of duplicated code.
The biggest hurdle here is not "portably" (we only support sane c
runtimes) but the following discrepancy: standard libc printf()
considers NULL args to %s to be undefined behavior strictly
while vim_snprintf() _defacto_ allows this by replacement to "[NULL]"
IMO, this should be seen as "graceful" error handling (nicer than crashing
on the user), not a valid means to have the string "[NULL]" intentionally
be shoved in the users face. more robust code should explicitly
check for NULL and replace it with a _appropriate_ fallback for
the situation, depending on what a NULL string actually means in the
context (unnamed buffer? anonymous namespace? global augroup?)
soo, this PR provides the most _gently_ incremental nudge towards
considering this case again as an error one could possible imagine.
If sanitizers are complied in, this minor incursion gets printed
into the sanitizers' log as a "report-and-continue" error with a
traceback. This doesn't annoy the end user or "stop the world"
in the test suite, but the CI will see the reported error and
fail the build, just like other non-fatal CI errors.
Problem:
A server that supports dynamic registration must not also declare
completionProvider at initialize, so server_capabilities.completionProvider
is nil for anything reading it directly.
Solution:
Do not advertise it by default. A client that follows a registration can
declare it itself.
Problem:
Scrolling a 'scrollbind' window whose peer has a virt_lines block
taller than the window makes the peer jump back and forth.
Solution:
After scrollup()/scrolldown(), sync w_scbind_pos to the actual
get_vtopline() when the target was not clamped to buffer bounds.
Ref: esmuellert/codediff.nvim#519
AI-assisted
Problem:
Type hierarchy (#28388, #28467) and `workspace/executeCommand` (#11607) are
implemented, but `textDocument.typeHierarchy` and `workspace.executeCommand`
are missing from `make_client_capabilities()`.
Solution:
Declare both capabilities.
AI-assisted
"vim.pot" file and tasks are N/A.
"clean" task is N/A after migrating to CMake.
N/A patches:
- 59bd74ed4c9ab366182c93bdc430b186729abbad
- 5d552d652b0197063565ab937d30f92a9ed28545
- 3c8d32e4fc17b4b38b17d7c039ee6203d1b01078
Problem:
The eol_offset used to decode multiline semantic tokens is computed as
vim.bo.fileformat[bufnr] == 'dos' and 2 or 1
which indexes the option value rather than the buffer, so it is never
"dos" and the offset is always 1. A token that crosses a line boundary
in a 'fileformat' of "dos" is then decoded one code unit short per line
ending, and the highlight extends past the end of the token.
Solution:
Read the option with the buffer-scoped form, vim.bo[bufnr].fileformat.
The existing multiline test covers both formats now. Its token length of
82 counts the line endings it spans, so the same token reaches four
characters less far once the buffer is "dos".
AI-assisted
Problem:
vim.lsp.util.show_document() can fail to load the target buffer, most
visibly with E325 when another process owns the file's swapfile and the
user declines to open it. The Vim error escapes show_document() and
surfaces inside whichever LSP handler called it, instead of being
reported as a failure to show the document.
Solution:
Load the buffer up front with vim.fn.bufload(), before any of that
state is touched, and report the error instead of raising.
AI-assisted
Problem: LuaLS struggles with the generics used in Nvim's runtime,
requiring broad diagnostic suppressions. Indexing is also slow.
Solution: Use EmmyLua for type checks in the build and CI. It offers
more sophisticated type checking, substantially better support for
generics, and much better flow analysis.
Correct the affected annotations. Use `@internal`, supported directly by
EmmyLua, instead of `@nodoc` for shared internal declarations, and
support it in the help parser.
AI-assisted
Problem: K on generic and nullable type annotations can jump to the
wrong help tag. Generated See references repeat the type names.
Solution: Strip generic arguments and nullable suffixes when resolving
help tags. Remove the redundant generated See references.
AI-assisted
Problem:
dynamicRegistration is declared false, and completionProvider is read
from server_capabilities only.
Solution:
Declare it, and prefer registerOptions per field.
Problem:
The LSP client excludes paths such as Git objects and installed
dependencies from file watching. However, watchdirs() still traverses
these subtrees before filtering which directories receive watchers,
paying the filesystem and Lua traversal cost for excluded content.
Solution:
Prune excluded subdirectories during the initial walk, and document
that excluding a directory also excludes its descendants.
Using the LSP client's existing **/node_modules/*/** exclusion on a
synthetic macOS tree with 100 installed packages and 4,000 files:
Before After
Directory scans 503 103
Entries inspected 4502 202
Directory watchers 103 103
The measurements use real filesystem calls and watcher handles, with
identical watcher paths for this exclusion.
Ref: #23291
AI-assisted
Problem:
msgpack#strptime() finds a timestamp by bisecting strftime() output, and
brackets the search with the extreme UTC offsets. The lower bound
subtracts 12 hours, but -12:00 is the westernmost offset, which produces
the *largest* timestamp for a given local time. The easternmost offset
is +14:00, so in any zone east of UTC+12 the search can start above the
target and the function throws:
internal-start-string:Internal error: start > string
With TZ=GMT-14, four of the five timestamps in msgpack_spec.lua fail,
as do three tests in shada_spec.lua, which reaches the same function
through shada#strings_to_sd().
Solution:
Subtract 14 hours instead. The upper bound is already generous enough at
+14, and widening a bisection bracket downwards cannot change the result
in zones that worked before.
The test disables the python3 provider, because msgpack#strptime() only
uses the Vimscript implementation changed here when no provider answers,
and otherwise hands the work to datetime.strptime().
AI-assisted
Problem: vim.pack uses a private async implementation even though
vim.async is now available.
Solution: Remove the private implementation and run plugin operations in
structured task scopes. Bound parallel work with semaphores and use
protected awaits so cancellation still propagates.
AI-assisted
Problem: Spup syntax fails for an out-of-range comment mode.
Solution: Add the missing let to the fallback assignment (Qiming zhao).
Setting oneline_comments above 3 raises E492 while loading the syntax
script. Use a valid legacy Vim script assignment to restore the default
value of 2.
Validated with oneline_comments set to 1, 2, 3, 4 and 99, and with the
variable unset. The original script fails with E492 for a value of 4.
The corrected script loads and applies the expected comment mode.
closes: vim/vim#21227
Supported by AI.
22b72dca7e
Co-authored-by: Qiming zhao <chemzqm@gmail.com>
Problem:
A Visual-mode mapping that leaves Visual mode ("xmap I Q0i") does not
replay its motions/edits at the extra cursors, though an insert session
it starts does.
atom_map_start() skips while Visual is active, so the mapping has no
`composite`, and atom_capturable() then rejects its commands.
Solution:
Open the `composite` for Visual-mode mappings too.
Bonus: the mapping atom is now reported as:
before: type=visual, keys="viwcFOO<Esc>"
after: type=mapping, keys="viwc<Esc>iFOO<Esc>", lhs=",c"
Problem:
TSHighlighter._on_conceal_line() parses with the range { row, row }. A
Range2 has an exclusive end, so that is the empty range, and no injected
region ever intercepts it.
The root tree is parsed regardless, because its region is empty, so only
injections are affected: conceal_lines metadata coming from an injected
language's highlights query is dropped. on_range_impl() then records the
row in _conceal_checked, so the miss persists until the buffer changes.
For a markdown code block nested in a markdown code block, the inner
fence delimiters stay visible and nvim_win_text_height() reports 5 rows
where 3 are displayed.
Solution:
Pass the one-row range, as the on_range_impl() call below already does.
AI-assisted
Problem:
A Visual selection opened programmatically (`:normal! viw`) is not
previewed at the other cursors, and a user-typed operator completing it
does not cascade.
":normal" keys run as child frames, which are never user input, so the
session they build was classified "fed" once and never revisited.
Solution:
Recalculate the session kind (`vatom.state`) on every frame. Record
`vatom.frame` (the last frame to add to the session) so an enclosing
frame does not reset or recapture it.
Problem:
cmd_on_key() tests the key it was handed against the literal string
'<MouseMove>', but at that point "typed" still holds raw key bytes. Thus
the comparison never holds and the branch its own comment describes
is dead. Moving the mouse over an expanded cmdline collapses it.
Solution:
Translate the key once, up front, so every comparison in the function
sees the same form.
AI-assisted
Problem:
The #has-parent? predicate indexes the result of node:parent() without
checking it, so a capture that matches a tree's root node raises
query.lua:600: attempt to index a nil value
instead of simply not matching. In a highlights query that breaks
highlighting for the whole buffer. The sibling #has-ancestor? predicate
handles the same situation.
Solution:
Treat a missing parent as "does not match".
AI-assisted