aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
Commit message (Collapse)AuthorAge
...
* refactor(typval)!: remove distinction of binary and nonbinary stringsbfredl2024-06-27
| | | | | | | | | | | | | | | | | | | | | 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.
* feat(column)!: rework 'statuscolumn' %r/l itemsLuuk van Baal2024-06-16
| | | | | | | 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.
* refactor(tests): use more global highlight definitionsbfredl2024-05-26
|
* feat(signs)!: place higher-priority signs from the left #27781Tobias Schmitz2024-05-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* feat(api): broadcast events to ALL channels #28487Justin M. Keyes2024-05-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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()`.
* fix(api): make getting explicit empty hl in virtual text work (#28697)zeertzjq2024-05-12
|
* perf(extmarks): better track whether namespace has extmarks (#28615)zeertzjq2024-05-03
| | | | | | 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.
* fix(api): use correct buffer for "range" in nvim__redraw (#28614)luukvbaal2024-05-03
|
* feat(api): add nvim__redraw for more granular redrawingLuuk van Baal2024-05-02
| | | | | | | | | | | 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'.
* feat(api): allow floats to be opened in non-current tabpage (#28480)Will Hopkins2024-04-25
| | | \
* test: improve test conventionsdundargoc2024-04-23
| | | | | | | | | 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.
* fix(api): do not update grid position in nvim_win_set_cursor (#28235)luukvbaal2024-04-21
| | | | Revert commit c971f538ab87b537ae4c97bd44167661c5691a2d. Forcing grid cursor position will need a new API like originally proposed in #27858.
* test: API can return Lua function to Lua code (#28380)zeertzjq2024-04-17
|
* fix(lua): only free luarefs when returning from API (#28373)zeertzjq2024-04-17
|
* fix(api): ignore 'autochdir' when renaming other buf (#28376)zeertzjq2024-04-16
| | | | | | 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.
* fix(api): ignore 'autochdir' when setting buf in other win (#28371)Raphael2024-04-16
| | | | | Problem: Wrong working directory when setting buffer in another window with 'autochdir' enabled. Solution: Temporarily disable 'autochdir'.
* test: make mapping tests more consistent (#28368)zeertzjq2024-04-16
| | | | | | - 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.
* test: getting autocmd Lua callback in Vimscript (#28367)zeertzjq2024-04-16
| | | Also remove unnecessary variable in API converter.
* fix(api): make width/height for split by nvim_open_win work (#28341)zeertzjq2024-04-15
|
* feat(api)!: nvim_open_win: noautocmd blocks all autocmds #28192Sean Dewar2024-04-14
| | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* refactor(test): inject after_each differentlyLewis Russell2024-04-10
|
* test: improve test conventionsdundargoc2024-04-08
| | | | Work on https://github.com/neovim/neovim/issues/27004.
* fix: adjust error message for error in UI event callback (#28200)zeertzjq2024-04-06
| | | | | | 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
* test: reduce sleep for file timestamp change (#28196)zeertzjq2024-04-06
| | | | Now that Nvim always supports nanotime, sleeping for some milliseconds is enough.
* test: reduce `exec_lua` callsdundargoc2024-04-04
| | | | | | | | | | | | | | | | | | | | | `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."
* fix: explain that user should run nvim with -V1 to see more informationdundargoc2024-03-30
| | | | | It's not obvious for users how to figure out where a mapping is set from only "Last set from Lua".
* test: use matches(...) instead of ok(string.find(...)) (#28111)zeertzjq2024-03-30
|
* refactor(tests): all screen tests should use highlightsbfredl2024-03-23
| | | | | | | | | | | | | | | | | | | | | | | 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)
* fix(rpc): do not crash when no input is consumedbfredl2024-03-21
| | | | | | fixes #23781 Co-authored-by: glacambre <code@lacamb.re>
* fix(api): nvim_create_buf assert fails if autocmds set &swapfileSean Dewar2024-03-19
| | | | | | | | | | | | | | | | | | 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).
* fix(api): nvim_create_buf leaks memory if buffer is loaded earlySean Dewar2024-03-19
| | | | | | | 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.
* fix(api): update grid cursor in nvim_win_set_cursor()Luuk van Baal2024-03-15
| | | | | | 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.
* fix(api): fix set_lines viewport adjustment, but this time goodbfredl2024-03-14
| | | | fixes #27720
* fix(api/buffer): fix handling of viewport of non-current bufferbfredl2024-03-13
| | | | | | | | | | | 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
* test: correct order of arguments to eq() (#27816)zeertzjq2024-03-11
|
* fix(api): win_set_config set tp_curwin of win moved from other tabpageSean Dewar2024-03-09
| | | | | | | 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.
* fix(api): win_set_config update statuslines after removing splitsSean Dewar2024-03-09
| | | | | | | | | | | | | 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.
* fix(api): patch some cmdwin/textlock holesSean Dewar2024-03-08
| | | | | | | | | | | | | | | 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...
* fix(api): handle win_split_ins failure properlySean Dewar2024-03-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* fix(api): make open_win block only enter/leave events if !enter && !noautocmdSean Dewar2024-03-08
| | | | | | | | | | | | | | | | | | | | | | Problem: nvim_open_win blocking all win_set_buf autocommands when !enter && !noautocmd is too aggressive. Solution: temporarily block WinEnter/Leave and BufEnter/Leave events when setting the buffer. Delegate the firing of BufWinEnter back to win_set_buf, which also has the advantage of keeping the timing consistent (e.g: before the epilogue in enter_buffer, which also handles restoring the cursor position if autocommands didn't change it, among other things). Reword the documentation for noautocmd a bit. I pondered modifying do_buffer and callees to allow for BufEnter/Leave being conditionally disabled, but it seems too invasive (and potentially error-prone, especially if new code paths to BufEnter/Leave are added in the future). Unfortunately, doing this has the drawback of blocking ALL such events for the duration, which also means blocking unrelated such events; like if window switching occurs in a ++nested autocmd fired by win_set_buf. If this turns out to be a problem in practice, a different solution specialized for nvim_open_win could be considered. :-)
* fix(api): make win_set_config with "win" for splits need "split/vertical"Sean Dewar2024-03-08
| | | | | | | | | | Problem: currently, for splits, nvim_win_set_config accepts win without any of split or vertical set, which has little effect and seems error-prone. Solution: require at least one of split or vertical to also be set for splits. Also, update nvim_win_set_config docs, as it's no longer limited to just floating and external windows.
* fix(api): make open_win/win_set_config check if splitting allowedSean Dewar2024-03-08
| | | | | | | | | | Problem: splitting is disallowed in some cases to prevent the window layout changes while a window is closing, but it's not checked for. Solution: check for this, and set the API error message directly. (Also sneak in a change to tui.c that got lost from #27352; it's a char* buf, and the memset is assuming one byte each anyway)
* fix(api): avoid open_win UAF if target buf deleted by autocmdsSean Dewar2024-03-08
| | | | | | | Problem: WinNew and win_enter autocommands can delete the target buffer to switch to, causing a heap-use-after-free. Solution: store a bufref to the buffer, check it before attempting to switch.
* fix(api): open_win fire Buf* events when !enter && !noautocmd if entered earlySean Dewar2024-03-08
| | | | | | | | | | | | | Problem: if switch_win{_noblock} fails to restore the old curwin after WinNew (e.g: it was closed), wp will become the new curwin, but win_set_buf enter events would still be blocked if !enter && !noautocmd. Solution: fire them, as we've actually entered the new window. Note: there's a problem of switch_win{_noblock} failing to restore the old curwin, leaving us in wp without triggering WinEnter/WinLeave, but this affects all callers of switch_win{_noblock} anyways. (It's also not clear how WinLeave can be called if the old curwin was closed already).
* fix(api): open_win fire BufWinEnter for other buffer when !enter && !noautocmdSean Dewar2024-03-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: BufWinEnter is not fired when not entering a new window, even when a different buffer is specified and buffer-related autocommands are unblocked (!noautocmd). Solution: fire it in the context of the new window and buffer. Do not do it if the buffer is unchanged, like :{s}buffer. Be wary of autocommands! For example, it's possible for nvim_win_set_config to be used in an autocommand to move a window to a different tabpage (in contrast, things like wincmd T actually create a *new* window, so it may not have been possible before, meaning other parts of Nvim could assume windows can't do this... I'd be especially cautious of logic that restores curwin and curtab without checking if curwin is still valid in curtab, if any such logic exists). Also, bail early from win_set_buf if setting the temp curwin fails; this shouldn't be possible, as the callers check that wp is valid, but in case that's not true, win_set_buf will no longer continue setting a buffer for the wrong window. Note that pum_create_float_preview also uses win_set_buf, but from a glance, doesn't look like it properly checks for autocmds screwing things up (win_enter, nvim_create_buf...). I haven't addressed that here. Also adds some test coverage for nvim_open_win autocommands. Closes #27121.
* fix(api): win_set_config fires unnecessary autocmdsSean Dewar2024-03-08
| | | | | | | | | | | | | | Problem: win_set_config should have the observable effect of moving an existing window to another place, but instead fires autocommands as if a new window was created and entered (and does not fire autocommands reflecting a "return" to the original window). Solution: do not fire win_enter-related autocommands when splitting the window, but continue to fire them when entering the window that fills the new space when moving a window to a different tabpage, as the new curwin changes. Also, remove "++once" from the WinEnter autocmd in the other test, as omitting it also crashed Nvim before this fix.
* fix(api): win_set_config autocmds crash when moving win to other tabpageSean Dewar2024-03-08
| | | | | | | | | | | | Problem: win_enter autocommands can close new_curwin, crashing if it was the last window in its tabpage after removing win, or can close parent, crashing when attempting to split it later. Solution: remove win first, check that parent is valid after win_enter. NOTE: This isn't actually quite right, as this means win is not in the window list or even has a frame when triggering enter autocommands (so it's not considered valid in the tabpage). This is addressed in later commits.
* test: more tests for nvim_eval_statusline "fillchar" (#27502)zeertzjq2024-02-17
|
* fix(api): don't use stl 'fillchar' for "use_statuscol_lnum" (#27501)luukvbaal2024-02-17
| | | | Problem: nvim_eval_statusline() uses "stl" from 'fillchars' with "use_statuscol_lnum". Solution: Reorder "fillchar" else chain.
* refactor(tests): get channel id via nvim_get_chan_info #27441Justin M. Keyes2024-02-12
| | | Minor "best practices" nudge.