hrsh7th / nvim-cmp

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

`custom_entries_view` throws an error when the window is too small #1759

Closed hankertrix closed 3 months ago

hankertrix commented 7 months ago

FAQ

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
EOF

Description

...d/vim-plug/nvim-cmp/lua/cmp/view/custom_entries_view.lua:210: Expected Lua number

This error keeps occurring every single time when cmp tries to open the completion menu to complete the word.

Steps to reproduce

  1. Use the configuration.
  2. Make the terminal window tiny, as shown below: image
  3. The error will keep occurring when there is more than 1 completion item.

Expected behavior

No error occurs and I get a tiny menu that has 1 or 2 words for the auto-completion. It used to work like that until something changed.

Actual behavior

...d/vim-plug/nvim-cmp/lua/cmp/view/custom_entries_view.lua:210: Expected Lua number

This error keeps occurring and it's nearly impossible to type anything.

Additional context

While the terminal window being that tiny may seem unreasonable, this actually happens a lot when using Firenvim on small text areas such as search bars and text boxes for chat apps.

joshuadanpeterson commented 3 months ago

I also received this error, particularly when I'm trying to comment on GitHub issues because the input window is so small. I used the fix in this comment, :set lines=20, to at least enlarge the firenvim input window so I'm not overwhelmed with error messages, and then I just clear the error messages. Setting the number of lines takes away the error, so I added this script to my nvim config and it removed the error:

-- set firenvim window height to kill 'custom_entries_view' error
if vim.g.started_by_firenvim then
    vim.api.nvim_create_autocmd("BufEnter", {
        callback = function()
            vim.o.lines = 20
        end,
    })
end
hankertrix commented 3 months ago

I see, thanks! It is not ideal, since the firenvim window wouldn’t fit nicely in the input box, but it’ll have to do for now while waiting for my pull request to be merged.

joshuadanpeterson commented 3 months ago

@hankertrix Agreed. I tweaked the script a bit after I posted it to adjust the size of the firenvim window. vim.o.lines = 12 is the lowest number of lines I could go without retriggering the error. I did have to refresh the window a few times in order for it to take affect. And it still covers the submit and image upload buttons, but you don't need that anyway while you're in the firenvim buffer.

Screenshot 2024-03-15 at 23 44 04
hankertrix commented 3 months ago

Ahhhh I see, that's great! Thank you for figuring this out!

joshuadanpeterson commented 3 months ago

Happy to help! It was bugging me too lol

hankertrix commented 3 months ago

Pull request #1824 has been merged, closing this issue since GitHub didn't automatically close this issue for some reason.