Commit Graph

6644 Commits

Author SHA1 Message Date
Gregory Anders
29d5ff6ac4 fix(diagnostic): check for sign namespace instead of sign group 2023-12-13 09:30:13 -06:00
Raphael
8122470f83
refactor(diagnostic): set sign by using extmark (#26193)
after sign implementation refactor by using extmark, we can use
`nvim_buf_set_extmark` to set diagnostic sign instead use `sign_define`
2023-12-13 08:19:53 -06:00
zeertzjq
d65c6a0baf
vim-patch:9.0.2159: screenpos() may crash with neg. column (#26542)
Problem:  screenpos() may crash with neg. column
Solution: validate and correct column

closes: vim/vim#13669

ec54af4e26
2023-12-13 06:17:50 +08:00
Will Hopkins
69ffbb76c2
feat(iter): add Iter.take (#26525) 2023-12-12 14:27:24 -06:00
Gregory Anders
1907abb4c2
fix(stream): do not close handle if it is already closing (#26537)
uv_close asserts that a handle is not already closing. We can guard
against this assertion failure by manually checking the handle's closing
status ourselves.
2023-12-12 13:19:46 -06:00
zeertzjq
b40170f7a3
fix(lua): memory leak when using invalid syntax with exists() (#26530) 2023-12-12 20:34:02 +08:00
Raphael
1d4a5cd185
feat(eval): exists() function supports checking v:lua functions (#26485)
Problem:  Vimscript function exists() can't check v:lua functions.
Solution: Add support for v:lua functions to exists().
2023-12-12 19:06:22 +08:00
bfredl
e69834744b
Merge pull request #26486 from glepnir/fix_linebyte
fix(eval): use no_ff instead of ffdos as condition
2023-12-12 11:57:56 +01:00
glepnir
d95e3a4c9c fix: use no_ff instead of ffdos as condition
Problem: line2byte behavior is changed after commit b051b13. It no
longer return `-1` on empty buffer.

Solution: use `nof_ff` instead of `!ff_dos` as condition. Then
compatible behavior of line2byte() is restored.
2023-12-12 13:49:04 +08:00
zeertzjq
a9fbba81d5
test(treesitter/fold_spec): fix flakiness (#26524) 2023-12-12 10:44:17 +08:00
zeertzjq
b76cc974b9
fix(tui): don't forget to update cursor visibility (#26523) 2023-12-12 09:44:46 +08:00
Lewis Russell
8097b4a725
Merge pull request #26506 from tomtomjhj/tsfold
fix(treesitter): improve vim.treesitter.foldexpr
2023-12-11 19:30:53 +00:00
Jaehwang Jung
b88d1fb15f test(treesitter): more foldexpr tests 2023-12-12 02:29:59 +09:00
dundargoc
529498685b
Merge pull request #26458 from famiu/refactor/options/optionindex 2023-12-10 16:26:08 +01:00
zeertzjq
096211a87b
test: make text-only snapshots work (#26494) 2023-12-10 07:06:48 +08:00
zeertzjq
1037ce2e46 test: avoid repeated screen lines in expected states
This is the command invoked repeatedly to make the changes:

    :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g
2023-12-09 22:15:02 +08:00
zeertzjq
5e43630a26 test: allow avoiding repeated screen lines in expected states
Allow a "*count" suffix in a screen line to repeat the screen line for
"count" times.

The change is made to Screen:expect() and Screen:get_snapshot() instead
of Screen:render() so that screen expectations generated using code can
still work and test failures can still be readable.

A snapshot is now also printed on failure so that there is no need to
run the test again with Screen:snapshot_util().
2023-12-09 22:14:50 +08:00
Famiu Haque
6346987601
refactor(options): reduce findoption() usage
Problem: Many places in the code use `findoption()` to access an option using its name, even if the option index is available. This is very slow because it requires looping through the options array over and over.

Solution: Use option index instead of name wherever possible. Also introduce an `OptIndex` enum which contains the index for every option as enum constants, this eliminates the need to pass static option names as strings.
2023-12-09 17:54:43 +06:00
Gregory Anders
c651fb3042
refactor(tui): use synchronized updates around actual buf flush (#26478)
Rather than writing the synchronized update begin and end sequences into
the TUI's internal buffer (where it is later flushed to the TTY), write
these sequences directly to the TTY before and after the TUI's internal
buffer is itself flushed to the TTY.

This guarantees that a synchronized update is always used when we are
actually sending data to the TTY. This means we do not need to keep
track of the TUI's "dirty" state (any sequences which affect the TUI
state will be written in the TUI's internal buffer, which is now
guaranteed to only ever be written when a synchronized update is
active).
2023-12-09 10:44:16 +08:00
zeertzjq
b8e227b621
vim-patch:9.0.2154: The option[] array is not sorted (#26475)
Problem:  The options[] array is not sorted alphabetically.
Solution: Sort it alphabetically.  Add a test.  Avoid unnecessary loop
          iterations in findoption().

closes: vim/vim#13648

Cherry-pick Test_set_one_column() change from patch 8.2.0432.

f48558e10a
2023-12-09 07:18:21 +08:00
Luuk van Baal
2289ca273c perf(column): avoid counting when max signs are removed from a range 2023-12-08 15:42:18 +00:00
zeertzjq
808fbe67a8
test(tui_spec): update cursor_address test for flush start (#26464) 2023-12-08 11:42:17 +08:00
zeertzjq
3bb5d2f219
test: use termopen() instead of :terminal more (#26462) 2023-12-08 08:00:27 +08:00
Gregory Anders
5e3c1b976a
test: fix Windows tests failures (#26461) 2023-12-08 06:58:03 +08:00
Gregory Anders
75aaec1b60
Merge pull request #26456 from gpanders/ignore-vim-runtime
fix(terminal): ignore $VIM and $VIMRUNTIME in pty jobs
2023-12-07 13:02:02 -08:00
Gregory Anders
8957df4f22 test: forward $VIMRUNTIME in child nvim instances 2023-12-07 11:54:22 -08:00
Gregory Anders
b2d471ab33
fix(lua): allow nil values in serialized Lua arrays (#26329)
When we convert a Lua table to an Object, we consider the table a
"dictionary" if it contains only string keys, and an array if it
contains all numeric indices with no gaps. While rare, Lua tables can
have both strictly numeric indices and gaps (e.g. { [2] = 2 }). These
currently cannot be serialized because it is not considered an array.

However, we know the maximum index of the table and as long as all of
the keys in the table are numeric, it is still possible to serialize
this table as an array. The missing indices will have nil values.
2023-12-07 08:01:27 -08:00
Luuk van Baal
4a34da82c1 perf(column): keep track of number of lines that hold up the 'signcolumn'
Problem:  The entire marktree needs to be traversed each time a sign is
          removed from the sentinel line.
Solution: Remove sentinel line and instead keep track of the number of
          lines that hold up the 'signcolumn' in "max_count". Adjust this
          number for added/removed signs, and set it to 0 when the
          maximum number of signs on a line changes. Only when
          "max_count" is decremented to 0 due to sign removal do we need
          to check the entire buffer.

          Also replace "invalid_top" and "invalid_bot" with a map of
          invalid ranges, further reducing the number of lines to be
          checked.

          Also improve tree traversal when counting the number of signs.
          Instead of looping over the to be checked range and counting
          the overlap for each row, keep track of the overlap in an
          array and add this to the count.
2023-12-07 14:22:24 +00:00
Justin M. Keyes
cca6c4c698 feat(rpc): allow empty string key in msgpack => Vim conversion
Problem:
Since e057b38e70 #20757 we support empty key in JSON encode/decode,
but we don't allow it in RPC object => Vim dict conversion. But empty
string is a valid key in Vim dicts and the msgpack spec.

Empty string key was disallowed in 7c01d5ff92 (2014) but that
commit/PR doesn't explicitly discuss it, so presumably it was a "seems
reasonable" decision (or Vimscript didn't allow empty keys until later).

Solution:
Remove the check in `object_to_vim()`. Note that
`tv_dict_item_alloc_len` will invoke `memcpy(…, 0)` but that's allowed
by the C spec: https://stackoverflow.com/a/3751937/152142
2023-12-07 12:57:25 +01:00
zeertzjq
aba954b662
fix(terminal): never propagate $COLORTERM from outer env (#26440)
If $COLORTERM is "truecolor" but the user sets 'notermguicolors',
propagating $COLORTERM to :terminal usually doesn't work well.
2023-12-07 19:14:56 +08:00
zeertzjq
94c2703a03
test(unit): correct header name (#26446) 2023-12-07 17:02:08 +08:00
zeertzjq
93011add10 test(inccommand_spec): actually trigger 'inccommand' preview 2023-12-07 15:32:56 +08:00
zeertzjq
1dba570e63
fix(inccommand): save and restore '[ and '] marks (#26442)
Undoing a change moves '[ and '] marks, so it is necessary to save and
restore them.
2023-12-07 12:04:02 +08:00
zeertzjq
6c3ddd8c51
test: set 'termguicolors' in outer Nvim instance (#26437)
Currently, the value of $COLORTERM in :terminal in tests depends on
outer environment because of 'notermguicolors'.

If $COLORTERM is not set in :terminal, an inner Nvim instance will try
to detect 'termguicolors' support, which may interfere with tests.

So set 'termguicolors' in outer Nvim instance unless $COLORTERM needs to
be overridden, and unset it in inner Nvim instance when running TUI.
2023-12-07 10:16:00 +08:00
zeertzjq
6b00b8a369
test(terminal): remove unnecessary string operations (#26434) 2023-12-07 07:15:37 +08:00
bfredl
8bb5089974
Merge pull request #26381 from bfredl/delaycolors
fix(startup): only send one default_colors_set event during startup
2023-12-06 19:58:02 +01:00
Gregory Anders
08545bd45b
Merge pull request #26407 from gpanders/default-tgc
feat(defaults): enable 'termguicolors' by default when supported by terminal
2023-12-06 10:55:50 -08:00
Gregory Anders
a5a346678a test: set notermguicolors in tests
Set 'notermguicolors' in tests which spawn a child Nvim process to force
existing tests to use 16 colors. Also refactor the child process
invocation to make things a little bit less messy.
2023-12-06 10:38:44 -08:00
bfredl
8f10362cdc fix(startup): only send one default_colors_set event during startup
If the color scheme is changed in a startup script, nvim used to send
multiple default_colors_set events, one for the default color scheme
and one for the user's chosen color scheme. This would cause flicker in
some UI:s. Throttle this event until we actually start drawing on the
screen.

fixes #26372
2023-12-06 18:46:39 +01:00
Justin M. Keyes
ca7f8786a0
test: unreliable 'nofsync' test #26423
Followup to 27501d3b6a.

Problem:
CI sometimes fails. Something is triggering an extra fsync().

    FAILED   test/functional/core/fileio_spec.lua @ 52: fileio fsync() with 'nofsync' #8304
    test/functional/core/fileio_spec.lua💯 Expected objects to be the same.
    Passed in:
    (number) 5
    Expected:
    (number) 4

Solution:
Relax the assertion.
2023-12-06 08:26:30 -08:00
Emanuel
e057b38e70
fix(json): allow objects with empty keys #25564
Problem:
Empty string is a valid JSON key, but json_decode() treats an object
with empty key as ":help msgpack-special-dict". #20757

    :echo json_decode('{"": "1"}')
    {'_TYPE': [], '_VAL': [['', '1']]}

Note: vim returns `{'': '1'}`.

Solution:
Allow empty string as an object key.

Note that we still (currently) disallow empty keys in object_to_vim() (since 7c01d5ff92):
f64e4b43e1/src/nvim/api/private/converter.c (L333-L334)

Fix #20757

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2023-12-06 07:56:04 -08:00
Justin M. Keyes
c84af395e8
test: 'nofsync' with deadly signal #26415
Problem:
The test for 'nofsync' swapfile preservation on a deadly signal, does
not actually assert anything.

followup to 1fd29a2884

Solution:
Check that swapfile contents are present after getting SIGTERM.
TODO: this doesn't really verify that 'fsync' was called; it still
passes with this patch:

    diff --git a/src/nvim/main.c b/src/nvim/main.c
    index 216e39f3e81c..7a635520401d 100644
    --- a/src/nvim/main.c
    +++ b/src/nvim/main.c
    @@ -838,7 +838,7 @@ void preserve_exit(const char *errmsg)
           if (errmsg != NULL) {
             os_errmsg("Vim: preserving files...\r\n");
           }
    -      ml_sync_all(false, false, true);  // preserve all swap files
    +      ml_sync_all(false, false, false);  // preserve all swap files
           break;
         }
       }

However it correctly fails with this patch, at least:

    diff --git a/src/nvim/main.c b/src/nvim/main.c
    index 216e39f3e81c..f2306c310ddc 100644
    --- a/src/nvim/main.c
    +++ b/src/nvim/main.c
    @@ -838,7 +838,6 @@ void preserve_exit(const char *errmsg)
           if (errmsg != NULL) {
             os_errmsg("Vim: preserving files...\r\n");
           }
    -      ml_sync_all(false, false, true);  // preserve all swap files
           break;
         }
       }
2023-12-06 07:11:36 -08:00
zeertzjq
f22e9e10f9
vim-patch:8.2.3695: confusing error for missing key (#26420)
Problem:    Confusing error for missing key.
Solution:   Use the actualy key for the error. (closes vim/vim#9241)

5c1ec439f0

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-12-06 16:49:40 +08:00
Gregory Anders
5b40a1c09d
feat(lua): implement Iter:join() (#26416) 2023-12-05 18:35:22 -08:00
dundargoc
cc38086039
docs: small fixes (#26243)
Co-authored-by: umlx5h <umlx5h21@protonmail.com>
Co-authored-by: Gregory Anders <greg@gpanders.com>
Co-authored-by: Evan Farrar <evan@evanfarrar.com>
2023-12-06 08:04:21 +08:00
zeertzjq
06ff540e1c
vim-patch:9.0.2151: 'breakindent' is not drawn after diff filler lines (#26412)
Problem:  'breakindent' is not drawn after diff filler lines.
Solution: Correct check for whether 'breakindent' should be drawn.

closes: vim/vim#13624

588f20dece

Cherry-pick Test_diff_with_syntax() change from patch 9.0.1257.
2023-12-06 07:16:02 +08:00
Justin M. Keyes
27501d3b6a
test: fileio_spec is unreliable/flaky #26404
Problem:
CI sometimes fails. Something is triggering an extra fsync().

    FAILED   test/functional/core/fileio_spec.lua @ 52: fileio fsync() codepaths #8304
    test/functional/core/fileio_spec.lua:87: Expected objects to be the same.
    Passed in:
    (number) 3
    Expected:
    (number) 2
    stack traceback:
            test/functional/core/fileio_spec.lua:87: in function <test/functional/core/fileio_spec.lua:52>

Solution:
Relax the assertion to `fsync >= 2` instead of exactly 2.

(Note this is not a behavior change: the next assertion has always
checked `fsync == 4`, it's just that the intermediate 3rd fsync was
never explicitly asserted.)
2023-12-05 12:52:06 -08:00
bfredl
ca4fe083e5
Merge pull request #26361 from luukvbaal/invalid
fix(extmarks): restore old position before revalidating
2023-12-05 16:13:39 +01:00
Riccardo Mazzarini
0b74ad0a64
refactor(api): complete conversion from Dictionary to Dict(opts) (#26365) 2023-12-05 19:33:57 +08:00
Christian Clason
c9828200ac vim-patch:9.0.2148: Vim does not detect pacman.log file
Problem:  Vim does not detect pacman.log file
Solution: Detect pacmanlogs and add syntax highlighting

pacman.log is a filetype common to Arch Liux and related distributions.
Add some simple syntax highlighting for the pacmanlog filetype.

closes: vim/vim#13618

1e5d66408e

Co-authored-by: Ronan Pigott <ronan@rjp.ie>
2023-12-05 09:45:13 +01:00