hrsh7th / nvim-cmp

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

Mapped confirm character breaks completion #1784

Open mireq opened 6 months ago

mireq commented 6 months ago

FAQ

Announcement

Minimal reproducible full config

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

-- Add mapping for (
vim.keymap.set('i', '(<Tab>', '()')

require("lazy").setup({
    {
        "hrsh7th/nvim-cmp",
        event = "InsertEnter",
        dependencies = {
            "hrsh7th/cmp-nvim-lsp",
            "hrsh7th/cmp-buffer",
        },
        config = function()
            local cmp = require'cmp'
            local insert_mapping = cmp.mapping.preset.insert({})
            cmp.setup({
                mapping = insert_mapping,
                confirmation = {
                    -- Confirm using '('
                    get_commit_characters = function(commit_characters) return {'('} end,
                },
                sources = cmp.config.sources( { { name = 'buffer' } } )
            })
        end,
    },
})

Description

I have mapping for left bracket to insert right bracket. If i press '(' in completion and then i hit ESC to cancel right bracket insertion, cmp inserts characters on wrong places. output

Steps to reproduce

Expected behavior

It should leave current selected completion.

Actual behavior

It inserts wrong text.

Additional context

Sometimes it leaves part of completion + '<Plug>(cmp.u.k.fallback_expr:)' in command line.