hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.08k stars 400 forks source link

[Bug] `lua require"cmp.utils.feedkeys".run(...)` is getting spammed into buffer #2033

Open drazil100 opened 2 months ago

drazil100 commented 2 months ago

FAQ

Announcement

Minimal reproducible full config

vim.keymap.set('i', '<Up>',   '<C-o>gk',      { silent = true })
vim.keymap.set('i', '<Down>', '<C-o>gj',      { silent = true })

local ensure_lazy = function()
  local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
  if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
      'git',
      'clone',
      '--filter=blob:none',
      'https://github.com/folke/lazy.nvim.git',
      '--branch=stable', -- latest stable release
      lazypath,
    })
  end
  vim.opt.rtp:prepend(lazypath)
end

ensure_lazy()

-- Using Lazy.nvim
require('lazy').setup({
  -- Plugin manager itself
  { 'folke/lazy.nvim' },

  -- LSP Zero
  { 'VonHeikemen/lsp-zero.nvim',        branch = 'v4.x' },
  { 'williamboman/mason.nvim' },
  { 'williamboman/mason-lspconfig.nvim' },
  { 'neovim/nvim-lspconfig' },
  { 'hrsh7th/cmp-nvim-lsp' },
  { 'hrsh7th/nvim-cmp' },
})

Description

When holding up or down at the edge of a buffer it spams the tail end of lua require"cmp.utils.feedkeys".run(...) repeatedly into the buffer.

I am pretty sure it has triggered in the middle of the file before but it is much less likely than at the edges of the buffer and I don't really have any proof.

Steps to reproduce

This issue is EXTREMELY difficult to reproduce on a minimum config and likely will not show if your machine is at all performant. (I only experience this on my laptop with an Intel Celeron N4000 processor, 4GB of ram, and emmc memory)

  1. Open or create a large file (The size of the file isn't necessary but it seems to increase the chance the issue triggers)
  2. Switch to insert mode
  3. Hold up while at the top of the file or down at the bottom of the file

Expected behavior

No input whatsoever

Actual behavior

It spams varying amount of the tail end of lua require"cmp.utils.feedkeys".run(...) into the buffer. It can spam as little as a ) or as much as the full line though usually it only a couple of the characters unless you hold it long enough that nvim starts slowing down.

Additional context

image

Reproduction with provided minimum config:

https://youtu.be/HmgRijZhuZ4 Note: Half the video is me copying and spam pasting the config to make the file super large. Even after pasting thousands of lines of code this only cropped up once. I was holding down pretty much the entire time after I hit the bottom of the file.

Reproduction with my normal config:

https://youtu.be/b0N2umon8pQ This it shows up super easily but I only have issues with it on my low powered machine. My regular desktop does not trigger this issue. (I haven't tried super hard though)

For all I know this could be an issue with nvim itself but since the line that gets pasted is a call to this plugin's function I figured you would have the best shot at figuring out what's going on.

I'll include a copy of my full nvim config as well in the event it helps you reproduce (the .txt is cause apparently github doesn't allow uploading of lua files) init.lua

Also I don't know if the 2 insert mode mappings are contributing to the error but it didn't trigger in any of the tests without them. That could however just be because of how hard it is to trigger on the provided minimum config.

drazil100 commented 2 months ago

Looking at the code this is probably the output I'm seeing in my file https://github.com/hrsh7th/nvim-cmp/blob/ae644feb7b67bf1ce4260c231d1d4300b19c6f30/lua/cmp/utils/feedkeys.lua#L27

While I haven't looked too very deeply into this code base my assumption is that this is a race condition where if command mode is exited before it finishes executing this line it instead inserts the rest of the line into the buffer. I have no clue what's interfering with this line though.

By the way, I just want to throw it out there that I am more than willing to help test patches and stuff. This isn't a case of report and leave. Just let me know what you need from me and I'll happily help you out in trying to get this resolved.

vurentjie commented 2 weeks ago

I had posted on the other issue about this. That was quite a long time ago and I can't repro it anymore.

I also noticed I had altered my mappings at some point to use norm! instead of <c-o>.

Does this help at all?

vim.keymap.set('i', '<up>', '<cmd>norm! gk<cr>', { silent = true }) 
vim.keymap.set('i', '<down>', '<cmd>norm! gj<cr>', { silent = true })
ljkenny commented 1 week ago

@vurentjie that fixed the issue for me. Thank you!