nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

Col out of range when there is no match between typed word and LSP suggestion (?)

Open alfaix opened this issue 11 months ago • 1 comments

FAQ

  • [X] I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

Sorry, I tried to reproduce with a minimal config and failed :( I've included the stack trace that I get and some debug prints I put together, which I think should give some intuition to the underlying error (see below). If you could provide some pointers for more debugging, I'd appreciate that.

Description

I'm using pyright LSP completion as usual, when I get the following error:

Error in decoration provider cmp.view.custom_entries_view.win:
Error executing lua: .../nvim/lazy/nvim-cmp/lua/cmp/view/custom_entries_view.lua:84: Invalid 'col': out of range
stack traceback:
	[C]: in function 'nvim_buf_set_extmark'
	.../nvim/lazy/nvim-cmp/lua/cmp/view/custom_entries_view.lua:84: in function <.../nvim/lazy/nvim-cmp/lua/cmp/view/custom_entries_view.lua:57>
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	.../share/nvim/lazy/nvim-notify/lua/notify/service/init.lua:63: in function 'push'
	...ocal/share/nvim/lazy/nvim-notify/lua/notify/instance.lua:77: in function <...ocal/share/nvim/lazy/nvim-notify/lua/notify/instance.lua:41>
	...e/nvim/lazy/noice.nvim/lua/noice/view/backend/notify.lua:169: in function '_notify'
	...e/nvim/lazy/noice.nvim/lua/noice/view/backend/notify.lua:199: in function <...e/nvim/lazy/noice.nvim/lua/noice/view/backend/notify.lua:176>
	[C]: in function 'xpcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:149: in function 'try'
	...local/sh
la

The error is repeated many-many times, once every redraw I believe.

It happens right here. I added some debug prints, like so:

            local ok, _ = pcall(vim.api.nvim_buf_set_extmark, buf, custom_entries_view.ns, i, a + m.word_match_start - 1, {
              end_line = i,
              end_col = a + m.word_match_end,
              hl_group = m.fuzzy and 'CmpItemAbbrMatchFuzzy' or 'CmpItemAbbrMatch',
              hl_mode = 'combine',
              ephemeral = true,
            })
            if not ok then
              vim.api.nvim_notify(vim.inspect({ lines = vim.api.nvim_buf_get_lines(buf, i, i + 1, false), a = a, start = m.word_match_start, field = field }), vim.log.levels.INFO, {})
            end

And this prints

{
  a = 0,
  lines = { "RepeatedScalarFieldContainer~          Class    google.protobuf.internal.containers " },
  start = -1
}

With these 2 values, it means that a + m.word_match_start - 1 is -2, which is what is triggering the error. However, I don't understand what is the special case here: what does it mean if m.word_match_start is -1? The word I entered when I saw this error was recons (trying to type reconstructed), does it mean there is no match between what I entered and the suggested words?

Either way, I would really appreciate some pointers - what I did so far is just avoid that line if m.word_match_start == -1, that makes the plugin usable again for me

Steps to reproduce

As I said, I don't have a great repro, sorry. I think it just happens when there is no match between what I typed and what LSP is suggesting, but I can't reliably reproduce this.

Expected behavior

No error messages, just completion.

Actual behavior

A ginormous wall of error messages, 1 error message every redraw, CPU explodes redrawing all these notifications, laptop gets very laggy.

Additional context

I'm using latest master (as of today).

NVIM v0.10.0-dev-737+gdf2f5e391
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Run "nvim -V1 -v" for more info

The issue happened with pyright 1.1.316.

Having made the dummy fix (check for -1 before calling nvim_api_set_extmark), the plugin is usable again for me, but I think there's a deeper underlying issue (matching is incorrect or missing match is not accounted for). I would appreciate any pointers in figuring it out - sorry again that I can't create a good repro, it's hard to trigger the LSP server into giving suggestions that don't match input.

alfaix avatar Jul 28 '23 18:07 alfaix

Hi @alfaix In my case this settings caused issue window = { completion = { side_padding = 0, }, documentation = { side_padding = 0, }, }, probably error happens, when scrollbar appears/disappears.

chshrct avatar Sep 27 '23 19:09 chshrct