nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

config merging does not convert vim.NIL to nil

Open wookayin opened this issue 3 years ago • 5 comments

FAQ

  • [X] I have checked the FAQ and it didn't resolve my problem.

Issues

  • [X] I have checked existing issues and there are no open or closed issues with the same problem.

Neovim Version

v0.7.0-dev+963-g082ff2190

Minimal reproducible full config

cmp version: dbc7229

minimal.vim

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/vim-vsnip'
"Plug 'gelguy/wilder.nvim'
"Plug 'romgrk/fzy-lua-native'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
local cmp_types = require('cmp.types.cmp')

cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-y>'] = cmp.config.disable,
    ['<C-e>'] = cmp.mapping.close(),
    ['<Down>'] = cmp.mapping.select_next_item({ behavior = cmp_types.SelectBehavior.Select }),
    ['<Up>'] = cmp.mapping.select_prev_item({ behavior = cmp_types.SelectBehavior.Select }),
    ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp_types.SelectBehavior.Insert }),
    ['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp_types.SelectBehavior.Insert }),
    ['<CR>'] = cmp.mapping.confirm({ select = false }),
    ['<Tab>'] = {
      i = function(fallback)  -- see GH-231, GH-286
        if cmp.visible() then cmp.select_next_item()
        elseif has_words_before() then cmp.complete()
        else fallback() end
      end,
      c = cmp.config.disable, -- see GH-880
    },
    ['<S-Tab>'] = {
      i = function(fallback)
        if cmp.visible() then cmp.select_prev_item()
        else fallback() end
      end,
      c = cmp.config.disable,
    },
  },

  sources = {
    { name = "buffer" },
  },
}

Note the config ['<Tab>'] = { .... c = cmp.config.disable } to disable TAB mappings in the command line.

Description

<Tab> keys are broken again. When pressing it, an error occurs.

Steps to reproduce

Press <Tab> in the command-line.

Expected behavior

Actual behavior

image
E5108: Error executing lua /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:113: attempt to call a userdata value
stack traceback:
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:113: in function 'on_keymap'
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/core.lua:145: in function 'callback'
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/keymap.lua:114: in function </tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/keymap.lua:108>
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/keymap.lua:244: in function </tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/keymap.lua:243>

Additional context

This happened due to recent breaking changes in the keymappings.

Can we completely disable and prevent cmp from taking <cmp> keymaps via the "delegation" or "fallback" mechanism? As in #590, I absolutely don't want the following cmap to exist when keymaps are configured to be disabled:

c  <Tab>       * <Cmd>call v:lua.cmp.utils.keymap.set_map(1)<CR> 

wookayin avatar Apr 13 '22 22:04 wookayin

Well...

  c = cmp.config.disable, -- see GH-880

The mapping config is needed? As I know the default mappings are removed.

Shougo avatar Apr 14 '22 00:04 Shougo

Hi @Shougo, thanks for the comment! After today's breaking change #895, this is not needed any more. I tried removing this line, and indeed no more errors.

However, that specific line was necessary, until today; four days ago #880 required us to explicitly disable it (and now the default mapping has been removed).

Even with the explicit disabling, it should behave the same.

wookayin avatar Apr 14 '22 00:04 wookayin

OK. The main problem seems cmp.config.disable does not work.

Shougo avatar Apr 14 '22 00:04 Shougo

Exactly! cmp.config.disable = vim.NIL, which does not evaluate to false in lua.

wookayin avatar Apr 14 '22 00:04 wookayin

I think you should simply remove c = cmp.config.disable.

But it's like a bug. I'll check it.

hrsh7th avatar Apr 14 '22 02:04 hrsh7th