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', '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, config = function() require('copilot_cmp').setup() end,
}, },
@ -680,7 +678,11 @@ local cmp_opts = {
border = "solid", border = "solid",
winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel', 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 { cmp.setup {
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
view = { view = {
@ -712,7 +714,7 @@ cmp.setup {
select = false, select = false,
}, },
['<Tab>'] = cmp.mapping(function(fallback) ['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() and has_words_before() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
@ -731,11 +733,11 @@ cmp.setup {
end, { 'i', 's' }), end, { 'i', 's' }),
}, },
sources = { sources = {
{ name = 'nvim_lsp', priority = 2000 }, { name = 'copilot', priority = 2 },
{ name = 'luasnip', priority = 1000 }, { name = 'nvim_lsp', priority = 2 },
{ name = 'copilot', priority = 750 }, { name = 'buffer', priority = 2 },
{ name = 'buffer', priority = 500 }, { name = 'path', priority = 2 },
{ name = 'path', priority = 250 }, { name = 'luasnip', priority = 2 },
}, },
} }