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

snippet getting confirm and not preselect when doing cmp.select_next_item

Open GZLiew opened this issue 1 year ago • 6 comments

FAQ

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

Announcement

Minimal reproducible full config

cmp.setup({
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },
  mapping = {
		['<C-n>'] = function(fallback)
        if cmp.visible() then
          cmp.select_next_item()
        else
          fallback()
        end
      end,
		['<C-p>'] = function(fallback)
        if cmp.visible() then
          cmp.select_prev_item()
        else
          fallback()
        end
      end,
    ['<C-y>'] = cmp.config.disable,
    ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's', 'v' }),
    ['<C-f>'] = cmp.mapping.confirm({ select = true }),
    ['<Tab>'] = cmp.mapping.confirm({ select = true }),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
  },
  sources = cmp.config.sources({
    { name = 'vsnip' },
    { name = 'nvim_lsp' },
    { name = 'buffer' },
  })
})

Description

https://github.com/hrsh7th/nvim-cmp/assets/43195293/b8d59787-1bc6-45c9-a8f2-c216ab56b1ee

Steps to reproduce

https://github.com/hrsh7th/nvim-cmp/assets/43195293/b8d59787-1bc6-45c9-a8f2-c216ab56b1ee

Expected behavior

should preselect the trycatch snippet and not select and hide cmp dialog

Actual behavior

selected the trycatch snippet and hides cmp dialog

Additional context

No response

GZLiew avatar May 21 '24 14:05 GZLiew

Facing the same issue when select some rust macros. Keystroke sequence: print<tab>

https://github.com/hrsh7th/nvim-cmp/assets/75246050/9b2a87fd-8acd-4701-b202-ed409d4a845b

KeqiZeng avatar Jun 02 '24 15:06 KeqiZeng

Facing the same issue when select some rust macros. Keystroke sequence: print<tab>

Screen.Recording.2024-06-02.at.17.11.34.mov

mapping = {
	["<Tab>"] = cmp.mapping(function(fallback)
		if cmp.visible() then
			cmp.select_next_item()
		elseif vim.snippet.active({ direction = 1 }) then
			vim.schedule(function()
				vim.snippet.jump(1)
			end)
		elseif has_words_before() then
			cmp.complete()
		else
			fallback()
		end
	end, { "i", "s" }),
}
local has_words_before = function()
	---@diagnostic disable-next-line: deprecated
	local line, col = unpack(vim.api.nvim_win_get_cursor(0))
	return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

KeqiZeng avatar Jun 02 '24 15:06 KeqiZeng

I have the same issue particularly with intelephense using lspconfig. It seems that some completion get confirmed early like the function mysqli_init or max, don't know what might be the problem since my config works fine before I upgraded to 0.10.0 from 0.9.5

sglkc avatar Jun 05 '24 16:06 sglkc

I had this exact issue.

It turned out andymass/vim-matchup was trying to match selection text emitted for LSP snippets (snippets from other sources such as LuaSnip do not have this issue), which makes the completion menu close then open again with the previously selected text now as the current prefix.

I just removed the plugin, and everything worked correctly.

aymanalqadhi avatar Jun 24 '24 22:06 aymanalqadhi

I had this exact issue.

It turned out was trying to match selection text emitted for LSP snippets (snippets from other sources such as LuaSnip do not have this issue), which makes the completion menu close then open again with the previously selected text now as the current prefix.andymass/vim-matchup

I just removed the plugin, and everything worked correctly.

I just removed this plugin and everything is ok, but do you know any plugin that can replace andymass/vim-matchup ?

nhattVim avatar Jul 01 '24 10:07 nhattVim

It turned out andymass/vim-matchup was trying to ...

Temporarily disabling vim-matchup works well for me:

-- plugins/vim-matchup.lua
return {
  "andymass/vim-matchup",
  config = function(_, opts)
    local ok, cmp = pcall(require, "cmp")
    if ok then
      cmp.event:on("menu_opened", function() vim.b.matchup_matchparen_enabled = false end)
      cmp.event:on("menu_closed", function() vim.b.matchup_matchparen_enabled = true end)
    end
    require("match-up").setup(opts)
  end,
}

loichyan avatar Jul 20 '24 10:07 loichyan