fix(nvim): copilot_cmp tab completion

This commit is contained in:
Rob Watson 2023-10-04 05:12:14 +02:00
parent f3d8f6e5cd
commit 0cd4cf6d40
1 changed files with 11 additions and 10 deletions

View File

@ -1,10 +1,13 @@
local cmp = require("cmp") local cmp = require("cmp")
-- local cmp_buffer = require("cmp_buffer") -- local cmp_buffer = require("cmp_buffer")
-- https://github.com/zbirenbaum/copilot-cmp#tab-completion-configuration-highly-recommended
local has_words_before = function() 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)) 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 end
cmp.setup({ cmp.setup({
@ -32,15 +35,13 @@ cmp.setup({
behavior = cmp.ConfirmBehavior.Insert, behavior = cmp.ConfirmBehavior.Insert,
select = true, select = true,
}), }),
["<Tab>"] = function(fallback) ["<Tab>"] = vim.schedule_wrap(function(fallback)
if not cmp.select_next_item() then if cmp.visible() and has_words_before() then
if vim.bo.buftype ~= "prompt" and has_words_before() then cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
cmp.complete()
else else
fallback() fallback()
end end
end end),
end,
["<S-Tab>"] = function(fallback) ["<S-Tab>"] = function(fallback)
if not cmp.select_prev_item() then if not cmp.select_prev_item() then
if vim.bo.buftype ~= "prompt" and has_words_before() then if vim.bo.buftype ~= "prompt" and has_words_before() then