Updated copilot implementation

This commit is contained in:
Christoffer Martinsson 2024-04-09 00:36:27 +02:00
parent 5dea2d52f4
commit c4f26928cb

View File

@ -136,21 +136,19 @@ require('lazy').setup({
},
},
{
'zbirenbaum/copilot.lua',
config = function()
require('copilot').setup {
suggestion = { enabled = false },
panel = { enabled = false },
filetypes = { markdown = true },
}
end,
},
{
'zbirenbaum/copilot-cmp',
event = { 'BufRead', 'BufNewFile' },
dependencies = {
{
'zbirenbaum/copilot.lua',
config = function()
require('copilot').setup {
suggestion = { enabled = false },
panel = { enabled = false },
filetypes = { markdown = true },
}
end,
},
},
config = function() require('copilot_cmp').setup() end,
},
@ -680,7 +678,11 @@ local cmp_opts = {
border = "solid",
winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel',
}
local has_words_before = function()
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_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
end
cmp.setup {
preselect = cmp.PreselectMode.None,
view = {
@ -712,7 +714,7 @@ cmp.setup {
select = false,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
if cmp.visible() and has_words_before() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
@ -731,11 +733,11 @@ cmp.setup {
end, { 'i', 's' }),
},
sources = {
{ name = 'nvim_lsp', priority = 2000 },
{ name = 'luasnip', priority = 1000 },
{ name = 'copilot', priority = 750 },
{ name = 'buffer', priority = 500 },
{ name = 'path', priority = 250 },
{ name = 'copilot', priority = 2 },
{ name = 'nvim_lsp', priority = 2 },
{ name = 'buffer', priority = 2 },
{ name = 'path', priority = 2 },
{ name = 'luasnip', priority = 2 },
},
}