windwp / nvim-autopairs

autopairs for neovim written in lua
MIT License
3.14k stars 119 forks source link

cssmodules_ls and enter with nvim-autopairs bug #218

Closed ghost closed 2 years ago

ghost commented 2 years ago

Description

This bug due to cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) when trying to complete text with enter for cssmodules_ls. Neovim 0.6.1. Screenshot_2022-03-07_11-32-17

Mapping bug

No response

Steps to reproduce

  1. I use nvim-lsp-installer (LspInstall cssmodules_ls), but you can install by hand cssmodules_ls.
  2. Try to complete text with enter when cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) is set.
  3. Default configuration enter from nvim-cmp ['<CR>'] = cmp.mapping.confirm({ select = true })
  4. If i remove cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) from settings - no error anymore. But this setting is convenient, i don't want to remove it.

Minimal config

require("nvim-autopairs").setup()
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')

cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({  map_char = { tex = '' } }))
ghost commented 2 years ago

Probably bug in cssmodules.

HendrikThePendric commented 2 years ago

To keep this functionality enabled everywhere, apart from when using cssmodules_ls I've changed this:

cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({  map_char = { tex = '' } }))

To this:

cmp.event:on('confirm_done', function(arg)
    local client_name = nil

    if type(arg) == "table" then
        client_name = arg.entry.source.source.client.name
    end

    if (client_name ~= "cssmodules_ls") then
        local handler = cmp_autopairs.on_confirm_done({
            map_char = {
                tex = ''
            }
        })
        handler(arg)
    end
end)