fix(nvim): copilot_cmp tab completion
This commit is contained in:
parent
f3d8f6e5cd
commit
0cd4cf6d40
|
@ -1,10 +1,13 @@
|
|||
local cmp = require("cmp")
|
||||
-- local cmp_buffer = require("cmp_buffer")
|
||||
|
||||
-- https://github.com/zbirenbaum/copilot-cmp#tab-completion-configuration-highly-recommended
|
||||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
|
||||
return false
|
||||
end
|
||||
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
|
||||
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
|
||||
end
|
||||
|
||||
cmp.setup({
|
||||
|
@ -32,15 +35,13 @@ cmp.setup({
|
|||
behavior = cmp.ConfirmBehavior.Insert,
|
||||
select = true,
|
||||
}),
|
||||
["<Tab>"] = function(fallback)
|
||||
if not cmp.select_next_item() then
|
||||
if vim.bo.buftype ~= "prompt" and has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
["<Tab>"] = vim.schedule_wrap(function(fallback)
|
||||
if cmp.visible() and has_words_before() then
|
||||
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
end),
|
||||
["<S-Tab>"] = function(fallback)
|
||||
if not cmp.select_prev_item() then
|
||||
if vim.bo.buftype ~= "prompt" and has_words_before() then
|
||||
|
|
Loading…
Reference in New Issue