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

tab key will freeze nvim #226

Closed
krisfans opened this issue Sep 20, 2021 · 19 comments
Closed

tab key will freeze nvim #226

krisfans opened this issue Sep 20, 2021 · 19 comments
Labels
bug Something isn't working difficult high-priority

Comments

@krisfans
Copy link

see hrsh7th/vim-vsnip#214

@hrsh7th hrsh7th added bug Something isn't working difficult high-priority labels Sep 20, 2021
hrsh7th added a commit that referenced this issue Sep 20, 2021
@hrsh7th hrsh7th closed this as completed Sep 20, 2021
hrsh7th added a commit that referenced this issue Sep 21, 2021
@krisfans
Copy link
Author

I just update this plugin , a new problem appears . The same stpes , nvim report a error "E5108: Error executing lua ...pos/github.com/hrsh7th/nvim-cmp/lua/cmp/utils/keymap.lua:163: Vim:E121: Undefined variable: Tab"

@hrsh7th hrsh7th reopened this Sep 21, 2021
@hrsh7th
Copy link
Owner

hrsh7th commented Sep 21, 2021

@krisfans Thank you for your report. It's very insightful.

Sorry for annoying but Could you check with the following debug codes?

-- keymap.lua:L162
misc.set(_G, { 'cmp', 'utils', 'keymap', 'evacuate', 'expr' }, function(mode, lhs, rhs)
  return keymap.t(keymap.recursive(mode, lhs, vim.api.nvim_eval(rhs)))
end)

↓↓↓

misc.set(_G, { 'cmp', 'utils', 'keymap', 'evacuate', 'expr' }, function(mode, lhs, rhs)
  print(rhs)
  return keymap.t(keymap.recursive(mode, lhs, vim.api.nvim_eval(rhs)))
end)

hrsh7th added a commit that referenced this issue Sep 21, 2021
hrsh7th added a commit that referenced this issue Sep 21, 2021
@krisfans
Copy link
Author

vsnip#jumpable(1)? '(vsnip-jump-next)' : ''
E5108: Error executing lua ...pos/github.com/hrsh7th/nvim-cmp/lua/cmp/utils/keymap.lua:167: Vim:E121: Undefined variable: Tab

hrsh7th added a commit that referenced this issue Sep 24, 2021
@rti
Copy link

rti commented Sep 26, 2021

Thank you so much for looking into this.

I think I run into a similar issue here:

from my init.lua

local cmp = require'cmp'

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

  mapping = {
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<C-j>'] = cmp.mapping.confirm({ select = true }),
    ['<TAB>'] = cmp.mapping.confirm({ select = true }),   -- removing this line fixes the issue
  },

  sources = {
    { name = 'nvim_lsp' },
    { name = 'vsnip' },
    { name = 'buffer' },
  }
})

In insert mode, press <TAB>, nvim freezes @ 100% CPU.
I am on cc21a61.
I do not get any error messages though.
Adding the print line mentioned above does not lead to any output here.

@hrsh7th
Copy link
Owner

hrsh7th commented Sep 28, 2021

@rti Thank you for pointing me it. Unfortunately, I can't reproduce the issue.
Can you still reproduce this issue with latest nvim-cmp?

@rti
Copy link

rti commented Sep 28, 2021

Sorry. Apparently I was hiding the most interesting part of my init.lua from you.

Yes, I am on the latest revision (cc21a61). Nvim 0.5.1.

The issue seems to be triggered by me configuring vsnip to react on <TAB> as well. Not sure whether my desired setting is possible at all, but from a user perspective, it would be very convenient :)

Minimal init.lua to reproduce the issue. It will install vim-plug on the first run in data path.
Disabling either cmp's or vsnip's <TAB> mapping prevents the freeze.

local cmd = vim.cmd
local call = vim.call
local fn = vim.fn

local scopes = {o = vim.o, b = vim.bo, w = vim.wo}

local function opt(scope, key, value)
  scopes[scope][key] = value
  if scope ~= 'o' then scopes['o'][key] = value end
end

