Commit Graph

6344 Commits

Author SHA1 Message Date
Riley Bruins
4b90952851 fix(treesitter): mark supertype nodes as named
**Problem:** Tree-sitter 0.24.0 introduced a new symbol type to denote
supertype nodes (`TSSymbolTypeSupertype`). Now, `language.inspect()`
(and the query `omnifunc`) return supertype symbols, but with double
quotes around them.

**Solution:** Mark a symbol as "named" based on it *not* being an
anonymous node, rather than checking that it is a regular node (which a
supertype also is not).
2024-10-12 09:59:44 +02:00
zeertzjq
0e42c81c7f
fix(lua): avoid recursive vim.on_key() callback (#30753) 2024-10-12 08:07:05 +08:00
Riley Bruins
d3193afc25 fix(treesitter): remove duplicate symbol names in language.inspect()
**Problems:**

- `vim.treesitter.language.inspect()` returns duplicate
  symbol names, sometimes up to 6 of one kind in the case of `markdown`
- The list-like `symbols` table can have holes and is thus not even a
  valid msgpack table anyway, mentioned in a test

**Solution:** Return symbols as a map, rather than a list, where field
names are the names of the symbol. The boolean value associated with the
field encodes whether or not the symbol is named.

Note that anonymous nodes are surrounded with double quotes (`"`) to
prevent potential collisions with named counterparts that have the same
identifier.
2024-10-11 18:15:07 +02:00
Riley Bruins
267c7525f7 feat(treesitter): introduce child_with_descendant()
This commit also marks `child_containing_descendant()` as deprecated
(per upstream's documentation), and uses `child_with_descendant()` in
its place. Minimum required tree-sitter version will now be `0.24`.
2024-10-11 17:29:45 +02:00
zeertzjq
c4762b3097
test(tui_spec): use child_exec_lua() more (#30757)
It is more readable.
2024-10-11 08:23:14 +00:00
Riley Bruins
a0e3fe5741
feat(ui): cascading style inheritance for Pmenu* highlights #29980
- `PmenuSel` and `PmenuMatch` inherit from `Pmenu`
- `PmenuMatchSel` inherits from both `PmenuSel` and `PmenuMatch`
2024-10-10 23:26:25 -07:00
zeertzjq
25665b365c
test(tui_spec): better prevent race between paste and input (#30751)
Problem:
Using a single RPC request to child server isn't enough to prevent race
between nvim_paste and nvim_input.

Solution:
Ensure both child client and child server have processed pending events
by sending an empty DCS response to the child client and waiting for
TermResponse autocommand on the child server.
2024-10-11 09:45:44 +08:00
Tomasz N
b3109084c2
fix(lsp): fix cursor position after snippet expansion (#30659)
Problem: on `CompleteDone` cursor can jump to the end of line instead of
the end of the completed word.

Solution: remove only inserted word for snippet expansion instead of everything
until eol.

Fixes #30656

Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2024-10-10 11:40:03 +02:00
zeertzjq
8450752f46 vim-patch:9.1.0771: completion attribute hl_group is confusing
Problem:  Currently completion attribute hl_group is combined with
          all items, which is redundant and confusing with kind_hlgroup
Solution: Renamed to abbr_hlgroup and combine it only with the abbr item
          (glepnir).

closes: vim/vim#15818

0fe17f8ffb

Co-authored-by: glepnir <glephunter@gmail.com>
2024-10-10 07:21:02 +08:00
zeertzjq
376de1483e
fix(drawline): correct highlight priority with Visual selection (#30706) 2024-10-08 06:24:36 +08:00
Justin M. Keyes
27f3750817
feat(lsp): improve LSP doc hover rendering #30695
Problem:
- Some servers like LuaLS add unwanted blank lines after multiline
  `@param` description.
- List items do not wrap nicely.

Solution:
- When rendering the LSP doc hover, remove blank lines in each `@param`
  or `@return`.
  - But ensure exactly one empty line before each.
- Set 'breakindent'.
2024-10-06 12:20:40 -07:00
dundargoc
00d1078ede ci: bump macos runner version to macos-15 2024-10-06 16:06:28 +02:00
Jongwook Choi
d5ae5c84e9
feat(lua): completion for vim.fn, vim.v, vim.o #30472
Problem: Lua accessors for
- global, local, and special variables (`vim.{g,t,w,b,v}.*`), and
- options (`vim.{o,bo,wo,opt,opt_local,opt_global}.*`),

do not have command-line completion, unlike their vimscript counterparts
(e.g., `g:`, `b:`, `:set`, `:setlocal`, `:call <fn>`, etc.).

Completion for vimscript functions (`vim.fn.*`) is incomplete and does
not list all the available functions.

Solution: Implement completion for vimscript function, variable and
option accessors in `vim._expand_pat` through:

- `getcompletion()` for variable and vimscript function accessors, and
- `nvim_get_all_options_info()` for option accessors.

Note/Remark:

- Short names for options are yet to be implemented.

- Completions for accessors with handles (e.g. `vim.b[0]`, `vim.wo[0]`)
  are also yet to be implemented, and are left as future work, which
  involves some refactoring of options.

- For performance reasons, we may want to introduce caching for
  completing options, but this is not considered at this time since the
  number of the available options is not very big (only ~350) and Lua
  completion for option accessors appears to be pretty fast.

- Can we have a more "general" framework for customizing completions?
  In the future, we may want to improve the implementation by moving the
  core logic for generating completion candidates to each accessor (or
  its metatable) or through some central interface, rather than writing
  all the accessor-specific completion implementations in a single
  function: `vim._expand_pat`.
2024-10-04 06:48:31 -07:00
zeertzjq
86c5c8724b
fix(mouse): indicate X1 and X2 button clicks on statusline (#30655) 2024-10-04 21:31:28 +08:00
Justin M. Keyes
b45c50f314
docs: render @since versions, 0 means experimental #30649
An implication of this current approach is that `NVIM_API_LEVEL` should be
bumped when a new Lua function is added.

TODO(future): add a lint check which requires `@since` on all new functions.

ref #25416
2024-10-04 02:13:31 -07:00
James Trew
385fbfb3e7
docs: improve luacats support #30580
Some composite/compound types even as basic as `(string|number)[]` are
not currently supported by the luacats LPEG grammar used by gen_vimdoc.
It would be parsed & rendered as just `string|number`.

Changeset adds better support for these types.
2024-10-03 03:45:51 -07:00
glepnir
cc300e553b
vim-patch:9.1.0756: missing change from patch v9.1.0754 (#30636)
Problem:  missing change from patch v9.1.0754
Solution: use correct width for the actual item
          in pum_redraw() (glepnir)

closes: vim/vim#15786

a6d9e3c4e0
2024-10-03 09:58:15 +00:00
fredizzimo
7eba016c86
fix(ui): ensure screen update before waiting for input #30576
Ensure the screen is fully updated before blocking for input. This did
not always happen before, for example when setting `cursorline
scrolloff=9999`, which lead to jerky movement when using some GUI
applications.

Because of the duality of redraw_later, this can't be done in
command-line or when waiting for "Press ENTER". In many of those cases
the redraw is expected AFTER the key press, while normally it should
update the screen immediately. So, those special cases are excluded.
2024-10-03 02:31:17 -07:00
glepnir
6a2f8958e8
vim-patch:9.1.0754: fixed order of items in insert-mode completion menu (#30619)
Problem:  fixed order of items in insert-mode completion menu
Solution: Introduce the 'completeitemalign' option with default
          value "abbr,kind,menu" (glepnir).

Adding an new option `completeitemalign` abbr is `cia` to custom
the complete-item order in popupmenu.

closes: vim/vim#14006
closes: vim/vim#15760

6a89c94a9e
2024-10-03 06:45:01 +08:00
Justin M. Keyes
bbf208784c tests: skip watch.watchdirs test on macos 14 CI
Problem:
Strange failure only in macos 14 CI

    FAILED   test/functional/lua/watch_spec.lua @ 82: vim._watch watchdirs() detects file changes
    test/functional/lua/watch_spec.lua:149: Expected objects to be the same.
    Passed in:
    (table: 0x0116023758) {
     *[1] = {
        [change_type] = 3
       *[path] = '/Users/runner/work/neovim/neovim/build/Xtest_tmpdir/nvim_KFMvPbXk9a/nvim_KFMvPbXk9a' }
      [2] = {
        [change_type] = 3
        [path] = '/Users/runner/work/neovim/neovim/build/Xtest_tmpdir/nvim_KFMvPbXk9a/file' } }
    Expected:
    (table: 0x010d9d6548) {
     *[1] = {
        [change_type] = 1
       *[path] = '/Users/runner/work/neovim/neovim/build/Xtest_tmpdir/nvim_KFMvPbXk9a/file' }
      [2] = {
        [change_type] = 3
        [path] = '/Users/runner/work/neovim/neovim/build/Xtest_tmpdir/nvim_KFMvPbXk9a/file' } }

    stack traceback:
            test/functional/lua/watch_spec.lua:149: in function <test/functional/lua/watch_spec.lua:82>

Solution:
Skip test for that exact version.
2024-10-02 16:41:01 +02:00
Justin M. Keyes
9e23b4e185 fix(watch): ignore nonexistent paths (ENOENT)
Problem:
The `_watch.watch()` strategy may fail if the given path does not exist:

    …/vim/_watch.lua:101: ENOENT: no such file or directory
    stack traceback:
        [C]: in function 'assert'
        …/vim/_watch.lua:101: in function <…/vim/_watch.lua:61>
        [string "<nvim>"]:5: in main chunk

- `_watch.watch()` actively asserts any error returned by `handle:start()`.
- whereas `_watch.watchdirs()` just ignores the result of `root_handle:start()`.

Servers may send "client/registerCapability" with "workspace/didChangeWatchedFiles"
item(s) (`baseUri`) which do not actually exist on the filesystem:
https://github.com/neovim/neovim/issues/28058#issuecomment-2189929424

    {
      method = "client/registerCapability",
      params = {
        registrations = { {
            method = "workspace/didChangeWatchedFiles",
            registerOptions = {
              watchers = { {
                  globPattern = {
                    baseUri = "file:///Users/does/not/exist",
                    pattern = "**/*.{ts,js,mts,mjs,cjs,cts,json,svelte}"
                  }
                },
    ...
    }

Solution:
- Remove the assert in `_watch.watch()`.
- Show a once-only message for both cases.
- More detailed logging is blocked until we have `nvim_log` / `vim.log`.

fix #28058
2024-10-02 16:41:01 +02:00
zeertzjq
0e484c2041
vim-patch:9.1.0753: Wrong display when typing in diff mode with 'smoothscroll' (#30614)
Problem:  Wrong display when typing in diff mode with 'smoothscroll'.
Solution: Use adjust_plines_for_skipcol() (zeertzjq).

closes: vim/vim#15776

47f8584a80
2024-10-01 22:55:43 +00:00
zeertzjq
1c30d86c33
fix(tabline): restore behavior of click after last tabpage (#30602)
Also correct the comments about tabpage labels in custom tabline.
2024-10-01 19:46:30 +08:00
Lewis Russell
0fb5299e53 test: refactor exec_lua in xdiff_spec 2024-09-30 11:51:33 +01:00
Lewis Russell
c65646c247 fix(diff): use mmfile_t in linematch
Problem:

Linematch used to use strchr to navigate a string, however strchr does
not supoprt embedded NULs.

Solution:

Use `mmfile_t` instead of `char *` in linematch and introduce `strnchr()`.

Also remove heap allocations from `matching_char_iwhite()`

Fixes: #30505
2024-09-30 11:51:33 +01:00
Christian Clason
99e0facf3a feat(treesitter)!: use return values in language.add()
Problem: No clear way to check whether parsers are available for a given
language.

Solution: Make `language.add()` return `true` if a parser was
successfully added and `nil` otherwise. Use explicit `assert` instead of
relying on thrown errors.
2024-09-29 15:27:16 +02:00
zeertzjq
df915f3afc
fix(float): properly find last window of tabpage (#30571) 2024-09-29 10:38:17 +00:00
zeertzjq
d5f6f61879
fix(column): set signcolumn width after splitting window (#30556) 2024-09-28 17:16:22 +08:00
zeertzjq
4f9311b759
fix(window): making float with title/footer non-float leaks memory (#30551) 2024-09-28 10:21:06 +08:00
Riley Bruins
0f067cd34d fix(treesitter): suppress get_parser warnings via opts.error 2024-09-28 00:31:45 +02:00
glepnir
7b71fdbc1e
fix(window): respect hide flag of float windows when switching (#30507) 2024-09-28 06:02:14 +08:00
Justin M. Keyes
09d76afe84
feat(defaults): pretty :help headings #30544
Problem:
Headings in :help do not stand out visually.

Solution:
Define a non-standard `@markup.heading.1.delimiter` group and
special-case it in `highlight_group.c`.

FUTURE:
This is a cheap workaround until we have #25718 which will enable:
- fully driven by `vimdoc/highlights.scm` instead of using highlight
  tricks (`guibg=bg guifg=bg guisp=fg`)
- better support of "cterm" ('notermguicolors')
2024-09-27 08:53:30 -07:00
zeertzjq
f55213ce0e
fix(api): fix crash/leak with float title/footer on error (#30543) 2024-09-27 14:33:24 +00:00
zeertzjq
eea6b84a87
test(api/window_spec): remove duplicate test (#30538) 2024-09-27 19:10:55 +08:00
zeertzjq
6f2fe8a791
vim-patch:9.1.0743: diff mode does not handle overlapping diffs correctly (#30532)
Problem:  diff mode does not handle overlapping diffs correctly
Solution: correct the logic to handle overlapping blocks
          (Yukihiro Nakadaira)

Vim merges overlapped diff blocks and it doesn't work expectedly
in some situation.

closes: vim/vim#15735

06fe70c183

Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
2024-09-27 07:14:39 +00:00
Justin M. Keyes
f2fa4ca97e
feat(health): highlight headings #30525
Problem:
checkhealth report sections are not visually separated.

Solution:
Highlight with "reverse".

TODO: migrate checkhealth filetype to use treesitter.
TODO: default :help should also highlight headings more boldy!
2024-09-26 07:45:03 -07:00
zeertzjq
66197dde70
test(api/buffer_updates_spec): prevent flakiness (#30521)
Use poke_eventloop() to wait for Nvim to finish processing input.
2024-09-26 18:34:35 +08:00
zeertzjq
8070988247
fix(channel): handle writing to file instead of pipe (#30519) 2024-09-26 08:36:50 +00:00
Riley Bruins
64847fbdc9 perf(treesitter): use child_containing_descendant() in is_ancestor()
**Problem:** `is_ancestor()` uses a slow, bottom-up parent lookup which
has performance pitfalls detailed in #28512.

**Solution:** Take `is_ancestor()` from $O(n^2)$ to $O(n)$ by
incorporating the use of the `child_containing_descendant()` function
2024-09-25 23:01:08 +02:00
Justin M. Keyes
f3b7444e66
refactor(lua): vim.keymap.set tests, docs #30511 2024-09-25 07:01:27 -07:00
zeertzjq
052875b9dc
fix(paste): only record a paste when it's from RPC (#30491)
Problem:  When using nvim_paste in a mapping during a macro recording,
          both the mapping and the paste are recorded, causing the paste
          to be performed twice when replaying the macro.
Solution: Only record a paste when it is from RPC.

Unfortunately this means there is no way for a script to make a recorded
paste. A way to enable that can be discussed later if there is need.
2024-09-24 11:48:40 +00:00
zeertzjq
d831392b15
feat(paste): unify cancel and error behavior (#30476)
Before this PR, the behavior of nvim_paste is:
- When vim.paste() returns false, return false to the client, but treat
  following chunks normally (i.e. rely on the client cancelling the
  paste as expected).
- When vim.paste() throws an error, still return true to the client, but
  drain the following chunks in the stream without calling vim.paste().

There are two problems with such behavior:
- When vim.paste() errors, the client is still supposed to send the
  remaining chunks of the stream, even though they do nothing.
- Having different code paths for two uncommon but similar situations
  complicates maintenance.

This PR makes both the cancel case and the error case return false to
the client and drain the remaining chunks of the stream, which, apart
from sharing the same code path, is beneficial whether the client checks
the return value of nvim_paste or not:
- If the client checks the return value, it can avoid sending the
  following chunks needlessly after an error.
- If the client doesn't check the return value, chunks following a
  cancelled chunk won't be pasted on the server regardless, which leads
  to less confusing behavior.
2024-09-24 07:14:14 +08:00
Justin M. Keyes
17027d6472 refactor(api): rename Dictionary => Dict
In the api_info() output:

    :new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val')
    ...

    {'return_type': 'ArrayOf(Integer, 2)', 'name': 'nvim_win_get_position', 'method': v:true, 'parameters': [['Window', 'window']], 'since': 1}

The `ArrayOf(Integer, 2)` return type didn't break clients when we added
it, which is evidence that clients don't use the `return_type` field,
thus renaming Dictionary => Dict in api_info() is not a breaking change.
2024-09-23 14:42:57 +02:00
Justin M. Keyes
737f58e232 refactor(api)!: rename Dictionary => Dict
In the api_info() output:

    :new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val')
    ...

    {'return_type': 'ArrayOf(Integer, 2)', 'name': 'nvim_win_get_position', 'method': v:true, 'parameters': [['Window', 'window']], 'since': 1}

The `ArrayOf(Integer, 2)` return type didn't break clients when we added
it, which is evidence that clients don't use the `return_type` field,
thus renaming Dictionary => Dict in api_info() is not (in practice)
a breaking change.
2024-09-23 14:42:57 +02:00
zeertzjq
5acdc4499e
test(tui_spec): prevent another case of race between paste and input (#30481)
Problem:  When input immediately follows end of bracketed paste, the
          nvim_input may be processed before the nvim_paste.
Solution: Ensure some waiting after the end of a bracketed paste.
2024-09-23 11:50:57 +00:00
zeertzjq
bfe0acaea1
vim-patch:9.1.0740: incorrect internal diff with empty file (#30471)
Problem:  incorrect internal diff with an empty file
Solution: Set pointer to NULL, instead of using an empty line file
          (Yukihiro Nakadaira)

When using internal diff, empty file is read as one empty line file.
So result differs from external diff.

closes: vim/vim#15719

f1694b439b

Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
2024-09-23 12:04:07 +08:00
Lewis Russell
511b991e66 feat(fs.lua): add vim.fs.rm()
Analogous to the shell `rm` command.
2024-09-22 15:05:24 +01:00
Evgeni Chasnovski
29bceb4f75
docs(api): nvim_get_runtime_file preserves 'runtimepath' order #30454 2024-09-22 03:51:22 -07:00
zeertzjq
e697c1b43d
fix(paste): improve repeating of pasted text (#30438)
- Fixes 'autoindent' being applied during redo.
- Makes redoing a large paste significantly faster.
- Stores pasted text in the register being recorded.

Fix #28561
2024-09-22 06:02:48 +08:00
Christian Clason
4e4b1b6590 test(terminal): unskip wrap tests on windows
These should have been unskipped again when reflow was reenabled.
2024-09-21 19:00:52 +02:00
Lewis Russell
e5c174421d test: support upvalues in exec_lua 2024-09-21 16:04:09 +01:00
zeertzjq
f01c764cc6
vim-patch:35699f1: runtime(vim): Update base-syntax, improve folding function matches (#30427)
- Allow function command modifiers.
- Match function bodies starting with empty lines.

Command modifiers reported by @Konfekt.

fixes vim/vim#15671
closes: vim/vim#15674

35699f1749

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
2024-09-20 06:59:46 +08:00
zeertzjq
7dbbaaec3f
refactor!: rename 'jumpoptions' flag "unload" to "clean" (#30418)
Follow-up to #29347
2024-09-19 18:05:27 +08:00
Justin M. Keyes
ff85e54939
feat(tui): builtin UI (TUI) sets client info #30397
Problem:
The default builtin UI client does not declare its client info. This
reduces discoverability and makes it difficult for plugins to identify
the UI.

Solution:
- Call nvim_set_client_info after attaching, as recommended by `:help dev-ui`.
- Also set the "pid" field.
- Also change `ui_active()` to return a count. Not directly relevant to
  this commit, but will be useful later.
2024-09-18 04:14:06 -07:00
Justin M. Keyes
23dcd7cd73 test(vim.ui.open): opt.cmd 2024-09-16 11:58:04 +02:00
Justin M. Keyes
5792546777
refactor(tests): rename terminal/testutil.lua => testterm.lua #30372
This module is generally used by any tests that need the full Nvim TUI
instead of `screen.lua`. Thus it should live in `functional/` instead of
in `functional/terminal/`.
2024-09-15 03:28:14 -07:00
zeertzjq
90585e47fe vim-patch:9.1.0729: Wrong cursor-screenline when resizing window
Problem:  Wrong cursor-screenline when resizing window
Solution: Invalidate saved left_col and right_col when width1 or width2
          change.

closes: vim/vim#15679

86dc4f8b43
2024-09-14 19:29:37 +08:00
Riley Bruins
b9b408a56c
feat(treesitter): start moving get_parser to return nil #30313
**Problem:** `vim.treesitter.get_parser` will throw an error if no parser
can be found.

- This means the caller is responsible for wrapping it in a `pcall`,
  which is easy to forget
- It also makes it slightly harder to potentially memoize `get_parser`
  in the future
- It's a bit unintuitive since many other `get_*` style functions
  conventionally return `nil` if no object is found (e.g. `get_node`,
  `get_lang`, `query.get`, etc.)

**Solution:** Return `nil` if no parser can be found or created

- This requires a function signature change, and some new assertions in
  places where the parser will always (or should always) be found.
- This commit starts by making this change internally, since it is
  breaking. Eventually it will be rolled out to the public API.
2024-09-13 05:09:11 -07:00
Justin M. Keyes
5931f780e0
feat(log): use "ui" as default name for TUI client #30345
The default "session name" for the builtin TUI is "ui".

before:

    INF 2024-09-10T14:57:35.385 hello.sock os_exit:692: Nvim exit: 1
    INF 2024-09-10T14:57:35.388 ?.4543     os_exit:692: Nvim exit: 1

after:

    INF 2024-09-10T14:59:19.919 hello.sock os_exit:692: Nvim exit: 1
    INF 2024-09-10T14:59:19.922 ui.5684    os_exit:692: Nvim exit: 1
2024-09-11 17:25:00 -07:00
Gregory Anders
98ba65b8be
fix: replace NVIM with Nvim in default titlestring (#30348) 2024-09-11 20:32:08 +00:00
Justin M. Keyes
7b680e0ca9 test(health): "test_plug/health/init.lua" completes as "test_plug" 2024-09-11 11:40:56 +02:00
bfredl
4c5bce9cb4
Merge pull request #30295 from glepnir/nfloat
fix(highlight): floating windows inherit NormalFloat from global-ns
2024-09-10 11:11:07 +02:00
glepnir
8e81212e15 fix(highlight): floating windows inherit NormalFloat from global-ns
Problem:
floating windows did not correctly inherit the NormalFloat highlight
group from the global namespace when it was not defined in the window-specific
namespace. This led to floating windows losing their background highlight when
switching between namespaces.

Solution:
Updated the window highlight logic in update_window_hl() to handle the fallback.

This fix resolves issues with floating window backgrounds not displaying as expected
in certain namespace configurations.
2024-09-10 13:31:42 +08:00
Justin M. Keyes
c8e3618e0e fix(test): "tempdir not a directory" in CI logs
$NVIM_LOG_FILE: /Users/runner/work/neovim/neovim/build/.nvimlog
    WRN 2024-09-08T21:48:13.279 ?.21134    vim_mktempdir:3281: $TMPDIR tempdir not a directory (or does not exist): TMPDIR-should-be-ignored
    WRN 2024-09-08T21:48:13.312 ?.21137    vim_mktempdir:3281: $TMPDIR tempdir not a directory (or does not exist): TMPDIR-should-be-ignored
2024-09-09 12:23:54 +02:00
Justin M. Keyes
ed832b9ddf refactor(test): rename alter_slashes, invert its behavior
- `alter_slashes` belongs in `testutil.lua`, not `testnvim.lua`.
- `alter_slashes` is an unusual name. Rename it to `fix_slashes`.
- invert its behavior, to emphasize that `/` slashes are the preferred,
  pervasive convention, not `\` slashes.
2024-09-09 12:23:54 +02:00
Justin M. Keyes
8a2aec9974
fix(startup): server fails if $NVIM_APPNAME is relative dir #30310
Problem:
If $NVIM_APPNAME is a relative dir path, Nvim fails to start its
primary/default server, and `v:servername` is empty.
Root cause is d34c64e342, but this wasn't
noticed until 96128a5076 started reporting the error more loudly.

Solution:
- `server_address_new`: replace slashes "/" in the appname before using
  it as a servername.
- `vim_mktempdir`: always prefer the system-wide top-level "nvim.user/"
  directory. That isn't intended to be specific to NVIM_APPNAME; rather,
  each *subdirectory* ("nvim.user/xxx") is owned by each Nvim instance.
  Nvim "apps" can be identified by the server socket(s) stored in those
  per-Nvim subdirs.

fix #30256
2024-09-08 12:48:32 -07:00
Christian Clason
3a88113246 fix(lua): revert vim.tbl_extend behavior change and document it
Problem: vim.tbl_deep_extend had an undocumented feature where arrays
(integer-indexed tables) were not merged but compared literally (used
for merging default and user config, where one list should overwrite the
other completely). Turns out this behavior was relied on in quite a
number of plugins (even though it wasn't a robust solution even for that
use case, since lists of tables (e.g., plugin specs) can be array-like
as well).

Solution: Revert the removal of this special feature. Check for
list-like (contiguous integer indices) instead, as this is closer to the
intent. Document this behavior.
2024-09-08 21:06:13 +02:00
Justin M. Keyes
08153ddd1c
fix(startup): ignore broken $XDG_RUNTIME_DIR #30285
Problem:
$XDG_RUNTIME_DIR may be broken on WSL, which prevents starting (and even
building) Nvim. #30282

Solution:
- When startup fails, mention the servername in the error message.
- If an autogenerated server address fails, log an error and continue
  with an empty `v:servername`. It's only fatal if a user provides a bad
  `--listen` or `$NVIM_LISTEN_ADDRESS` address.

Before:

    $ nvim --headless --listen ./hello.sock
    nvim: Failed to --listen: "address already in use"
    $ NVIM_LISTEN_ADDRESS='./hello.sock' ./build/bin/nvim --headless
    nvim: Failed to --listen: "address already in use"

After:

    $ nvim --headless --listen ./hello.sock
    nvim: Failed to --listen: address already in use: "./hello.sock"
    $ NVIM_LISTEN_ADDRESS='./hello.sock' ./build/bin/nvim --headless
    nvim: Failed $NVIM_LISTEN_ADDRESS: address already in use: "./hello.sock"
2024-09-08 07:07:19 -07:00
Tristan Knight
003b8a251d
fix(lsp): handle out-of-bounds character positions #30288
Problem:
str_byteindex_enc could return an error if the index was longer than the
lline length. This was handled in each of the calls to it individually

Solution:
* Fix the call at the source level so that if the index is higher than
  the line length, line length is returned as per LSP specification
* Remove pcalls on str_byteindex_enc calls. No longer needed now that
  str_byteindex_enc has a bounds check.
2024-09-08 03:44:46 -07:00
Justin M. Keyes
95b65a7554 test(tohtml): simplify font test 2024-09-08 12:17:42 +02:00
yayoyuyu
e37404f7fe fix(tohtml): enclose font-family names in quotation marks
Font-family names must be enclosed in quotation marks to ensure that
fonts are applied correctly when there are spaces in the name.

Fix an issue where multiple fonts specified in `vim.o.guifont` are
inserted as a single element, treating them as a single font.

Support for escaping commas with backslash and ignoring spaces
after a comma.

ref `:help 'guifont'`
2024-09-08 12:15:50 +02:00
Justin M. Keyes
5ddf2ab768
test(lua): tbl_deep_extend "after second argument" #30297 2024-09-07 09:41:02 -07:00
bfredl
439d031742
Merge pull request #30236 from luukvbaal/invalid
fix(decor): revise marktree metadata for invalid marks
2024-09-06 13:13:51 +02:00
bfredl
c81cb02dd6
Merge pull request #30272 from bfredl/replace_emoji
fix(multibyte): handle backspace of wide clusters in replace mode
2024-09-06 12:08:26 +02:00
bfredl
fa99afe35e fix(multibyte): handle backspace of wide clusters in replace mode
Make utf_head_off more robust against invalid sequences
and embedded NUL chars
2024-09-06 10:22:29 +02:00
Justin M. Keyes
76aa3e52be
feat(defaults): popupmenu "Open in browser", "Go to definition" #30261
- Use the popup to expose more features such as LSP and gx.
- Move the copy/paste items lower in the menu, they are lower priority.
2024-09-05 05:56:00 -07:00
Justin M. Keyes
975aeee537
test: avoid noise in CI logs #30264
Problem:
Since 96128a5076 the test logs have noise from tests that *expect*
failures:

    $NVIM_LOG_FILE: /tmp/cirrus-ci-build/build/.nvimlog
    (last 100 lines)
    ERR 2024-09-04T13:38:45.181 T949.28335.0/c terminfo_start:486: uv_pipe_open failed: no such device or address
    ERR 2024-09-04T13:38:45.181 T949.28335.0/c flush_buf:2527: uv_write failed: bad file descriptor
    ERR 2024-09-04T13:38:45.181 T949.28335.0/c flush_buf:2527: uv_write failed: bad file descriptor
    WRN 2024-09-04T13:43:43.294 ?.35904    server_start:173: Failed to start server: address already in use: /…/Xtest_tmpdir/…/T7159.35895.0
    WRN 2024-09-04T13:43:43.314 ?.35907    server_start:173: Failed to start server: illegal operation on a directory: /
    ERR 2024-09-04T13:43:43.332 ?.35909    socket_watcher_init:60: Host lookup failed: https://example.com

Solution:
Rewrite the test to use `vim.system()`. Set NVIM_LOG_FILE in the child
process to a "throwaway" logfile.
2024-09-05 02:39:58 -07:00
Tristan Knight
882a450a29
fix(lsp): handle locations exceeding line length #30253
Problem:
LSP spec [states](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position)
that "if the character value is greater than the line length it defaults
back to the line length", but `locations_to_items` fails in that case.

Solution:
Adjust locations_to_items to follow the spec.

closes #28281
2024-09-05 00:23:11 -07:00
Luuk van Baal
34ded4d97b fix(decor): exclude invalid marks from meta total
Problem:  Marktree meta count still includes invalidated marks, making
          guards that check the meta total ineffective.
Solution: Revise marktree metadata when in/revalidating a mark.
2024-09-04 15:13:12 +02:00
Lewis Russell
b6e350a6b4 fix(lua): allows tables with integer keys to be merged in tbl_deep_extend
- The exclusion of lists was never justified in the commit history and is
  the wrong thing to do for a function that deals with tables.

- Move the error checks out of the recursive path.

Fixes #23654
2024-09-04 11:34:19 +01:00
Tristan Knight
45e76acaa0
feat(lsp): support hostname in rpc.connect #30238
Updated the `rpc.connect` function to support connecting to LSP servers
using hostnames, not just IP addresses. This change includes updates to
the documentation and additional test cases to verify the new
functionality.

- Modified `connect` function to resolve hostnames.
- Updated documentation to reflect the change.
- Added test case for connecting using hostname.

Added a TCP echo server utility function to the LSP test suite. This
server echoes the first message it receives and is used in tests to
verify LSP server connections via both IP address and hostname.
Refactored existing tests to use the new utility function.
2024-09-03 08:10:39 -07:00
vanaigr
d1d7d54680
fix(api): nvim_buf_get_text() crashes with large negative column #28740
Problem:
crash when calling nvim_buf_get_text() with a large negative start_col:

    call nvim_buf_get_text(0, 0, -123456789, 0, 0, {})

Solution:
clamp start_col after subtracting it from the line length.
2024-09-03 06:01:42 -07:00
Justin M. Keyes
ea2d949351
test: tmpname(create:boolean) #30242
Problem:
137f98cf64 added the `create` parameter to `tmpname()` but didn't
fully implement it.

Solution:
- Update impl for the `os.tmpname()` codepath.
- Inspect all usages of `tmpname()`, update various tests.
2024-09-03 02:18:17 -07:00
Justin M. Keyes
96128a5076 feat(startup): validate --listen address
Problem:
`nvim --listen` does not error on EADDRINUSE. #30123

Solution:
Now that `$NVIM_LISTEN_ADDRESS` is deprecated and input *only* (instead
of the old, ambiguous situation where it was both an input *and* an
output), we can be fail fast instead of trying to "recover". This
reverts the "recovery" behavior of
704ba4151e, but that was basically
a workaround for the fragility of `$NVIM_LISTEN_ADDRESS`.
2024-09-02 22:41:41 +02:00
Justin M. Keyes
137f98cf64 test: tmpname() can skip file creation 2024-09-02 20:19:50 +02:00
Justin M. Keyes
61e9137394
docs: misc #28970 2024-09-01 13:01:24 -07:00
Gregory Anders
6913c5e1d9
feat(treesitter)!: default to correct behavior for quantified captures (#30193)
For context, see https://github.com/neovim/neovim/pull/24738. Before
that PR, Nvim did not correctly handle captures with quantifiers. That
PR made the correct behavior opt-in to minimize breaking changes, with
the intention that the correct behavior would eventually become the
default. Users can still opt-in to the old (incorrect) behavior for now,
but this option will eventually be removed completely.

BREAKING CHANGE: Any plugin which uses `Query:iter_matches()` must
update their call sites to expect an array of nodes in the `match`
table, rather than a single node.
2024-09-01 18:01:53 +00:00
luukvbaal
97f8d1de1c
vim-patch:9.1.0708: Recursive window update does not account for reset skipcol (#30217)
Problem:  Window is updated with potentially invalid skipcol in recursive
          window update path. I.e. cursor outside of visible range in
          large line that does not fit.
Solution: Make sure it is valid (Luuk van Baal).

3d5065fc75
2024-09-01 20:19:19 +08:00
zeertzjq
bfa365a872
fix(completion): don't include <Lua function> in -complete= (#30209) 2024-09-01 07:57:09 +08:00
zeertzjq
ea2998fec9
vim-patch:9.1.0704: inserting with a count is inefficient (#30206)
Problem:  inserting with a count is inefficient
Solution: Disable calculation of the cursor position and topline, if a
          count has been used (Ken Takata)

Optimize insertion when using :normal 10000ix.

This patch optimizes the insertion with a large count (e.g. `:normal
10000ix`).

It seems that calculation of the cursor position for a long line is slow
and it takes O(n^2). Disable the calculation if not needed.

Before:
```
$ time ./vim --clean -c 'normal 10000ix' -cq!
real    0m1.879s
user    0m1.328s
sys     0m0.139s

$ time ./vim --clean -c 'normal 20000ix' -cq!
real    0m5.574s
user    0m5.421s
sys     0m0.093s

$ time ./vim --clean -c 'normal 40000ix' -cq!
real    0m23.588s
user    0m23.187s
sys     0m0.140s
```

After:
```
$ time ./vim --clean -c 'normal 10000ix' -cq!
real    0m0.187s
user    0m0.046s
sys     0m0.093s

$ time ./vim --clean -c 'normal 20000ix' -cq!
real    0m0.217s
user    0m0.046s
sys     0m0.108s

$ time ./vim --clean -c 'normal 40000ix' -cq!
real    0m0.278s
user    0m0.093s
sys     0m0.140s

$ time ./vim --clean -c 'normal 80000ix' -cq!
real    0m0.494s
user    0m0.311s
sys     0m0.140s

$ time ./vim --clean -c 'normal 160000ix' -cq!
real    0m1.302s
user    0m1.140s
sys     0m0.094s
```

closes: vim/vim#15588

09b80d23cf

Co-authored-by: Ken Takata <kentkt@csc.jp>
2024-09-01 06:21:36 +08:00
zeertzjq
55dc482e75
fix(completion): fix inconsistent Enter behavior (#30196)
Problem:  Behavior of Enter in completion depends on typing speed.
Solution: Don't make whether Enter selects original text depend on
          whether completion has been interrupted, which can happen
          interactively with a slow completion function.
2024-08-31 04:03:30 +08:00
glepnir
42ed0ffad9
fix(lsp): when prefix is non word add all result into matches (#30044)
Problem: prefix can be a symbol like period, the fuzzy matching can't
handle it correctly.

Solution: when prefix is empty or a symbol add all lsp completion
result into matches.
2024-08-30 20:23:49 +02:00
bfredl
cfdf68a7ac feat(mbyte): support extended grapheme clusters including more emoji
Use the grapheme break algorithm from utf8proc to support grapheme
clusters from recent unicode versions.

Handle variant selector VS16 turning some codepoints into double-width
emoji. This means we need to use ptr2cells rather than char2cells when
possible.
2024-08-30 11:49:09 +02:00
Riley Bruins
59baa5e8a1
fix(tohtml): apply sp color if present #30110
Problem:
Things like underlines are always given a default foreground highlight
regardless of the value of `sp`.

Solution:
Check for `sp` first, and apply that color to the text decoration color if it
exists.

Limitations:
If there is no value of `sp`, vim applies a text decoration color that matches
the foreground of the text. This is still not implemented (and seems like a much
more complex problem): in TOhtml, the underline will still be given a default
foreground highlight.
2024-08-29 09:36:33 -07:00
Lewis Russell
688b961d13 feat(treesitter): add support for wasm parsers
Problem: Installing treesitter parser is hard (harder than
climbing to heaven).

Solution: Add optional support for wasm parsers with `wasmtime`.

Notes:

* Needs to be enabled by setting `ENABLE_WASMTIME` for tree-sitter and
  Neovim. Build with
  `make CMAKE_EXTRA_FLAGS=-DENABLE_WASMTIME=ON
  DEPS_CMAKE_FLAGS=-DENABLE_WASMTIME=ON`
* Adds optional Rust (obviously) and C11 dependencies.
* Wasmtime comes with a lot of features that can negatively affect
  Neovim performance due to library and symbol table size. Make sure to
  build with minimal features and full LTO.
* To reduce re-compilation times, install `sccache` and build with
  `RUSTC_WRAPPER=<path/to/sccache> make ...`
2024-08-26 16:44:03 +02:00
zeertzjq
cf44121f7f
vim-patch:9.1.0694: matchparen is slow on a long line (#30134)
Problem:  The matchparen plugin is slow on a long line.
Solution: Don't use a regexp to get char at and before cursor.
          (zeertzjq)

Example:

```vim
  call setline(1, repeat(' foobar', 100000))
  runtime plugin/matchparen.vim
  normal! $hhhhhhhh
```

closes: vim/vim#15568

81e7513c86
2024-08-25 06:07:43 +08:00
zeertzjq
bb4b6b427c
vim-patch:9.1.0690: cannot set special highlight kind in popupmenu (#30128)
Problem:  cannot set special highlight kind in popupmenu
Solution: add kind_hlgroup item to complete function
          (glepnir)

closes: vim/vim#15561

38f99a1f0d

Co-authored-by: glepnir <glephunter@gmail.com>
2024-08-24 08:38:05 +08:00
glepnir
1f5bcc7c4e
feat(lsp): completion opts support custom item conversion (#30060)
Problem: Some items of completion results include function signatures that can
cause the pum to be very long when a function has many params, because pum
scales with the longest word/abbr.

Solution: add custom covert function that can customise abbr to remove params.
2024-08-22 21:42:27 +02:00
zeertzjq
a8fbe1d409
fix(decor): don't use separate DecorSignHighlight for url (#30096) 2024-08-20 08:20:19 +08:00
ibhagwan
1d11808bfd
fix(terminal): interrupt/got_int hangs terminal (#30056)
Upon `terminal_enter`, `mapped_ctrl_c` is set in order to avoid `CTRL-C`
interrupts (which is proxied to the terminal process instead), `os_inchar`
will then test `mapped_ctrl_c` against `State` and set `ctrl_c_interrupts=false`
which prevents `process_ctrl_c` from setting `got_int=true` in a terminal
state.

However, if `got_int` is set outside of `process_ctrl_c`, e.g. via
`interrupt()`, this will hang the neovim process as `terminal_execute` will
enter an endless loop as `got_int` will never be cleared causing `safe_vgetc`
to always return `Ctrl_C`.

A minimal example reproducing this bug:
```vim
:autocmd TermEnter * call timer_start(500, {-> interrupt()})
:terminal
:startinsert
```

To fix, we make sure `got_int` is cleared inside `terminal_execute` when
it detects `Ctrl_C`.

Closes #20726

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-08-20 06:23:56 +08:00