hrsh7th / nvim-cmp

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

select_next_item() causing LSP crash #1917

Open SethGower opened 1 month ago

SethGower commented 1 month 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 }),
    ['<Tab>'] = cmp.mapping.select_next_item()
  },

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

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

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

Description

I am having an issue that I seem to have boiled down to when I select a completion candidate with cmp.mapping.select_next_item(). The LSP Server crashes when I do this (or select_prev_item() for that matter). Everything seems fine when I do just cmp.mapping.confirm{select = true}.

https://github.com/VHDL-LS/rust_hdl/issues/300

Steps to reproduce

Expected behavior

It should just select the candidate as normal

Actual behavior

The LSP server crashes. I reported this originally over on the vhdl_ls repo, but they weren't able to reproduce in VSCode (neither was I). It doesn't always happen, I found a case where it doesn't happen, however given it doesn't happen at all in VSCode, I am not sure if it's the server or client (I'm including nvim-cmp in "the client").

Additional context

Example VHDL file to use. After the end process q_proc; line, if you do o_| where | is the cursor, and then hit <Tab> to select the next completion candidate, the LSP should crash.

Please see my various comments in the other issue for logs during this process (which were captured not using the minimal config, FYI).

library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;

entity test1 is
    port (
        i_clk  : in    std_logic;
        i_rstn : in    std_logic;
        i_d    : in    std_logic;
        o_q    : out   std_logic;
        o_qn   : out   std_logic
    );
end entity test1;

architecture behav of test1 is

begin

    o_q_proc : process (i_clk) is
    begin

        if rising_edge(i_clk) then
            if (i_rstn = '0') then
                o_q <= '0';
            else
                o_q <= i_d;
            end if;
        end if;

    end process o_q_proc;

end architecture behav;
Chris44442 commented 1 month ago

I have the same issue. Strangely enough when I scroll through the auto complete list with the arrow keys, the LSP does not crash. With cmp.mapping.select_next_item() it crashes.