Commit Graph

32034 Commits

Author SHA1 Message Date
zeertzjq
246b1e9fb3 Merge pull request #32768 from zeertzjq/vim-9.1.1179
perf(keycodes): use hashy for string lookup
2025-03-08 06:04:16 +08:00
zeertzjq
12d4caa9d3 perf(keycodes): use hashy for string lookup
This is slightly faster than the binary search as per the benchmark, and
allows handling the vim/vim#16821 situation in generator code.
2025-03-08 05:45:39 +08:00
zeertzjq
af42f79221 vim-patch:partial:9.1.1179: too many strlen() calls in misc2.c
Problem:  too many strlen() calls in misc2.c
Solution: refactor misc2.c and use bsearch() instead of a linear search
          to find matches in the key_names_table array (John Marriott).

This commit changes misc2.c to use bsearch() to perform string searches of
the key_names_table array.

Implementation detail:
- Some entries in this array have alternate names. Add field alt_name to
  point to the alternate name.
- Some entries in this array are only available if a given feature is
  defined. Keep them in the array, but add a boolean field enabled to
  indicate if the record can be used or not. If the feature is not
  available, the corresponding enabled field is set to FALSE.

In my measurements running the test suite on a huge non-gui build on
linux, the number of string comparisons in get_special_key_code():
Before (linear search): 2,214,957
After (binary search): 297,770

A side effect of this is 1477 calls to STRLEN() in
get_special_key_name() for the same test run are no longer necessary.

closes: vim/vim#16788

4a1e6dacbb

Skip the mouse shape changes.

