Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config merging does not convert vim.NIL to nil #897

Closed
2 tasks done
wookayin opened this issue Apr 13, 2022 · 5 comments
Closed
2 tasks done

config merging does not convert vim.NIL to nil #897

wookayin opened this issue Apr 13, 2022 · 5 comments
Labels
bug Something isn't working valid

Comments

@wookayin
Copy link
Contributor

wookayin commented Apr 13, 2022

FAQ

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

Issues

  • 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 wookayin added the bug Something isn't working label Apr 13, 2022
@wookayin wookayin changed the title Broken <Tab> key in the command-line mapping mode Broken <Tab> key mappings in the command mode Apr 13, 2022
@Shougo
Copy link

Shougo commented Apr 14, 2022

Well...

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

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

@wookayin
Copy link
Contributor Author

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.

@Shougo
Copy link

Shougo commented Apr 14, 2022

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

@wookayin
Copy link
Contributor Author

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

wookayin added a commit to wookayin/dotfiles that referenced this issue Apr 14, 2022
Avoid a bug in hrsh7th/nvim-cmp#897; these lines are no longer needed
in newer versions of nvim-cmp due to removal of default key mappings.
@hrsh7th
Copy link
Owner

hrsh7th commented Apr 14, 2022

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

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

@hrsh7th hrsh7th changed the title Broken <Tab> key mappings in the command mode config merging does not convert vim.NIL to nil Apr 14, 2022
@hrsh7th hrsh7th added the valid label May 1, 2022
@hrsh7th hrsh7th closed this as completed in 5a80cd4 May 8, 2023
williamboman added a commit to williamboman/nvim-cmp that referenced this issue May 26, 2023
…indow

* upstream/main: (31 commits)
  fix entry highlight in complete-menu (hrsh7th#1593)
  Remove max_item_count from source configuration
  feat: cmp async (hrsh7th#1583)
  ghost text inline (hrsh7th#1588)
  Fix demo video in README.md (hrsh7th#1585)
  docs: fix adjecent typo (hrsh7th#1577)
  docs: fix typos, add confirm.behavior example cfg (hrsh7th#1576)
  perf(source): only filter up to 200 entries and dont use the cache (hrsh7th#1574)
  fix(ghost_text): safely apply virtual_text highlight (hrsh7th#1563)
  Improve misc.merge
  Fix hrsh7th#897
  Added a modified=false to documentation buffer, so it can be removed without E89 errors (hrsh7th#1557)
  Fix hrsh7th#1556
  fix 1533, add regression test (hrsh7th#1558)
  Add `buftype=nofile` for entries_win and docs_win - reddit user mention this...
  Fix hrsh7th#1550
  Format with stylua
  Add test for hrsh7th#1552 Close hrsh7th#1552
  Revert hrsh7th#1534 temporaly
  fix typo (hrsh7th#1551)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working valid
Projects
None yet
Development

No branches or pull requests

3 participants