hrsh7th / nvim-cmp

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

Error messages when inserting past null character #1843

Open lukasvrenner opened 7 months ago

lukasvrenner 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

Suppose you open a text file, and there is a null character before the end of the file. If the cursor is past the null character (to the left of it), and the mode is switched to insert mode, and then a character is typed, error messages pop up: Error detected while processing TextChangedI Autocommands for "*": Error executing lua callback: Vim:E976: using Blob as a String stack traceback: [C]: in function '_dirname' ...nvim/site/pack/paqs/start/cmp-path/lua/cmp_path/init.lua:41: in function 'complet e' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/source.lua:326: in function 'complete' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:299: in function 'complete' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:169: in function 'callback' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:229: in function 'autoindent' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:161: in function 'on_change' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/init.lua:338: in function 'callback' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/autocmd.lua:49: in function 'emit' /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/autocmd.lua:23: in function </tmp/plugg ed/vim-plug/nvim-cmp/lua/cmp/utils/autocmd.lua:22> Typing another character makes the error disappear, and both characters show up.

Steps to reproduce

run the following commands into a shell:

touch test.txt
find -name test.txt -print0 | nvim -u ~/cmp-repro.vim

while in Normal mode, hit 'A' to enter Insert mode, at the end of the file. Then, type any character.

Expected behavior

No error messages.

Actual behavior

Error messages pop up. They do not appear if only inserting text before the null character.

Additional context

Thank you for the wonderful project!