opt('o', 'completeopt', 'menu,menuone,noselect')

local install_path = fn.stdpath('data') .. '/site/autoload/'
local install_file = install_path .. 'plug.vim'

if fn.empty(fn.glob(install_file)) > 0 then
  cmd[[echom 'Installing vim-plug']]
  fn.system({'mkdir', '-p', install_path})
  fn.system({
    'curl',
    '-fLo',
    install_file,
    'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  })
end

local Plug = fn['plug#']

call('plug#begin', '~/.config/nvim/plugged')

Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'

call('plug#end')

local cmp = require'cmp'

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

  mapping = {
    ['<TAB>'] = cmp.mapping.confirm({ select = true }),
  },

  sources = {
    { name = 'vsnip' },
  }
})

cmd[[imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>']]

Load with nvim -u, enter insert mode, press <TAB>, nvim will freeze. At least on my machine :)

@hrsh7th
Copy link
Owner

hrsh7th commented Sep 29, 2021

It's reproduced. Thank you. I will tackle it.

hrsh7th added a commit that referenced this issue Sep 29, 2021
hrsh7th added a commit that referenced this issue Sep 29, 2021
@rti
Copy link

rti commented Sep 29, 2021

Awesome. Indeed. It is fixed. My <TAB> key can now trigger completion AND jump the snipped.

Thank you so much ❤️

hrsh7th added a commit that referenced this issue Sep 30, 2021
E-ricus pushed a commit to E-ricus/nvim-cmp that referenced this issue Oct 7, 2021
hrsh7th added a commit that referenced this issue Oct 7, 2021
hrsh7th added a commit that referenced this issue Oct 8, 2021
* WIP

* WIP

* Fix #226

* Insert text

* Emulate vim native

* テキトウ

* Tekito

* Move scrollbar impl

* aaa

* Ignore unexpected event

* fix

* fix scroll

* Refactor (conflict...)

* Fix bug

* Positive integer

* Refactor a bit

* Fix for pumheight=0

* fx

* Improve matching highlight

* Improve colorscheme handling

* fmt

* Add cmp.visible

* Fix pum pos

* ABBR_MARGIN

* Fix cel calculation

* up

* refactor

* fix

* a

* a

* compat

* Remove current completion state

* Fix ghost text

* Add feature toggle

* highlight customization

* Update

* Add breaking change announcement

* Add README.md

* Remove unused function

* extmark ephemeral ghost text

* Support native comp

* Fix docs  pos

* a

* Remove if native menu visible

* theme async

* Improvement idea: option to disables insert on select item (#240)

* use ghost text instead of insertion on prev/next item

* add disables_insert_on_selection option

* move disable_insert_on_select option as argumet on

* update README

* use an enum behavior to disable insert on select

* Adopt contribution

* Preselect

* Improve

* Change configuration option

* a

* Improve

* Improve

* Implement proper <C-e> behavior to native/custom

* Support <C-c> maybe

* Improve docs view

* Improve

* Avoid syntax leak

* TODO: refactor

* Fix

* Revert win pos

* fmt

* ghost text remaining

* Don't use italic by default

* bottom

* dedup by label

* Ignore events

* up

* Hacky native view partial support

* up

* perf

* improve

* more cache

* fmt

* Fix format option

* fmt

* recheck

* Fix

* Improve

* Improve

* compat

* implement redraw

* improve

* up

* fmt/lint

* immediate ghost text

* source timeout

* up

* Support multibyte

* disable highlight

* up

* improve

* fmt

* fmt

* fix

* fix

* up

* up

* Use screenpos

* Add undojoin check

* Fix height

* matcher bug

* Fix dot-repeat

* Remove undojoin

* macro

* Support dot-repeat

* MacroSafe

* Default item count is 200

* fmt

Co-authored-by: Eric Puentes <[email protected]>
@gmorer
Copy link

gmorer commented Oct 16, 2021

Hello I ran into that issue today, when i press the TAB key without the the cmp popup, my neovim do freeze, filling the log file with Executing: call v:lua.cmp.utils.keymap.listen.run(23592651)
I can reproduce with the following conf:

mapping = {
   ['<Tab>'] = cmp.mapping.select_next_item()
}

my nvim version is v0.5.1
and nvim cmp local HEAD is at 4ecf2a2 (Sun Oct 17)

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 17, 2021

I'll try it with minimal config.

@Diomendius
Copy link

I think I'm encountering the same issue. I use <c-n> / <c-p>, but otherwise the symptoms are the same. <c-c> will un-freeze Nvim, by the way.

In my case, it is a regression. Bisecting shows that 5fe7dc1 is the first bad commit.

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 22, 2021

Please minimal reproduction configuration...

@hrsh7th hrsh7th reopened this Oct 22, 2021
@Diomendius
Copy link

Use this init.vim:

lua << EOF
local cmp = require('cmp')
cmp.setup {
	mapping = {
		['<c-n>'] = cmp.mapping.select_next_item(),
	},
}
EOF

This assumes cmp is already loaded, so if it isn't already available in runtimepath or packpath, symlink/copy it there first.

To test it on my end, I made a temporary directory containing the following:

  • nvim/init.vim (contents from above)
  • pack/packs/start/nvim-cmp (the root of this repo, copied/symlinked/wget'd/whatever)

Then, I ran XDG_CONFIG_HOME=$NVIM_TEST XDG_DATA_HOME=$NVIM_TEST nvim, where $NVIM_TEST is the temporary directory I described above.

Nvim should freeze when typing CTRL-N in Insert mode. CTRL-C should unfreeze Nvim.

This is probably reproducible with any config that binds select_next_item() or select_prev_item(), but I can definitely reproduce it with this config.

@ghost
Copy link

ghost commented Oct 25, 2021

Hello I ran into that issue today, when i press the TAB key without the the cmp popup, my neovim do freeze, filling the log file with Executing: call v:lua.cmp.utils.keymap.listen.run(23592651) I can reproduce with the following conf:

mapping = {
   ['<Tab>'] = cmp.mapping.select_next_item()
}

my nvim version is v0.5.1 and nvim cmp local HEAD is at 4ecf2a2 (Sun Oct 17)

Same Isssue persists for neovim for latest commit.

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 25, 2021

I can't reproduce the issue with the following configuration.

I can't fix if the user doesn't provide minimal reproducible configuration.

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'
call plug#end()

lua <<EOF
local cmp = require("cmp")
cmp.setup({
  mapping = {
    ['<c-n>'] = cmp.mapping.select_next_item(),
    ['<C-p>'] = cmp.mapping.select_prev_item(),
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.abort(),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<C-y>'] = cmp.mapping.confirm({ select = true }),
  },
  sources = {
    { name = 'buffer' }
  }
})
EOF

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 25, 2021

Sorry... reproduced.

hrsh7th added a commit that referenced this issue Oct 25, 2021
@gmorer
Copy link

gmorer commented Oct 25, 2021

The issue is stil present (i did update to latest) with:

['<Tab>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),

and with:

['<Tab>'] = function(fallback)
    if cmp.visible() then
         cmp.mapping.select_next_item()
      else
         fallback()
      end
 end,
['<S-Tab>'] = function(fallback)
      if cmp.visible() then
         cmp.mapping.select_prev_item()
      else
         fallback()
      end
end,

Same return in the log, it fill the log in an endless loop with Executing: call v:lua.cmp.utils.keymap.listen.run(12475286)

I recorded the log just before it strat to write that line endlessly: https://pastebin.com/dfUP8HEd

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 26, 2021

What is the HighlightMatchingPairs?
I will try it with your config.

@gmorer
Copy link

gmorer commented Oct 26, 2021

From neovim sourcecode The function that is invoked (very often) to define a ":match" highlighting for any matching paren., look like it's call on thoses events: autocmd! CursorMoved,CursorMovedI,WinEnter * call s:Highlight_Matching_Pair() and autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair()
From neovim report in runtime/plugin/matchparen.vim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working difficult high-priority
Projects
None yet
Development

No branches or pull requests

5 participants