Commit Graph

750 Commits

Author SHA1 Message Date
Justin M. Keyes
ed832b9ddf refactor(test): rename alter_slashes, invert its behavior
- `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.
2024-09-09 12:23:54 +02:00
vanaigr
d1d7d54680
fix(api): nvim_buf_get_text() crashes with large negative column #28740
Problem:
crash when calling nvim_buf_get_text() with a large negative start_col:

    call nvim_buf_get_text(0, 0, -123456789, 0, 0, {})

Solution:
clamp start_col after subtracting it from the line length.
2024-09-03 06:01:42 -07:00
bfredl
cfdf68a7ac feat(mbyte): support extended grapheme clusters including more emoji
Use the grapheme break algorithm from utf8proc to support grapheme
clusters from recent unicode versions.

Handle variant selector VS16 turning some codepoints into double-width
emoji. This means we need to use ptr2cells rather than char2cells when
possible.
2024-08-30 11:49:09 +02:00
zeertzjq
a8fbe1d409
fix(decor): don't use separate DecorSignHighlight for url (#30096) 2024-08-20 08:20:19 +08:00
bfredl
7381f0a1d5
Merge pull request #29650 from ruuzia/fix_expression_parser_crash
fix: assert failure in VimL expression parser
2024-07-21 16:29:16 +02:00
bfredl
cbb46ac4fa
Merge pull request #28873 from luukvbaal/redraw
fix(api): alloc and draw cursor window in nvim__redraw
2024-07-21 16:04:59 +02:00
Luuk van Baal
89f9f168a5 fix(api): alloc and draw cursor window in nvim__redraw
Problem:  Unable to move cursor to recently opened window.
Solution: Make sure uninitialized window is drawn before trying to move
          the cursor to it.
2024-07-20 14:53:42 +02:00
Luuk van Baal
012db2b0f5 fix(marks): revalidate marks whose position did not change
Problem:  Marks whose position did not change with the action that
          invalidated them (right_gravity = false) are not revalidated
          upon undo.
Solution: Remove early return when restoring a marks saved position so
          that it is still revalidated. Add "move" guards instead.
2024-07-20 14:52:39 +02:00
Rustum Zia
6720bd440f fix: assert failure in VimL expression parser 2024-07-17 23:37:59 -04:00
Amit Singh
970a27927e
fix(lua)!: do not use typed table for empty dict
Problem:
Empty dictionaries are converted into typed tables of the form `{ [true]
= 6}` instead of an empty dictionary representation `{}`. This leads to
incorrect table representation, along with failure in JSON encoding of
such tables as currently tables with only string and number type keys
can be encoded.

Solution:
The typed table logic has been removed from `nlua_push_Dictionary`. The
typed table logic is required only for float value conversions which is
already handled in `nlua_push_Float`. So, it is(was) no longer required
here.

Fixes neovim/neovim#29218
2024-07-13 16:42:28 +05:30
dundargoc
aa6b9c677d refactor: use vim._with where possible
This mostly means replacing `nvim_buf_call` and `nvim_win_call` with
`vim._with`.
2024-06-28 19:58:31 +02:00
bfredl
bda63d5b97 refactor(typval)!: remove distinction of binary and nonbinary strings
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.
2024-06-27 11:04:04 +02:00
Luuk van Baal
ad70c9892d feat(column)!: rework 'statuscolumn' %r/l items
Problem:  A custom 'statuscolumn' needs to check a bunch of options and
          placed signs to replicate the default number column.
Solution: Rework %l item to include the necessary logic to mimic the
          default number column. Remove now redundant %r item.
2024-06-16 19:04:34 +02:00
bfredl
fb43741f80 refactor(tests): use more global highlight definitions 2024-05-26 09:22:20 +02:00
Tobias Schmitz
ad191be65e
feat(signs)!: place higher-priority signs from the left #27781
Problem:
Higher-priority signs may be hidden by lower-priority signs.

Solution:
Place higher-priority signs from the left.

Example:

    nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='H', priority=1})
    nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='W', priority=2})
    nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='E', priority=3})

Before:

            |     |
          H | W E |
          ^ |     |
Not visible

After:

  |     |
  | E W | H
  |     | ^
          Not visible

Fixes #16632
2024-05-21 09:21:42 -07:00
Justin M. Keyes
aec4938a21
feat(api): broadcast events to ALL channels #28487
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()`.
2024-05-17 07:37:39 -07:00
zeertzjq
4e5c633ed4
fix(api): make getting explicit empty hl in virtual text work (#28697) 2024-05-12 05:39:33 +08:00
zeertzjq
d44ed3a885
perf(extmarks): better track whether namespace has extmarks (#28615)
This avoids redraw when adding/removing an empty namespace for a window.

This also avoids marktree traversal when clearing a namespace that has
already been cleared, which is added as a benchmark.
2024-05-03 18:02:25 +08:00
luukvbaal
cf9f002f31
fix(api): use correct buffer for "range" in nvim__redraw (#28614) 2024-05-03 10:35:32 +08:00
Luuk van Baal
037ea6e786 feat(api): add nvim__redraw for more granular redrawing
Experimental and subject to future changes.
Add a way to redraw certain elements that are not redrawn while Nvim is waiting
for input, or currently have no API to do so. This API covers all that can be
done with the :redraw* commands, in addition to the following new features:
- Immediately move the cursor to a (non-current) window.
- Target a specific window or buffer to mark for redraw.
- Mark a buffer range for redraw (replaces nvim__buf_redraw_range()).
- Redraw the 'statuscolumn'.
2024-05-02 15:57:06 +02:00
Will Hopkins
16513b3033
feat(api): allow floats to be opened in non-current tabpage (#28480)
\
2024-04-25 09:14:05 +08:00
dundargoc
052498ed42 test: improve test conventions
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.
2024-04-23 18:17:04 +02:00
luukvbaal
344906a08f
fix(api): do not update grid position in nvim_win_set_cursor (#28235)
Revert commit c971f538ab.
Forcing grid cursor position will need a new API like originally proposed in #27858.
2024-04-21 08:15:18 +08:00
zeertzjq
329fc0e5b7
test: API can return Lua function to Lua code (#28380) 2024-04-17 06:34:10 +08:00
zeertzjq
f150b62423
fix(lua): only free luarefs when returning from API (#28373) 2024-04-17 05:44:06 +08:00
zeertzjq
5cfdaaaeac
fix(api): ignore 'autochdir' when renaming other buf (#28376)
Problem:  Renaming non-current buffer changes working directory when
          'autochdir' is set.
Solution: Temporarily disable 'autochdir'.  Add more tests for the
          win_set_buf change.
2024-04-16 20:57:01 +08:00
Raphael
2fc2343728
fix(api): ignore 'autochdir' when setting buf in other win (#28371)
Problem:  Wrong working directory when setting buffer in another window with
          'autochdir' enabled.
Solution: Temporarily disable 'autochdir'.
2024-04-16 19:49:56 +08:00
zeertzjq
7fa24948a9
test: make mapping tests more consistent (#28368)
- 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.
2024-04-16 14:05:09 +08:00
zeertzjq
47ba96a6b3
test: getting autocmd Lua callback in Vimscript (#28367)
Also remove unnecessary variable in API converter.
2024-04-16 11:59:55 +08:00
zeertzjq
4ec8fd43bf
fix(api): make width/height for split by nvim_open_win work (#28341) 2024-04-15 17:55:57 +08:00
Sean Dewar
7180ef6901
feat(api)!: nvim_open_win: noautocmd blocks all autocmds #28192
Problem: noautocmd is confusing; despite its name, it doesn't block all
autocommands (instead it blocks only those related to setting the buffer), and
is commonly used by plugins to open windows while producing minimal
side-effects.

Solution: be consistent and block all autocommands when noautocmd is set.
This includes WinNew (again), plus autocommands from entering the window (if
enter is set) like WinEnter, WinLeave, TabEnter, .etc.

See the discussion at https://github.com/neovim/neovim/pull/14659#issuecomment-2040029517
for more information.

Remove win_set_buf's noautocmd argument, as it's no longer needed.

NOTE: pum_create_float_preview sets noautocmd for win_set_buf, but all its
callers already use block_autocmds.

Despite that, pum_create_float_preview doesn't actually properly handle
autocommands (it has no checks for whether those from win_enter or
nvim_create_buf free the window).

For now, ensure autocommands are blocked within it for correctness (in case it's
ever called outside of a block_autocmds context; the function seems to have been
refactored in #26739 anyway).
2024-04-14 16:10:16 -07:00
Lewis Russell
81fc27124b refactor(test): inject after_each differently 2024-04-10 15:53:50 +01:00
dundargoc
7035125b2b test: improve test conventions
Work on https://github.com/neovim/neovim/issues/27004.
2024-04-08 22:51:00 +02:00
zeertzjq
ae28ef327e
fix: adjust error message for error in UI event callback (#28200)
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
2024-04-06 11:18:43 +08:00
zeertzjq
5581a90e20
test: reduce sleep for file timestamp change (#28196)
Now that Nvim always supports nanotime, sleeping for some milliseconds
is enough.
2024-04-06 08:59:50 +08:00
dundargoc
e016f5bee6 test: reduce exec_lua calls
`exec_lua` makes code slighly harder to read, so it's beneficial to
remove it in cases where it's possible or convenient.

Not all `exec_lua` calls should be removed even if the test passes as it
changes the semantics of the test even if it happens to pass.

From https://github.com/neovim/neovim/pull/28155#discussion_r1548185779:

"Note for tests like this, which fundamentally are about conversion, you
end up changing what conversion you are testing. Even if the result
happens to be same (as they often are, as we like the rules to be
consistent if possible), you are now testing the RPC conversion rules
instead of the vim script to in-process lua conversion rules."

From https://github.com/neovim/neovim/pull/28155#discussion_r1548190152:

"A test like this specifies that the cursor is valid immediately and not
after a separate cycle of normal (or an other input-processing) mode."
2024-04-04 13:10:11 +02:00
dundargoc
77d3526a3d fix: explain that user should run nvim with -V1 to see more information
It's not obvious for users how to figure out where a mapping is set from
only "Last set from Lua".
2024-03-30 12:32:47 +01:00
zeertzjq
35239e977f
test: use matches(...) instead of ok(string.find(...)) (#28111) 2024-03-30 09:29:21 +08:00
bfredl
0c59771e31 refactor(tests): all screen tests should use highlights
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)
2024-03-23 13:44:35 +01:00
bfredl
8921d56053 fix(rpc): do not crash when no input is consumed
fixes #23781

Co-authored-by: glacambre <code@lacamb.re>
2024-03-21 15:52:28 +01:00
Sean Dewar
6091df6b7a
fix(api): nvim_create_buf assert fails if autocmds set &swapfile
Problem: assertion failure in nvim_create_buf if buflist_new autocommands open
a swapfile when "scratch" is set.

Solution: block autocommands when setting up the buffer; fire them later
instead.

Note that, unlike buflist_new, I don't check if autocommands aborted script
processing; the buffer is already created and configured at that point, so might
as well return the handle anyway.

Rather than repeat try_{start,end} and {un}block_autocmds for each relevant
operation, just do it at the start and near the end. This means that, if
TermResponse fires from unblock_autocmds for whatever reason, it can see the
buffer in an already configured state if we didn't bail due to an error (plus
it's probably a bit cleaner this way).
2024-03-19 16:13:52 +00:00
Sean Dewar
d5c23d72a5
fix(api): nvim_create_buf leaks memory if buffer is loaded early
Problem: memory leak in nvim_create_buf if buflist_new autocommands load the
new buffer early.

Solution: do not open a memfile in that case.
2024-03-19 15:43:08 +00:00
Luuk van Baal
c971f538ab fix(api): update grid cursor in nvim_win_set_cursor()
Problem:  Cursor position set by nvim_win_set_cursor() is not reflected
          on the screen when followed by a blocking call like getchar().
Solution: Immediately update the cursor position on the grid.
2024-03-15 09:15:50 +01:00
bfredl
fc2a56fe61 fix(api): fix set_lines viewport adjustment, but this time good
fixes #27720
2024-03-14 10:56:24 +01:00
bfredl
08fc1ebbaa fix(api/buffer): fix handling of viewport of non-current buffer
A lot of functions in move.c only worked for curwin, alternatively
took a `wp` arg but still only work if that happens to be curwin.

Refactor those that are needed for update_topline(wp) to work
for any window.

fixes #27723
fixes #27720
2024-03-13 07:19:59 +01:00
zeertzjq
1da0f3494e
test: correct order of arguments to eq() (#27816) 2024-03-11 22:23:14 +08:00
Sean Dewar
b52d15853e
fix(api): win_set_config set tp_curwin of win moved from other tabpage
Problem: nvim_win_set_config does not update the tp_curwin of win's original
tabpage when moving it to another.

Solution: update it if win was the tp_curwin. Add a test.
2024-03-09 18:00:30 +00:00
Sean Dewar
54022a2946
fix(api): win_set_config update statuslines after removing splits
Problem: nvim_win_set_config does not update statuslines after removing a split.

Solution: call last_status.

Didn't realize this was missing in the original nvim_win_set_config for splits
PR.

As it can only be done for the current tabpage, do it if win_tp == curtab;
enter_tabpage will eventually call last_status anyway when the user enters
another tabpage.
2024-03-09 01:00:33 +00:00
Sean Dewar
e7c262f555
fix(api): patch some cmdwin/textlock holes
Problem: there are new ways to escape textlock or break the cmdwin in
nvim_win_set_config and nvim_tabpage_set_win.

Solution: fix them. Use win_goto to check it in nvim_tabpage_set_win and use the
try_start/end pattern like with similar functions such as nvim_set_current_win
(which uses the existing msg_list, if set).

Careful not to use `wp->handle` when printing the window ID in the error message
for nvim_tabpage_set_win, as win_goto autocommands may have freed the window.

On a related note, I have a feeling some API functions ought to be checking
curbuf_locked...
2024-03-08 23:24:06 +00:00
Sean Dewar
d942c2b943
fix(api): handle win_split_ins failure properly
Problem: nvim_win_set_config does not handle failure in win_split_ins properly
yet, which can cause all sorts of issues. Also nvim_open_win and
nvim_win_set_config do not set the error message to the one from win_split_ins.

Solution: handle failure by undoing winframe_remove, like in win_splitmove.
Make sure autocommands from switching to the altwin fire within a valid window,
and ensure they don't screw things up. Set the error message to that of
win_split_ins, if any.

Also change a few other small things, including:

- adjust win_append to take a tabpage_T * argument, which is more consistent
  with win_remove (and also allows us to undo a call to win_remove).

- allow winframe_restore to restore window positions. Useful if `wp` was in a
  different tabpage, as a call to win_comp_pos (which only works for the current
  tabpage) after winframe_restore should no longer be needed.

  Though enter_tabpage calls win_comp_pos anyway, this has the advantage of
  ensuring w_winrow/col remains accurate even before entering the tabpage
  (useful for stuff like win_screenpos, if used on a window in another tabpage).

  (This change should probably also be PR'd to Vim later, even though it doesn't
  use winframe_restore for a `wp` in a different tabpage yet).
2024-03-08 23:24:05 +00:00