Skip to content

Commit

Permalink
feat(plugins): copilot wip
Browse files Browse the repository at this point in the history
  • Loading branch information
n3wborn committed Feb 1, 2025
1 parent 23f20b8 commit 4406c99
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ return {
'hrsh7th/cmp-nvim-lua',
'lukas-reineke/cmp-rg',
'windwp/nvim-autopairs',
'zbirenbaum/copilot-cmp',
},
opts = function()
local cmp = require('cmp')
local compare = require('cmp.config.compare')
local cmp_buffer = require('cmp_buffer')
local icons = require('custom.icons').kinds
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

return {
enabled = function()
Expand All @@ -32,6 +40,7 @@ return {
nvim_lua = '[API]',
path = '[Path]',
rg = '[RG]',
Copilot = '[ ]',
})[entry.source.name]
return item
end,
Expand Down Expand Up @@ -80,6 +89,7 @@ return {
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp', priority = 1000 },
{ name = 'copilot', priority = 100 },
{ name = 'nvim_lsp_signature_help' },
{ name = 'nvim_lua' },
}, {
Expand All @@ -95,6 +105,7 @@ return {
}),
sorting = {
comparators = {
require('copilot_cmp.comparators').prioritize,
-- Sort by distance of the word from the cursor
-- https://github.com/hrsh7th/cmp-buffer#locality-bonus-comparator-distance-based-sorting
function(...)
Expand Down Expand Up @@ -122,6 +133,15 @@ return {

autopairs.setup({ fast_wrap = {} })
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())

-- copilot
cmp.event:on('menu_opened', function()
vim.b.copilot_suggestion_hidden = true
end)
cmp.event:on('menu_closed', function()
vim.b.copilot_suggestion_hidden = false
end)

cmp.setup.filetype({ 'sql' }, {
sources = {
{ name = 'vim-dadbod-completion' },
Expand Down
32 changes: 32 additions & 0 deletions lua/plugins/copilot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
return {
'zbirenbaum/copilot.lua',
cmd = 'Copilot',
build = ':Copilot auth',
event = 'BufReadPost',
opts = {
suggestion = {
enabled = not vim.g.ai_cmp,
auto_trigger = true,
hide_during_completion = vim.g.ai_cmp,
keymap = {
accept = false, -- handled by nvim-cmp / blink.cmp
next = '<C-n>',
prev = '<C-N>',
},
},
panel = { enabled = false },
filetypes = {
javascript = true,
typescript = true,
lua = true,
php = true,
sh = function()
if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
return false
end
return true
end,
['*'] = false, -- disable for all other filetypes
},
},
}

0 comments on commit 4406c99

Please sign in to comment.