neovim/test/functional/editor
Alexandre Teoi a741c7fd04
fix(api): nvim_parse_cmd error message in pcall() #23297
Problem:
nvim_parse_cmd() in pcall() may show an error message (side-effect):

    :lua pcall(vim.api.nvim_parse_cmd, vim.fn.getcmdline(), {})
    E16: Invalid range

Solution:
Avoid emsg() in the nvim_parse_cmd() codepath.

- refactor(api): add error message output parameter to get_address()
- fix: null check emsg() parameter
- refactor: remove emsg_off workaround from do_incsearch_highlighting()
- refactor: remove emsg_off workaround from cmdpreview_may_show()
- refactor: remove remaining calls to emsg() from parse_cmd_address() and get_address()
- (refactor): lint set_cmd_dflall_range()
- refactor: addr_error() - move output parameter to return value

Fix #20339

TODO:

These are the functions called by `get_address()`:

```
nvim_parse_cmd() -> parse_cmdline() -> parse_cmd_address() -> get_address()
    skipwhite()
    addr_error()
    qf_get_cur_idx()
    qf_get_cur_valid_idx()
    qf_get_size()
    qf_get_valid_size()
    mark_get()
    mark_check()
    assert()
    skip_regexp()
    magic_isset()
>   do_search()
>   searchit()
    ascii_isdigit()
    getdigits()
    getdigits_int32()
    compute_buffer_local_count()
    hasFolding()
```

From these functions, I found at least two that call emsg directly:
- do_search()
  - seems to be simple to refactor
- searchit()
  - will be more challenging because it may generate multiple error messages,
    which can't be handled by the current `errormsg` out-parameter.
    For example, it makes multiple calls to `vim_regexec_multi()` in a loop that
    possibly generate error messages, and later `searchit()` itself may generate
    another one:
    - c194acbfc4/src/nvim/search.c (L631-L647)
    - c194acbfc4/src/nvim/search.c (L939-L954)

---------

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2023-07-01 06:33:51 -07:00
..
completion_spec.lua refactor(options): deprecate nvim[_buf|_win]_[gs]et_option 2023-05-21 15:14:01 +06:00
count_spec.lua test: reorg #15698 2021-09-17 09:16:40 -07:00
ctrl_c_spec.lua test: use poke_eventloop() instead of sleep(10) where possible (#19794) 2022-08-16 15:21:46 +08:00
fold_spec.lua test: fix dependencies between test cases (#23343) 2023-04-27 15:51:44 +08:00
jump_spec.lua fix(mark): mark without a view restores at topline #19224 2022-07-04 13:28:14 -07:00
K_spec.lua refactor(options): deprecate nvim[_buf|_win]_[gs]et_option 2023-05-21 15:14:01 +06:00
lang_spec.lua test: reorg #15698 2021-09-17 09:16:40 -07:00
langmap_spec.lua vim-patch:8.2.0867: using \{xxx} for encoding a modifier is not nice 2022-04-29 15:51:04 +08:00
macro_spec.lua test: correct order of arguments to eq() and neq() 2022-04-26 11:38:58 +08:00
mark_spec.lua fix(api): nvim_parse_cmd error message in pcall() #23297 2023-07-01 06:33:51 -07:00
meta_key_spec.lua fix(input): do no reinterpret mouse keys with ALT modifiers 2022-07-25 09:47:28 +08:00
mode_cmdline_spec.lua refactor(options): deprecate nvim[_buf|_win]_[gs]et_option 2023-05-21 15:14:01 +06:00
mode_insert_spec.lua vim-patch:8.2.3135: Vim9: builtin function arguments not checked at compile time 2023-05-05 09:19:05 +08:00
put_spec.lua test: fix dependencies between test cases (#23343) 2023-04-27 15:51:44 +08:00
search_spec.lua test: reorg #15698 2021-09-17 09:16:40 -07:00
tabpage_spec.lua fix: avoid unsigned overflow in home_replace() (#20854) 2022-10-30 06:49:39 +08:00
undo_spec.lua test(undo_spec): add more tests for writing in Insert mode 2022-12-09 07:00:27 +08:00