Commit Graph

6670 Commits

Author SHA1 Message Date
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
Jaehwang Jung
3159a2c28f
fix(change): update fold after on_bytes (#26364)
Problem:
With vim.treesitter.foldexpr, `o`-ing two lines above a folded region
opens the fold. This does not happen with legacy foldexprs. For example,
make a markdown file with the following text (without indentation),
enable treesitter fold, and follow the instruction in the text.

    put cursor on this line and type zoo<Esc>
    initially folded, revealed by zo
    # then this fold will be opened
    initially folded, revealed by o<Esc>

Analysis:
* `o` updates folds first (done in `changed_lines`), evaluating
  foldexpr, and then invokes `on_bytes` (done in `extmark_splice`).
* Treesitter fold allocates the foldinfo for added lines (`add_range`)
  on `on_bytes`.
* Therefore, when treesitter foldexpr is invoked while running `o`, it
  sees outdated foldinfo.

Solution:
`extmark_splice`, and then `changed_lines`. This seems to be the
standard order in other places, e.g., `nvim_buf_set_lines`.
2023-12-05 08:40:48 +08:00
Justin M. Keyes
c3836e40a2
build: enable lintlua for test/unit/ dir #26396
Problem:
Not all Lua code is checked by stylua. Automating code-style is an
important mechanism for reducing time spent on accidental
(non-essential) complexity.

Solution:
- Enable lintlua for `test/unit/` directory.
- TODO: only `test/functional/` remains unchecked.

previous: 45fe4d11ad
previous: 517f0cc634
2023-12-04 14:32:39 -08:00
Jongwook Choi
cf612c64b0
fix(treesitter): allow passing lang to vim.treesitter.get_node() now correctly takes opts.lang (#26360)
PROBLEM: `vim.treesitter.get_node()` does not recognize the `lang` in
the option table. This option was used in somewhere else, for instance,
`vim.treesitter.dev` (for `inspect_tree`) but was never implemented.

SOLUTION: Make `get_node()` correctly use `opts.lang` when getting a
treesitter parser.
2023-12-04 10:00:49 +01:00
zeertzjq
5651c1ff27
vim-patch:9.0.2145: wrong scrolling in insert mode with smoothscroll (#26375)
Problem:  Wrong scrolling in Insert mode with 'smoothscroll' at the
          bottom of the window.
Solution: Don't use set_topline() when 'smoothscroll' is set.

fixes: vim/vim#13612
closes: vim/vim#13613

5b4d1fcbf0
2023-12-04 06:42:47 +08:00
Christian Clason
988b472d90
feat(treesitter): highlight help files by default (#26347) 2023-12-03 15:58:27 +01:00
Evgeni Chasnovski
64a14026d7
feat(highlight): update default color scheme
Problem: Default color scheme is suboptimal.

Solution: Start using new color scheme. Introduce new `vim` color scheme
for opt-in backward compatibility.

------
Main design ideas
- Be "Neovim branded".
- Be minimal for 256 colors with a bit more shades for true colors.
- Be accessible through high enough contrast ratios.
- Be suitable for dark and light backgrounds via exchange of dark and
  light palettes.

------
Palettes

- Have dark and light variants. Implemented through exporeted
  `NvimDark*` and `NvimLight*` hex colors.

- Palettes have 4 shades of grey for UI elements and 6 colors (red,
  yellow, green, cyan, blue, magenta).

- Actual values are computed procedurally in Oklch color space based on
  a handful of hyperparameters.

- Each color has a 256 colors variant with perceptually closest color.

------
Highlight groups

Use:

- Grey shades for general UI according to their design.

- Bold text for keywords (`Statement` highlight group). This is an
  important choice to increase accessibility for people with color
  deficiencies, as it doesn't rely on actual color.

- Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some
  minor text UI elements.

- Cyan as main syntax color, i.e. for function usage (`Function`
  highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI
  elements.

- Red to generally mean high user attention, i.e. errors; in particular
  for `ErrorMsg`, `DiffDelete`, `DiagnosticError`.

- Yellow very sparingly only with true colors to mean mild user
  attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`.

- Blue very sparingly only with true colors as `DiagnosticHint` and some
  additional important syntax group (like `Identifier`).

- Magenta very carefully (if at all).

------
Notes

- To make tests work without relatively larege updates, each one is
  prepended with an equivalent of the call `:colorscheme vim`.

  Plus some tests which spawn new Neovim instances also now use 'vim'
  color scheme.

  In some cases tests are updated to fit new default color scheme.
2023-12-02 18:53:19 +02:00
Luuk van Baal
1cc358aed6 fix(extmarks): restore old position before revalidating 2023-12-02 12:35:52 +01:00
zeertzjq
9d7544ac4c vim-patch:9.0.2143: [security]: buffer-overflow in ex_substitute
Problem:  [security]: buffer-overflow in ex_substitute
Solution: clear memory after allocating

When allocating the new_start pointer in ex_substitute() the memory
pointer points to some garbage that the following for loop in
ex_cmds.c:4743 confuses and causes it to accessing the new_start pointer
beyond it's size, leading to a buffer-overlow.

So fix this by using alloc_clear() instead of alloc(), which will
clear the memory by NUL and therefore cause the loop to terminate
correctly.

Reported by @henices, thanks!

closes: vim/vim#13596

abfa13ebe9

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-12-02 10:41:31 +08:00
zeertzjq
9cc346119b vim-patch:9.0.2142: [security]: stack-buffer-overflow in option callback functions
Problem:  [security]: stack-buffer-overflow in option callback functions
Solution: pass size of errbuf down the call stack, use snprintf()
          instead of sprintf()

We pass the error buffer down to the option callback functions, but in
some parts of the code, we simply use sprintf(buf) to write into the error
buffer, which can overflow.

So let's pass down the length of the error buffer and use sprintf(buf, size)
instead.

Reported by @henices, thanks!

b39b240c38

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-12-02 10:41:31 +08:00
zeertzjq
01edcd6db8 vim-patch:9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Problem:  [security]: buffer-overflow in suggest_trie_walk
Solution: Check n before using it as index into byts array

Basically, n as an index into the byts array, can point to beyond the byts
array. So let's double check, that n is within the expected range after
incrementing it from sp->ts_curi and bail out if it would be invalid.

Reported by @henices, thanks!

0fb375aae6

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-12-02 10:41:31 +08:00
zeertzjq
7402655132 vim-patch:9.0.2140: [security]: use-after-free in win-enter
Problem:  [security]: use-after-free in win-enter
Solution: validate window pointer before calling win_enter()

win_goto() may stop visual mode, if it is active. However, this may in
turn trigger the ModeChanged autocommand, which could potentially free
the wp pointer which was valid before now became stale and points to now
freed memory.

So before calling win_enter(), let's verify one more time, that the
wp pointer still points to a valid window structure.

Reported by @henices, thanks!

eec0c2b3a4

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-12-02 10:41:31 +08:00
zeertzjq
387c5ba3de
revert: "memory: Free buffers after freeing variables" (#26356)
This reverts commit fe30d8ccef.

The original commit intends to prevent heap-use-after-free with EXITFREE
caused by changedtick_di, which is no longer a problem.

Freeing buffers after freeing variables will cause heap-use-after-free
with EXITFREE when a partial is used as prompt callback.
2023-12-02 09:55:11 +08:00
zeertzjq
fedbf32250
vim-patch:9.0.2139: html.angular ft is problematic (#26357)
Problem:  html.angular ft is problematic
Solution: partly revert v9.0.2137

The html.angular filetype causes issues and does not trigger FileType
autocommands for the html or angular filetypes.

So let's roll back that particular change and detect this only as html
file

related: https://github.com/vim/vim/pull/13594#issuecomment-1834465890

closes: vim/vim#13604

4f3480c943

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-12-02 09:42:16 +08:00
zeertzjq
548f03c66c
refactor: change event_create() to a macro (#26343)
A varargs functions can never be inlined, so a macro is faster.
2023-12-01 15:22:22 +08:00
zeertzjq
130cb4815a
fix(api): use a conditional stack for nvim_cmd (#26341) 2023-12-01 13:56:04 +08:00
ObserverOfTime
307d5bcc79 vim-patch:9.0.2137: Can't detect angular & mustache filetypes
Problem:  Can't detect angular & mustache filetypes
Solution: Detect *.mustache as Mustache filetype;
          detect *.component.html as html.angular filetype

closes: vim/vim#13594

7bed263c34
2023-11-30 18:40:27 +01:00
Gregory Anders
884a83049b
fix(tui): grow termkey's internal buffer for large escape sequences (#26309)
Some escape sequences (in particular, OSC 52 paste responses) can be
very large, even unbounded in length. These can easily overflow
termkey's internal buffer. In order to process these long sequences,
dynamically grow termkey's internal buffer.
2023-11-30 08:04:33 -06:00
bfredl
3b6dd8608d
Merge pull request #23657 from luukvbaal/extmark
fix(extmark): restore extmarks when completing original text
2023-11-30 11:48:16 +01:00
zeertzjq
85be914879
test: unskip more terminal tests on Windows (#26315) 2023-11-30 10:55:21 +08:00
zeertzjq
62dff43947
test(ex_terminal_spec): match descriptions (#26314) 2023-11-30 08:56:21 +08:00
zeertzjq
90b213990f test: :terminal when 'shell' uses backslashes 2023-11-30 07:32:28 +08:00
zeertzjq
73691b6c3d
test(ex_terminal_spec): unskip tests that work on Windows (#26310) 2023-11-30 07:06:23 +08:00
Luuk van Baal
8e97edb93f fix(extmark): restore extmarks when completing original text 2023-11-29 23:38:27 +01:00
zeertzjq
a6cba103ce
refactor: move some constants out of vim_defs.h (#26298) 2023-11-29 20:32:40 +08:00
Luuk van Baal
f4001d27ef perf(column): only invalidate lines affected by added sign 2023-11-29 10:17:15 +00:00
bfredl
584c6c25cc
Merge pull request #26292 from luukvbaal/decor
fix(decorations): do not apply sign highlight id as range attr id
2023-11-29 11:12:25 +01:00
zeertzjq
640680ccce
vim-patch:9.0.2134: ml_get error when scrolling (#26264)
Problem:  ml_get error when scrolling after delete
Solution: mark topline to be validated in main_loop
          if it is larger than current buffers line
          count

reset_lnums() is called after e.g. TextChanged autocommands and it may
accidentally cause curwin->w_topline to become invalid, e.g. if the
autocommand has deleted some lines.

So verify that curwin->w_topline points to a valid line and if not, mark
the window to have w_topline recalculated in main_loop() in
update_topline() after reset_lnums() returns.

fixes: vim/vim#13568
fixes: vim/vim#13578

c4ffeddfe5

The error doesn't happen in Nvim because Nvim triggers TextChanged after
calling update_topline().

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-29 13:24:24 +08:00
Luuk van Baal
a0e9ef09d7 fix(decorations): do not apply sign highlight id as range attr id 2023-11-29 03:57:23 +01:00
zeertzjq
aa9d9cafd0
vim-patch:9.0.2135: No test for mode() when executing Ex commands (#26282)
Problem:  No test for mode() when executing Ex commands
Solution: Add some test cases and simplify several other test cases.
          Also add a few more test cases for ModeChanged.

closes: vim/vim#13588

fcaeb3d42b
2023-11-29 06:51:00 +08:00
dundargoc
79b6ff28ad refactor: fix headers with IWYU 2023-11-28 22:23:56 +01:00
Luuk van Baal
35cec0de4a fix(column): redraw and update signcols for paired extmark
Problem:  Signcolumn width does not increase when ranged sign does not
          start at sentinel line.
Solution: Handle paired range of added sign when checking signcols.
2023-11-28 16:44:20 +00:00
bfredl
ba564442ae
Merge pull request #26249 from bfredl/concealchar
feat(decoration): allow conceal_char to be a composing char
2023-11-28 11:01:21 +01:00
bfredl
ae3685798d feat(decoration): allow conceal_char to be a composing char
decor->text.str pointer must go. This removes it for conceal char,
in preparation for a larger PR which will also handle the sign case.

By actually allowing composing chars for a conceal chars, this
becomes a feature and not just a refactor, as a bonus.
2023-11-28 10:35:25 +01:00
zeertzjq
e6d38c7dac
vim-patch:9.0.2133: Cannot detect overstrike mode in Cmdline mode (#26263)
Problem:  Cannot detect overstrike mode in Cmdline mode
Solution: Make mode() return "cr" for overstrike

closes: vim/vim#13569

d1c3ef1f47
2023-11-28 11:46:20 +08:00
Christian Clason
a314703cf1
vim-patch:9.0.2131: not all nushell files detected (#26260)
Problem:  not all nushell files detected
Solution: use *.nu to detect nushell files

closes: vim/vim#13586

b9efc72c24

Co-authored-by: Daniel Buch Hansen <boogiewasthere@gmail.com>
2023-11-28 07:58:31 +08:00
Dmytro Soltys
72ed99319d fix(treesitter): don't invalidate parser when discovering injections
When parsing with a range, languagetree looks up injections and adds
them if needed. This explicitly invalidates parser, making `is_valid`
report `false` both when including and excluding children.

This is an attempt to describe desired behaviour of `is_valid` in tests,
with what ended up being a single line change to satisfy them.
2023-11-27 15:53:26 +01:00
zeertzjq
a03bd2b878
test: check vim.wait() error message in fast context (#26242) 2023-11-27 18:24:32 +08:00
Lewis Russell
84bbe4b0ca fix(lua): disallow vim.wait() in fast contexts
`vim.wait()` cannot be called in a fast callback since the main loop
cannot be run in that context as it is not reentrant

Fixes #26122
2023-11-27 09:09:21 +00:00
Christian Clason
38e98754a5 vim-patch:9.0.2128: runtime(swig): add syntax and filetype plugins
Add syntax and filetype plugins for SWIG (Simplified Wrapper Interface
Generator) description files.

The default syntax for .i files highlights comments in a reverse
color scheme which doesn't look well.  This syntax builds
on vim's c++ syntax by adding highlighting for common swig
directives and user defined directives.  For an alternative
syntax, see vimscript vim/vim#1247 (which I found after writing this).

closes: vim/vim#13562

2e31065a65

Co-authored-by: Julien Marrec <julien.marrec@gmail.com>
Co-authored-by: Matěj Cepl <mcepl@cepl.eu>
2023-11-26 00:41:59 +01:00
James McCoy
0da62b579f
Merge pull request #26203 from jamessan/swapfile-test-fix
fix(oldtest): always use a 64-bit int for swapfile block number
2023-11-25 07:08:27 -05:00
luukvbaal
6a2a37b1e1
fix(mouse): avoid dragging when clicking next to popupmenu (#26201) 2023-11-25 07:10:19 +08:00
James McCoy
a1ded1b113
fix(oldtest): always use a 64-bit int for swapfile block number
09d4133 changed blocknr_T from long to int64_t, so pe_bnum is now always 64-bit.  This was an incompatible change in the swapfile format for 32-bit systems, but there have been no complaints in the past 9 years so just adjust the test.
2023-11-24 15:22:00 -05:00
zeertzjq
55dbf5c379
fix(messages): validate msg_grid before using msg_grid_pos (#26189) 2023-11-24 10:44:19 +08:00
luukvbaal
a8a93e517f
fix(mouse): avoid dragging after click label popupmenu callback (#26187) 2023-11-24 09:15:50 +08:00
zeertzjq
fe94e04893
vim-patch:9.0.2126: unused assignments when checking 'listchars' (#26182)
Problem:  Unused assignments when checking the value of 'listchars'.
Solution: Loop only once when just checking the value.  Add a test to
          check that this change doesn't cause double-free.

closes: vim/vim#13559

00624a2fa0
2023-11-24 06:52:50 +08:00
zeertzjq
9510346141
vim-patch:9.0.2125: File info disappears when 'cmdheight' has decreased (#26180)
Problem:  File info disappears immediately when 'cmdheight' has just
          decreased due to switching tabpage and 'shortmess' doesn't
          contain 'o' or 'O'.
Solution: Make sure msg_row isn't smaller than cmdline_row.

fixes: vim/vim#13560
closes: vim/vim#13561

40ed6711bd
2023-11-24 06:13:24 +08:00
Luuk van Baal
df399ea0d2 fix(column): reset decor state before starting from top 2023-11-23 16:27:17 +00:00
zeertzjq
b514edcdf4
test: remove the pipe created by new_pipename() (#26173) 2023-11-23 23:05:52 +08:00
luukvbaal
c126a3756a
fix(column): apply numhl signs when 'signcolumn' is "no" (#26167) 2023-11-23 19:58:17 +08:00
zeertzjq
8d8136bfcf vim-patch:9.0.2121: [security]: use-after-free in ex_substitute
Problem:  [security]: use-after-free in ex_substitute
Solution: always allocate memory

closes: vim/vim#13552

A recursive :substitute command could cause a heap-use-after free in Vim
(CVE-2023-48706).

The whole reproducible test is a bit tricky, I can only reproduce this
reliably when no previous substitution command has been used yet
(which is the reason, the test needs to run as first one in the
test_substitute.vim file) and as a combination of the `:~` command
together with a :s command that contains the special substitution atom `~\=`
which will make use of a sub-replace special atom and calls a vim script
function.

There was a comment in the existing :s code, that already makes the
`sub` variable allocate memory so that a recursive :s call won't be able
to cause any issues here, so this was known as a potential problem
already.  But for the current test-case that one does not work, because
the substitution does not start with `\=` but with `~\=` (and since
there does not yet exist a previous substitution atom, Vim will simply
increment the `sub` pointer (which then was not allocated dynamically)
and later one happily use a sub-replace special expression (which could
then free the `sub` var).

The following commit fixes this, by making the sub var always using
allocated memory, which also means we need to free the pointer whenever
we leave the function. Since sub is now always an allocated variable,
we also do no longer need the sub_copy variable anymore, since this one
was used to indicated when sub pointed to allocated memory (and had
therefore to be freed on exit) and when not.

Github Security Advisory:
https://github.com/vim/vim/security/advisories/GHSA-c8qm-x72m-q53q

26c11c5688

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-23 16:17:37 +08:00
Luuk van Baal
c249058758 feat(extmarks): add sign name to extmark "details" array
Problem:  Unable to identify legacy signs when fetching extmarks with
          `nvim_buf_get_extmarks()`.
Solution: Add "sign_name" to the extmark detail array.

Add some misc. changes as follow-up to #25724
2023-11-22 12:43:59 +01:00
bfredl
fba17d5b88 fix(decorations): fix imbalanced sign count 2023-11-22 11:41:47 +01:00
bfredl
0b38fe4dbb refactor(decorations): break up Decoration struct into smaller pieces
Remove the monolithic Decoration struct. Before this change, each extmark
could either represent just a hl_id + priority value as a inline
decoration, or it would take a pointer to this monolitic 112 byte struct
which has to be allocated.

This change separates the decorations into two pieces: DecorSignHighlight
for signs, highlights and simple set-flag decorations (like spell,
ui-watched), and DecorVirtText for virtual text and lines.

The main separation here is whether they are expected to allocate more
memory. Currently this is not really true as sign text has to be an
allocated string, but the plan is to get rid of this eventually (it can
just be an array of two schar_T:s). Further refactors are expected to
improve the representation of each decoration kind individually. The
goal of this particular PR is to get things started by cutting the
Gordian knot which was the monolithic struct Decoration.

Now, each extmark can either contain chained indicies/pointers to
these kinds of objects, or it can fit a subset of DecorSignHighlight
inline.

The point of this change is not only to make decorations smaller in
memory. In fact, the main motivation is to later allow them to grow
_larger_, but on a dynamic, on demand fashion. As a simple example, it
would be possible to augment highlights to take a list of multiple
`hl_group`:s, which then would trivially map to a chain of multiple
DecorSignHighlight entries.

One small feature improvement included with this refactor itself, is
that the restriction that extmarks cannot be removed inside a decoration
provider has been lifted. These are instead safely lifetime extended
on a "to free" list until the current iteration of screen drawing is done.

NB: flags is a mess. but DecorLevel is useless, this slightly less so
2023-11-22 09:28:54 +01:00
Bara C. Tudor
91ef26dece
fix(messages): :map output with ext_messages (#26126) 2023-11-22 09:50:28 +08:00
zeertzjq
fec5e3ab24
fix(vim.region): handle multibyte inclusive selection properly (#26129) 2023-11-21 14:25:45 +08:00
luukvbaal
d667e0e414
vim-patch:9.0.2116: No test for defining sign without attribute (#26115)
Problem:  No test for defining sign without attribute
Solution: Add test for defining sign without attributes

closes: vim/vim#13544

e670d17342
2023-11-20 10:25:14 +08:00
Mathias Fußenegger
7ca2d64e8b
test: skip failing watch file tests on freebsd (#26110)
Quick fix as follow up to https://github.com/neovim/neovim/pull/26108

kqueue only reports events on a watched folder itself, not for files
created or deleted within. So the approach the PR took doesn't work on FreeBSD.

We'll either need to bring back polling for it, combine watching with manual
file tracking, or disable LSP file watching on FreeBSD
2023-11-19 18:37:49 +01:00
Mathias Fußenegger
de28a0f84c
perf(lsp): replace file polling on linux with per dir watcher (#26108)
Should help with https://github.com/neovim/neovim/issues/23291

On linux `new_fs_event` doesn't support recursive watching, but we can
still use it to watch folders.

The downside of this approach is that we may end up sending some false
`Deleted` events. For example, if you save a file named `foo` there will
be a intermediate `foo~` due to the save mechanism of neovim.

The events we get from vim.uv in that case are:

- rename: foo~
- rename: foo~
- rename: foo
- rename: foo
- change: foo
- change: foo

The mechanism in this PR uses a debounce to reduce this to:

- deleted: foo~
- changed: foo

`foo~` will be the false positive.
I suspect that for the LSP case this is good enough. If not, we may need
to follow up on this and keep a table in memory that tracks available
files.
2023-11-19 14:25:32 +01:00
bfredl
df87266b23
Merge pull request #25724 from luukvbaal/signmerge
refactor(sign): move legacy signs to extmarks
2023-11-18 15:04:14 +01:00
Raphael
cdc8bacc79
fix(completion): filter results with complete+=f (#26029) 2023-11-18 12:26:52 +08:00
Maria José Solano
4972c80489 refactor(snippet): rename test utilities 2023-11-17 17:10:27 +01:00
Maria José Solano
7e36c8e972 feat(lsp): support for choice snippet nodes 2023-11-17 17:10:27 +01:00
zeertzjq
ad867fee26
fix(tui): handle cursor visibility properly (#26091)
The test is for the case without 'termsync' because libvterm doesn't
support synchronized output, and it passes without this PR.
2023-11-17 22:13:30 +08:00
Luuk van Baal
c4afb9788c refactor(sign): move legacy signs to extmarks
Problem:  The legacy signlist data structures and associated functions are
          redundant since the introduction of extmark signs.
Solution: Store signs defined through the legacy commands in a hashmap, placed
          signs in the extmark tree. Replace signlist associated functions.

Usage of the legacy sign commands should yield no change in behavior with the
exception of:
  - "orphaned signs" are now always removed when the line it is placed on is
    deleted. This used to depend on the value of 'signcolumn'.
  - It is no longer possible to place multiple signs with the same identifier
    in a single group on multiple lines. This will now move the sign instead.

Moreover, both signs placed through the legacy sign commands and through
|nvim_buf_set_extmark()|:
  - Will show up in both |sign-place| and |nvim_buf_get_extmarks()|.
  - Are displayed by increasing sign identifier, left to right.
    Extmark signs used to be ordered decreasingly as opposed to legacy signs.
2023-11-17 15:10:15 +01:00
bfredl
b522cb1ac3 refactor(grid): make screen rendering more multibyte than ever before
Problem: buffer text with composing chars are converted from UTF-8
to an array of up to seven UTF-32 values and then converted back
to UTF-8 strings.

Solution: Convert buffer text directly to UTF-8 based schar_T values.

The limit of the text size is now in schar_T bytes, which is currently
31+1 but easily could be raised as it no longer multiplies the size
of the entire screen grid when not used, the full size is only required
for temporary scratch buffers.

Also does some general cleanup to win_line text handling, which was
unnecessarily complicated due to multibyte rendering being an "opt-in"
feature long ago. Nowadays, a char is just a char, regardless if it consists
of one ASCII byte or multiple bytes.
2023-11-17 12:58:57 +01:00
zeertzjq
790bd4d585 vim-patch:9.0.2106: [security]: Use-after-free in win_close()
Problem:  [security]: Use-after-free in win_close()
Solution: Check window is valid, before accessing it

If the current window structure is no longer valid (because a previous
autocommand has already freed this window), fail and return before
attempting to set win->w_closing variable.

Add a test to trigger ASAN in CI

25aabc2b8e

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:59:22 +08:00
zeertzjq
d49be1cd28 vim-patch:9.0.2010: [security] use-after-free from buf_contents_changed()
Problem:  [security] use-after-free from buf_contents_changed()
Solution: block autocommands

41e6f7d6ba

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:59:22 +08:00
zeertzjq
b6200fbdf2 vim-patch:9.0.1992: [security] segfault in exmode
Problem:  segfault in exmode when redrawing
Solution: skip gui_scroll when exmode_active

20d161ace3

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:59:22 +08:00
zeertzjq
3ab0e296c6 vim-patch:9.0.1969: [security] buffer-overflow in trunc_string()
Problem:  buffer-overflow in trunc_string()
Solution: Add NULL at end of buffer

Currently trunc_string() assumes that when the string is too long,
buf[e-1] will always be writeable. But that assumption may not always be
true. The condition currently looks like this

    else if (e + 3 < buflen)
    [...]
    else
    {
	// can't fit in the "...", just truncate it
	buf[e - 1] = NUL;
    }

but this means, we may run into the last else clause with e still being
larger than buflen. So a buffer overflow occurs.

So instead of using `buf[e - 1]`, let's just always
truncate at `buf[buflen - 1]` which should always be writable.

3bd7fa12e1

vim-patch:9.0.2004: Missing test file

Problem:  Missing test file
Solution: git-add the file to the repo

closes: vim/vim#13305

d4afbdd071

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:59:16 +08:00
zeertzjq
5a67878e86 vim-patch:9.0.1882: Trailing white space in tests
Problem:  Trailing white space in tests
Solution: Delete it

This causes test_codestyle to fail, so we need to remove it again.
Hopefully that makes the CI green again.

Note: I will start using annotated tags from now on.

da200c2f78

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:54:03 +08:00
zeertzjq
7f62775d5d vim-patch:9.0.1881: Test_crash fails on Mac
Problem:  Test_crash fails on Mac
Solution: Skip test on Mac

5856b07795

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:54:03 +08:00
zeertzjq
b5b6e6fb49 vim-patch:9.0.1878: tests running sh have problems
Problem:  tests running sh have problems
Solution: Check that dash is installed

closes: vim/vim#13040

1690ec64ff

Co-authored-by: Philip H <47042125+pheiduck@users.noreply.github.com>
Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:54:03 +08:00
zeertzjq
eae10de14e vim-patch:9.0.1873: [security] heap-buffer-overflow in vim_regsub_both
Problem:  heap-buffer-overflow in vim_regsub_both
Solution: Disallow exchanging windows when textlock is active

f6d28fe2c9

Cherry-pick test_crash.vim change from patch 9.0.1876.

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:54:03 +08:00
zeertzjq
6867d2492c vim-patch:9.0.1872: CI: test_crash() fails on CI
Problem:  CI: test_crash() fails on CI
Solution: Skip test on BSD

d2a08ba0fa

Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-17 09:54:03 +08:00