fix(cmp): remove vim.defer_fn

remove nvim-compe,completion-nvim
This commit is contained in:
zztrieuzz 2021-10-17 08:34:37 +07:00
parent 2cab63437f
commit 4e8043e2ee
2 changed files with 24 additions and 73 deletions

View File

@ -44,23 +44,6 @@ Before Input After
}
------------------------------------
```
<details>
<summary><b>nvim-compe</b></summary>
``` lua
require("nvim-autopairs.completion.compe").setup({
map_cr = true, -- map <CR> on insert mode
map_complete = true, -- it will auto insert `(` (map_char) after select function or method item
auto_select = false, -- auto select first item
map_char = { -- modifies the function or method delimiter by filetypes
all = '(',
tex = '{'
}
})
```
Make sure to remove mapping insert mode `<CR>` binding if you have it.
</details>
<details>
<summary><b>nvim-cmp</b></summary>
@ -82,37 +65,6 @@ require("nvim-autopairs.completion.cmp").setup({
Make sure to remove mapping insert mode `<CR>` binding if you have it.
</details>
<details>
<summary><b>completion nvim</b></summary>
``` lua
local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
-- skip it, if you use another global object
_G.MUtils= {}
vim.g.completion_confirm_key = ""
MUtils.completion_confirm=function()
if vim.fn.pumvisible() ~= 0 then
if vim.fn.complete_info()["selected"] ~= -1 then
require'completion'.confirmCompletion()
return npairs.esc("<c-y>")
else
vim.api.nvim_select_popupmenu_item(0 , false , false ,{})
require'completion'.confirmCompletion()
return npairs.esc("<c-n><c-y>")
end
else
return npairs.autopairs_cr()
end
end
remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
```
</details>
<details>
<summary><b>coq_nvim</b></summary>
``` lua
@ -178,10 +130,11 @@ remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap =
```
</details>
[another completion plugin](https://github.com/windwp/nvim-autopairs/wiki/Completion-plugin)
If you have a problem with indent after press ` <CR> `
Please check setting of treesitter indent or install plugin support indent on your filetype
### Rule
nvim-autopairs use rule with condition to check pair.

View File

@ -38,34 +38,32 @@ M.setup = function(opt)
local function_kind = cmp.lsp.CompletionItemKind.Function
cmp_setup.event = {
on_confirm_done = function(entry)
vim.defer_fn(function()
local line = utils.text_get_current_line(0)
local _, col = utils.get_cursor()
local prev_char, next_char = utils.text_cusor_line(line, col, 1, 1, false)
local item = entry:get_completion_item()
local line = utils.text_get_current_line(0)
local _, col = utils.get_cursor()
local prev_char, next_char = utils.text_cusor_line(line, col, 1, 1, false)
local item = entry:get_completion_item()
local char = map_char[vim.bo.filetype] or map_char['all'] or '('
if char == '' then
return
end
local char = map_char[vim.bo.filetype] or map_char['all'] or '('
if char == '' then
return
end
if prev_char ~= char and next_char ~= char then
if item.kind == method_kind or item.kind == function_kind then
-- check insert text have ( from snippet
if
(
item.textEdit
and item.textEdit.newText
and item.textEdit.newText:match('[%(%[]')
)
or (item.insertText and item.insertText:match('[%(%[]'))
then
return
end
vim.api.nvim_feedkeys(char, 'i', true)
if prev_char ~= char and next_char ~= char then
if item.kind == method_kind or item.kind == function_kind then
-- check insert text have ( from snippet
if
(
item.textEdit
and item.textEdit.newText
and item.textEdit.newText:match('[%(%[]')
)
or (item.insertText and item.insertText:match('[%(%[]'))
then
return
end
vim.api.nvim_feedkeys(char, 'i', true)
end
end, 1)
end
end,
}
end