Co-authored-by: John Marriott <basilisk@internode.on.net>
2025-03-08 05:45:39 +08:00
zeertzjq
08d12b57ad test: add benchmark for nvim_replace_termcodes and keytrans() 2025-03-08 05:45:39 +08:00
zeertzjq
3824f52e52 refactor(keycodes): generate key_names_table[] using Lua
This allows easier refactoring.
2025-03-08 05:45:38 +08:00
Gregory Anders
3d49c55d3c fix(terminal): avoid rescheduling events onto the same queue (#32755)
Problem:

When a function like vim.wait() is used, we continuously drain the main
event queue until it is empty, never stopping for user input. This means
the libuv timer never runs and the terminal never gets refreshed, so
emit_termrequest continously reschedules itself onto the same event
queue, causing an infinite loop.

Solution:

Use a separate "pending" event queue, where events that require a
terminal refresh are temporarily placed. Drain this queue after a
terminal refresh and events are copied back onto the main queue. This
prevents infinite loops since the main event queue will always be able
to properly drain.
2025-03-07 12:16:39 -06:00
luukvbaal
8da59060c6 fix(marks): mark winline as invalid if change is in a concealed line (#32766)
Code that checks whether a `w_lines` entry has become invalid due to
a change in a folded line should now also check for concealed lines.
2025-03-07 16:21:20 +01:00
Gregory Anders
b31132f1c1 feat(defaults): jump between :terminal shell prompts with ]]/[[ #32736 2025-03-07 05:45:34 -08:00
zeertzjq
c8b64b7a43 fix(lua): always use vim.inspect() for :lua= (#32715) 2025-03-07 19:50:00 +08:00
Maria José Solano
5d08b65ac2 fix(lsp): use unresolved code action when codeAction/resolve fails 2025-03-07 10:23:55 +01:00
Christian Clason
e46f07b1d2 vim-patch:9.1.1177: filetype: tera files not detected
Problem:  filetype: tera files not detected
Solution: detect '*.tera' files as tera filetype,
          include a simple filetype plugin
          (MuntasirSZN)

closes: vim/vim#16806

5daaf23268

Co-authored-by: MuntasirSZN <muntasir.joypurhat@gmail.com>
2025-03-07 00:07:08 +01:00
luukvbaal
7371abf755 fix(marks): wrong winline info for concealed line with below virt line (#32747)
Problem:  Skipping over a concealed line for which `win_line()`
          _should_ be called because it has `virt_lines_above = false`
          lines associated with it.
Solution: Don't include such a line in `wl_lastlnum` from the line
          above.
2025-03-06 16:36:10 +01:00
zeertzjq
9a02906c44 vim-patch:08a410f: runtime(vim): recognize <...> strings (and keys) for 'keywordprg' (#32752)
see :help E499 and :h key-notation

closes: vim/vim#16795

08a410f674

Co-authored-by: Konfekt <Konfekt@users.noreply.github.com>
2025-03-06 19:40:47 +08:00
zeertzjq
baccb569dc vim-patch:9.1.1173: filetype: ABNF files are not detected (#32751)
Problem:  filetype: ABNF files are not detected
Solution: detect '.abnf' file as abnf filetype and
          include an abnf syntax plugin (A4-Tacks).

References:
- RFC5234
- RFC7405

closes: vim/vim#16802

9f827ec587

Co-authored-by: A4-Tacks <wdsjxhno1001@163.com>
2025-03-06 19:39:49 +08:00
Sean Dewar
fa46441264 fix(terminal): improve cursor refresh handling (#32596)
Problem: terminal mode cursor refresh logic has too many edge cases where it
fails when events change curbuf.

Solution: change the logic. Introduce cursor_visible to TerminalState to more
reliably track if terminal mode has changed busy. Move visibility handling to
refresh_cursor and move its call in refresh_terminal to terminal_check to avoid
temporarily changed curbufs from influencing cursor state.

This has the effect of "debouncing" shape/visibility updates to once per
terminal state tick (with the final attributes taking effect, as expected). I
think this is OK, but as a result it may also be warranted to update when
redrawing during the same state tick (e.g: from events executing :redraw); this
can be added later, if wanted.

Also move previous tests to a more appropriate place.
2025-03-06 08:31:50 +00:00
Maria José Solano
41b07b128c feat(lsp): support for resolving code action command (#32704)
* fix(lsp): don't call codeAction_resolve with commands

* feat(lsp): support for resolving code action command
2025-03-06 08:21:47 +00:00
Gregory Anders
0c0352783f fix(tui): remove DCS escaping in tmux (#32723)
Per https://github.com/tmux/tmux/issues/4386, tmux does not support DCS
responses, even if the initial request was escaped.
2025-03-05 21:28:05 -06:00
zeertzjq
9c4f2cde7b vim-patch:9.1.1176: wrong indent when expanding multiple lines (#32746)
Problem:  wrong indentation of lastline when expanding multiple lines
Solution: Check OPENLINE_FORCE_INDENT flag in open_line() (glepnir)

closes: vim/vim#16786

34a7d82aae

Co-authored-by: glepnir <glephunter@gmail.com>
2025-03-06 08:26:31 +08:00
zeertzjq
1a35eb9b56 vim-patch:9.1.1175: inconsistent behaviour with exclusive selection and motion commands (#32745)
Problem:  inconsistent behaviour with exclusive selection and motion
          commands (aidancz)
Solution: adjust cursor position when selection is exclusive
          (Jim Zhou)

fixes: vim/vim#16278
closes: vim/vim#16784

c8cce711dd

Co-authored-by: Jim Zhou <jimzhouzzy@gmail.com>
Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
2025-03-06 08:24:13 +08:00
zeertzjq
a261f602a0 vim-patch:9.1.1174: tests: Test_complete_cmdline() may fail (#32743)
Problem:  tests: when the file 'TestCommand?Test' exists,
          'Test_complete_cmdline()' will fail when writing the file. And
          there's no related cleaning operation for this kind of file
          before the test run.
Solution: modify `write` to `write!` to override (Jim Zhou).

closes: vim/vim#16799

f7087cbec7

Co-authored-by: Jim Zhou <jimzhouzzy@gmail.com>
2025-03-05 23:39:15 +00:00
zeertzjq
cd7d3cc041 vim-patch:4783a2c: runtime(doc): mention bzip3 in gzip plugin documentation (#32742)
closes: vim/vim#16800

4783a2c073

Co-authored-by: Jim Zhou <jimzhouzzy@gmail.com>
2025-03-05 23:38:33 +00:00
zeertzjq
761e920280 vim-patch:9.1.1172: [security]: overflow with 'nostartofline' and Ex command in tag file (#32739)
Problem:  heap-buffer-overflow with 'nostartofline' and Ex command in
          tag file.
Solution: Set cursor column when moving cursor to line 1 (zeertzjq).

closes: vim/vim#16796

3ed6659549
2025-03-06 07:08:53 +08:00
Gregory Anders
35e5307af2 feat(terminal)!: include cursor position in TermRequest event data (#31609)
When a plugin registers a TermRequest handler there is currently no way
for the handler to know where the terminal's cursor position was when
the sequence was received. This is often useful information, e.g. for
OSC 133 sequences which are used to annotate shell prompts.

Modify the event data for the TermRequest autocommand to be a table
instead of just a string. The "sequence" field of the table contains the
sequence string and the "cursor" field contains the cursor
position when the sequence was received.

To maintain consistency between TermRequest and TermResponse (and to
future proof the latter), TermResponse's event data is also updated to
be a table with a "sequence" field.

BREAKING CHANGE: event data for TermRequest and TermResponse is now a
table
2025-03-05 09:45:22 -06:00
bfredl
8448703662 Merge pull request #12049 from bfredl/luverr
convert non-string errors using tostring()
2025-03-05 13:30:06 +01:00
bfredl
ebb963a4a0 fix(lua): format errors from luv callbacks using __tostring 2025-03-05 12:09:57 +01:00
Christian Clason
e4c094a84d build(deps): bump tree-sitter to v0.25.3 2025-03-05 09:59:51 +01:00
zeertzjq
b0341136c1 vim-patch:9.1.1170: wildmenu highlighting in popup can be improved (#32728)
Problem:  wildmenu highlighting in popup can be improved
Solution: Check if the completion items contain submatches of the
          entered text (Girish Palya).

This update enables highlighting in the popup menu even when the matched
fragment or pattern appears within an item (string) rather than only at the
beginning. This is especially useful for custom completion, where menu items
may not always start with the typed pattern.

For specific use cases, refer to the two examples in
https://github.com/vim/vim/pull/16759

A sliding window approach is used with direct string comparison. Performance
is not a concern, as highlighting is applied only to displayed lines, even if
the menu list is arbitrarily long.

closes: vim/vim#16785

4ec46f3210

Co-authored-by: Girish Palya <girishji@gmail.com>
2025-03-04 22:51:36 +00:00
zeertzjq
97dc02687a vim-patch:9.1.1171: tests: wrong arguments passed to assert_equal() (#32727)
Problem:  tests: wrong arguments passed to assert_equal()
          (after v9.1.1167).
Solution: Swap arguments in the assert_equal() call (zeertzjq).

closes: vim/vim#16782

a95085e0fc
2025-03-05 06:42:54 +08:00
luukvbaal
81ea44fa6a fix(display): adjust winline info for concealed lines below last line (#32708)
Problem:  Last line in a window does not store correct `wl_lastlnum` if
          lines below it are concealed (resulting in e.g. incorrect
          cursor row).
Solution: Increment `wl_lastlnum` while it points to a line above a
          concealed line.
2025-03-04 19:45:21 +01:00
Robert Muir
7d5866d471 fix(lsp): open_floating_preview() ignores max_height (#32716)
Problem:  After 47aaddfa the max_height option is no longer respected.
          Hover documentation and Signature help windows take up the
          entire text height.
Solution: Compare to window's current height and only modify the height
          if it would reduce the height, not enlarge it.
2025-03-04 18:36:57 +00:00
James Trew
fb842dfc22 fix(diagnostic): virtual_lines diagnostic columns (#32703)
When multiple diagnostics appear on a single line, the virtual lines for
all diagnostics except the first were rendered with progressively fewer
columns.
2025-03-04 08:59:37 -06:00
bfredl
859dbb6619 Merge pull request #32608 from bfredl/nolegacyhl
refactor(tests): use new-style highlight spec in legacy/
2025-03-04 13:12:01 +01:00
bfredl
90a63d242a refactor(tests): use new-style highlight spec in legacy/ 2025-03-04 12:32:22 +01:00
zeertzjq
47cfe901d7 vim-patch:9.1.1169: using global variable for get_insert()/get_lambda_name() (#32713)
Problem:  using global variable for get_insert()/get_lambda_name()
          (after v9.1.1151)
Solution: let the functions return a string_T object instead
          (Yee Cheng Chin)

In vim/vim#16720, `get_insert()` was modified to store a string length in a
global variable to be queried immediately by another `get_insert_len()`
function, which is somewhat fragile. Instead, just have the function
itself return a `string_T` object instead. Also do the same for
`get_lambda_name()` which has similar issues.

closes: vim/vim#16775

0b5fe42071

Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-03-03 23:37:14 +00:00
zeertzjq
8ce504820a vim-patch:9.1.1167: mark '] wrong after copying text object (#32712)
Problem:  mark '] wrong after copying text object (ubaldot)
Solution: Adjust position of '] for non-linewise, exclusive motions
          (Jim Zhou)

related: vim/vim#16679
closes: vim/vim#16772

360a39ae6c

Co-authored-by: Jim Zhou <jimzhouzzy@gmail.com>
2025-03-04 07:05:05 +08:00
zeertzjq
65a3da8b15 vim-patch:659cb28: runtime(doc): fix typo "bet" in :h 'completeopt' (#32711)
closes: vim/vim#16773

659cb28c25
2025-03-04 07:04:25 +08:00
zeertzjq
e4fb697b69 Merge pull request #32709 from deathbeam/vim-9.1.1166
vim-patch:9.1.{1166,1168}: 'wildmode' noselect
2025-03-04 06:41:41 +08:00
zeertzjq
e56f741350 vim-patch:9.1.1168: wrong flags passed down to nextwild()
Problem:  wrong flags passed down to nextwild()
          (zeertzjq, after v9.1.1166)
Solution: only pass options flags (Girish Palya)

`options` needs to be passed into nextwild() since it may contain
WILD_KEEP_SOLE_ITEM which prevents the menu items list from getting
freed if there is only 1 item left (if `noselect` is set).

closes: vim/vim#16778

d2219d547d

Co-authored-by: Girish Palya <girishji@gmail.com>
2025-03-04 06:20:57 +08:00
Tomas Slusny
99d688e645 vim-patch:9.1.1166: command-line auto-completion hard with wildmenu
Problem:  command-line auto-completion hard with wildmenu
Solution: implement "noselect" wildoption value (Girish Palya)

When `noselect` is present in `wildmode` and 'wildmenu' is enabled, the
completion menu appears without pre-selecting the first item.

This change makes it easier to implement command-line auto-completion,
where the menu dynamically appears as characters are typed, and `<Tab>`
can be used to manually select an item. This can be achieved by
leveraging the `CmdlineChanged` event to insert `wildchar(m)`,
triggering completion menu.

Without this change, auto-completion using the 'wildmenu' mechanism is
not feasible, as it automatically inserts the first match, preventing
dynamic selection.

The following Vimscript snippet demonstrates how to configure
auto-completion using `noselect`:

```vim
vim9script
set wim=noselect:lastused,full wop=pum wcm=<C-@> wmnu
autocmd CmdlineChanged : timer_start(0, function(CmdComplete, [getcmdline()]))

def CmdComplete(cur_cmdline: string, timer: number)
  var [cmdline, curpos] = [getcmdline(), getcmdpos()]
  if cur_cmdline ==# cmdline  # Avoid completing each character in keymaps and pasted text
    && !pumvisible() && curpos == cmdline->len() + 1

    if cmdline[curpos - 2] =~ '[\w*/:]'  # Reduce noise by completing only selected characters
      feedkeys("\<C-@>", "ti")
      set eventignore+=CmdlineChanged  # Suppress redundant completion attempts
      timer_start(0, (_) => {
        getcmdline()->substitute('\%x00$', '', '')->setcmdline()  # Remove <C-@> if no completion items exist
        set eventignore-=CmdlineChanged
      })
    endif
  endif
enddef
```

fixes: vim/vim#16551
closes: vim/vim#16759

2bacc3e5fb

Cherry-pick Wildmode_Tests() change from patch 9.0.0418.

Co-authored-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
2025-03-04 06:20:20 +08:00
zeertzjq
948179cb19 vim-patch:9.1.1165: diff: regression with multi-file diff blocks (#32702)
Problem:  Vim's diff block merging algorithm when doing a multi-file diff
          is buggy when two different diff hunks overlap a single
          existing diff block (after v9.1.0743)

Solution: fix a couple bugs in this logic:

1. Fix regression from v9.1.0743 where it's not correctly expanding the
   2nd overlap correctly, where it always expands without taking into
   account that this was always taken care of when the first overlap
   happened. Instead, we should only grow the 2nd overlap if it overhangs
   outside the existing diff block, and if we encounter a new overlapping
   diff block (due to overlap chaining).
2. When we expand a diff block to match the hunk size on the orig side
   (when handling the first overlap), we expand the same amount of lines
   in the new side. This is not sound if there exists a second overlap
   hunk that we haven't processed yet, and that hunk has different
   number of lines in orig/new. Fix this by doing the corresponding
   counter adjustment when handling 2nd/3rd/etc overlap by calculating
   the difference in lines between orig and new side.
   (Yee Cheng Chin)

closes: vim/vim#16768

bc08ceb755

Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-03-03 10:53:03 +08:00
zeertzjq
560b8a8ce0 vim-patch:9.1.1164: [security]: code execution with tar.vim and special crafted tar files (#32701)
Problem:  editing a special crafted tar file allows code execution
          (RyotaK, after 129a8446d23cd9cb4445fcfea259cba5e0487d29)
Solution: escape the filename before feeding it to the `:read` command

Github Advisory:
https://github.com/vim/vim/security/advisories/GHSA-wfmf-8626-q3r3

334a13bff7

Co-authored-by: Christian Brabandt <cb@256bit.org>
2025-03-02 22:59:54 +00:00
Justin M. Keyes
c4a0c1d3b0 docs: misc #31996 2025-03-02 14:27:52 -08:00
Maria José Solano
0a5a0efda6 feat(lua): don't complete private (_) fields after dot (.) #32690 2025-03-02 13:44:13 -08:00
Riley Bruins
65c7033cbe feat(comment): allow commentstring to be determined from node metadata
**Problem:** Some weird languages have different comment syntax
depending on the location in the code, and we do not have a way to
determine the correct `commentstring` for these special cases.

**Solution:** Allow queries to specify `commentstring` values in
metadata, allowing users/`nvim-treesitter` to provide a better
commenting experience without hugely increasing the scope of the code in
core.
2025-03-02 18:38:13 +01:00
dundargoc
59c328bc88 test: simplify ASAN detection 2025-03-02 11:57:41 +01:00
fredizzimo
b45a44dd32 test: enable more multigrid popup tests (#32470) 2025-03-02 15:07:46 +08:00
dundargoc
188ec19894 build!: turn off translations by default
The translation step prolongs the build time too much to be enabled by
default. Enable it by passing cmake flag `ENABLE_TRANSLATIONS=ON`.
2025-03-02 02:29:25 +01:00
zeertzjq
1351383579 vim-patch:9.1.1161: preinsert requires bot "menu" and "menuone" to be set
Problem:  preinsert requires bot "menu" and "menuone" to be set,
          but "menu" is redundant (after v9.1.1160)
Solution: preinsert only requires menuone (glepnir)

closes: vim/vim#16763

94a045ed56

Co-authored-by: glepnir <glephunter@gmail.com>
2025-03-02 07:02:10 +08:00
zeertzjq
26775183ff vim-patch:9.1.1160: Ctrl-Y does not work well with "preinsert" when completing items
Problem:  The 'preinsert' feature requires Ctrl-Y to confirm insertion,
          but Ctrl-Y only works when the popup menu (pum) is displayed.
          Without enforcing this dependency, it could lead to confusing
          behavior or non-functional features.

Solution: Modify ins_compl_has_preinsert() to check for both 'menu' and
          'menuone' flags when 'preinsert' is set. Update documentation
          to clarify this requirement. This avoids adding complex
          conditional behaviors. (glepnir)

fixes: vim/vim#16728
closes: vim/vim#16753

a2c5559f29

Co-authored-by: glepnir <glephunter@gmail.com>
2025-03-02 07:02:10 +08:00
brianhuster
47b748af54 vim-patch:0b82054: runtime(lua): Improve 'include' and make '*expr' functions script-local
- Prevent 'include' from matching variable assignments as calls to
  require() and others.
- Use script-local functions for 'includeexpr' and 'foldexpr'.
- Formatting fixes.

closes: vim/vim#16746

0b8205484b

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
2025-03-02 06:46:26 +08:00