hrsh7th / nvim-cmp

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

Setting `autocomplete = true` causes exception #1566

Open tlindsay opened 1 year ago

tlindsay commented 1 year 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" },
  }),
}

cmp.setup.cmdline(':', {
  mapping = cmp.mapping.preset.cmdline(),
  completion = { autocomplete = true },
  sources = cmp.config.sources({
    { name = 'path' },
  }, {
    { name = 'cmdline' },
  }),
})
EOF

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

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

Description

I updated my neovim plugins this morning. This was the diff from my Lazy.nvim log:

    ● nvim-cmp 8.67ms  start
        935b406 Improve misc.merge (19 hours ago)
        5a80cd4 Fix #897 (2 days ago)

Steps to reproduce

1) $ nvim -u ~/cmp-repro.vim 2) Type :

Expected behavior

I should be in my cmdline with no errors

Actual behavior

I'm getting the following exception

Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got boolean
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_contains'
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:168: 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:304: in function 'callback'
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/async.lua:138: in function </tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/async.lua:136>

Additional context

My minimal config to reproduce this error includes the following block:

cmp.setup.cmdline(':', {
  mapping = cmp.mapping.preset.cmdline(),
  completion = { autocomplete = true },
  sources = cmp.config.sources({
    { name = 'path' },
  }, {
    { name = 'cmdline' },
  }),
})

Manually setting autocomplete = false fixes the error. I believe this issue is related to #1565, however PR #1563 does not fix my issue.

ribru17 commented 1 year ago

I think this may be intended, at least judging by the doc. It states that the value can be cmp.TriggerEvent[] or false, rather than cmp.TriggerEvent[] or boolean.

qrsforever commented 1 year ago

same problem, update to :

commit 935b4069ce73b60ba9075bf05ee6ab50ed3af1a9 (grafted, HEAD -> main, origin/main, origin/HEAD)
Author: hrsh7th <629908+hrsh7th@users.noreply.github.com>
Date:   Mon May 8 11:41:15 2023 +0900

    Improve misc.merge

error:

Error executing vim.schedule lua callback: vim/shared.lua:0: t: expected table, got boolean
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_contains'
        ....config/nvim/pack/packer/start/nvim-cmp/lua/cmp/core.lua:168: in function 'autoindent'
        ....config/nvim/pack/packer/start/nvim-cmp/lua/cmp/core.lua:161: in function 'on_change'
        ....config/nvim/pack/packer/start/nvim-cmp/lua/cmp/init.lua:304: in function 'callback'
        .../nvim/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:138: in function <.../nvim/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:136>
:
hrsh7th commented 1 year ago

Hm... I intent the false or cmp.TriggerEvent[] but I don't intent that the change should be breaking anything.

At least, please change the value to cmp.TriggerEvent[]. I'll check codes anyway.

tlindsay commented 1 year ago

Changing that line to completion = { autocomplete = { require('cmp.types').cmp.TriggerEvent.TextChanged } }, fixed the issue.

I think that my config has actually not been working as intended for a long time, I just didn't notice because autocomplete = true would silently fail.

erancx commented 1 year ago

Changing that line to completion = { autocomplete = { require('cmp.types').cmp.TriggerEvent.TextChanged } }, fixed the issue.

I think that my config has actually not been working as intended for a long time, I just didn't notice because autocomplete = true would silently fail.

weird that does seem to work here.

    completion = { autocomplete = { require('cmp.types').cmp.TriggerEvent.TextChanged } },
    sources = {
        { name = "nvim_lsp" },
        { name = "buffer" },
        { name = "luasnip" },
        { name = "nvim_lsp_signature_help" },
        { name = "path" },
    },

and I'm still getting with NVIM v0.9.0

cmp:GHOST_TEXT: Error executing lua: ...hare/nvim/lazy/nvim-cmp/lua/cmp/view/ghost_text_view.lua:40: attempt to index local 'c'
erancx commented 1 year ago

oh, I disabled

    experimental = {
        ghost_text = false,
    }

and now it's seems to be working again.