neovim-confs/lua/plex/plugins/extras/coding/copilot.lua

109 lines
2.8 KiB
Lua
Raw Permalink Normal View History

2023-09-06 00:26:45 +02:00
-- This is part of LazyVim's code, with my modifications.
-- See: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/coding/copilot.lua
return {
-----------------------------------------------------------------------------
{
'zbirenbaum/copilot.lua',
2023-09-06 10:19:56 +02:00
enabled = false,
2023-09-06 00:26:45 +02:00
cmd = 'Copilot',
build = ':Copilot auth',
opts = {
suggestion = { enabled = false },
panel = { enabled = false },
filetypes = {
markdown = true,
help = true,
},
},
},
-----------------------------------------------------------------------------
{
'nvim-lualine/lualine.nvim',
optional = true,
event = 'VeryLazy',
opts = function(_, opts)
2023-09-06 10:19:56 +02:00
local get_color = require('plex.lib.color').get_color
2023-09-06 00:26:45 +02:00
local fg = function(...)
return { fg = get_color('fg', ...) }
end
local colors = {
[''] = fg({ 'Comment' }),
['Normal'] = fg({ 'Comment' }),
['Warning'] = fg({ 'DiagnosticError' }),
['InProgress'] = fg({ 'DiagnosticWarn' }),
}
-- Add copilot icon to lualine statusline
table.insert(opts.sections.lualine_x, {
function()
2023-09-06 10:19:56 +02:00
local icon = require('plex.config').icons.kinds.Copilot
2023-09-06 00:26:45 +02:00
local status = require('copilot.api').status.data
return icon .. (status.message or '')
end,
cond = function()
local clients
if vim.lsp.get_clients ~= nil then
clients = vim.lsp.get_clients({ name = 'copilot', bufnr = 0 })
else
---@diagnostic disable-next-line: deprecated
clients = vim.lsp.get_active_clients({
name = 'copilot',
bufnr = 0,
})
end
return #clients > 0
end,
color = function()
if not package.loaded["copilot"] then
return
end
local status = require('copilot.api').status.data
return colors[status.status] or colors['']
end,
})
end,
},
-----------------------------------------------------------------------------
{
'nvim-cmp',
dependencies = {
{
'zbirenbaum/copilot-cmp',
dependencies = 'zbirenbaum/copilot.lua',
opts = {},
config = function(_, opts)
local copilot_cmp = require('copilot_cmp')
copilot_cmp.setup(opts)
-- attach cmp source whenever copilot attaches
-- fixes lazy-loading issues with the copilot cmp source
---@param client lsp.Client
2023-09-06 10:19:56 +02:00
require('plex.lib.utils').on_attach(function(client)
2023-09-06 00:26:45 +02:00
if client.name == 'copilot' then
copilot_cmp._on_insert_enter({})
end
end)
end,
},
},
---@param opts cmp.ConfigSchema|{sources: table[]}
opts = function(_, opts)
-- Add copilot nvim-cmp source.
table.insert(opts.sources, 1, {
name = 'copilot',
group_index = 2,
priority = 60,
})
opts.sorting = opts.sorting or require('cmp.config.default')().sorting
table.insert(
opts.sorting.comparators,
1,
require('copilot_cmp.comparators').prioritize
)
end,
},
}