windwp / nvim-autopairs

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

The nvim-cmp confirm_done completion function in the js file will be invalid #319

Closed fengwk closed 1 year ago

fengwk commented 1 year ago

Description

Recently, I used nvim-cmp on in js confirm The completion of done brackets is invalid. I have no energy to read the submission point, but I guess from the description that it may be caused by commit 4d9000e87f148eaf1ce0a94b674f0f7c97afbc6c. After I rolled back to the previous comet f00eb3b766c370cb34fdabc29c760338ba9e4c6c, the completion function has come into effect again, so I am ready to continue using the old commit until this problem is fixed.

Mapping bug

No response

Steps to reproduce

Configure according to "You need to add mapping CR on nvim-cmp setup. Check readme.md on nvim-cmp repo.". The completion function in the js file will be invalid.

Minimal config

-- https://github.com/windwp/nvim-autopairs

local ok, nvim_autopairs = pcall(require, "nvim-autopairs")
if not ok then
  return
end

nvim_autopairs.setup({
  check_ts = true,
  ts_config = {
    lua = { "string", "source" },
    javascript = { "string", "template_string" },
    java = false,
  },
  disable_filetype = { "TelescopePrompt", "spectre_panel", "dap-repl" },
  disable_in_macro = false,
  disable_in_visualblock = true,
  fast_wrap = {
    -- map = "<M-e>", -- alt+e,快速补充右侧符号
    map = "<C-l>", -- ctrl+l,快速补充右侧符号
    chars = { "{", "[", "(", '"', "'", "`" },
    pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
    offset = 0, -- Offset from pattern match
    end_key = "$",
    keys = "qwertyuiopzxcvbnmasdfghjkl",
    check_comma = true,
    highlight = "PmenuSel",
    highlight_grey = "LineNr",
  },
})

-- 对于一些无法自动补充括号的LSP,下面的方法将增加这一功能
local ok, cmp = pcall(require, "cmp")
if ok and cmp ~= nil then
  -- If you want insert `(` after select function or method item
  local cmp_autopairs = require('nvim-autopairs.completion.cmp')
  local handlers = require('nvim-autopairs.completion.handlers')
  cmp.event:on(
    "confirm_done",
    cmp_autopairs.on_confirm_done({
      filetypes = {
        -- "*" is a alias to all filetypes
        ["*"] = {
          ["("] = {
            kind = {
              -- https://docs.rs/lsp/0.2.0/lsp/types/enum.CompletionItemKind.html
              cmp.lsp.CompletionItemKind.Function,
              cmp.lsp.CompletionItemKind.Method,
              cmp.lsp.CompletionItemKind.Constructor,
            },
            handler = handlers["*"],
          },
        },
        -- 禁用指定类型的LSP
        tex = false,
        sh = false,
        bash = false,
      }
    })
  )
end
jackfranklin commented 1 year ago

I just came to report the same issue, adding brackets upon cmp completion does seem to have unfortunately broken. Now when completing methods, no brackets are inserted. I have the code from the README in my dotfiles and this was working until recently.

I can also confirm that pinning to f00eb3b766c370cb34fdabc29c760338ba9e4c6c fixes the issue; so I think it was introduced in the subsequent commit.

anthony-S93 commented 1 year ago

I can confirm this as well.

schardev commented 1 year ago

yep. doesn't seem to work for me either

bushblade commented 1 year ago

Just arrived to say the same and can confirm reverting to f00eb3b also fixes it for me.

schardev commented 1 year ago

@aspeddro is it working for you as expected?

aspeddro commented 1 year ago

Can anyone show me an example for JS files?

You could test #327?

schardev commented 1 year ago

~Can anyone show me an example for JS files?~

You could test #327?

Yep. Seems to be working now. Thanks.