diff --git a/init.lua b/init.lua index 39e4b527..241833a9 100644 --- a/init.lua +++ b/init.lua @@ -697,6 +697,31 @@ require('lazy').setup({ -- into multiple repos for maintenance purposes. 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-path', + + -- copilot cmp source, aki + { + 'zbirenbaum/copilot-cmp', + dependencies = '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 + local on_attach = function(client, _) + if client.name == 'copilot' then + copilot_cmp._on_insert_enter {} + end + end + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local buffer = args.buf ---@type number + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) + end, + }, }, config = function() -- See `:help cmp` @@ -768,6 +793,7 @@ require('lazy').setup({ { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, + { name = 'copilot', group_index = 1, priority = 100 }, }, } end, @@ -885,7 +911,7 @@ require('lazy').setup({ -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lua/custom/plugins/copilot-cmp.lua b/lua/custom/plugins/copilot-cmp.lua new file mode 100644 index 00000000..4003237d --- /dev/null +++ b/lua/custom/plugins/copilot-cmp.lua @@ -0,0 +1,23 @@ +return { + 'zbirenbaum/copilot-cmp', + dependencies = '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 + local on_attach = function(client, _) + if client.name == 'copilot' then + copilot_cmp._on_insert_enter {} + end + end + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local buffer = args.buf ---@type number + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) + end, +} diff --git a/lua/custom/plugins/copilot.lua b/lua/custom/plugins/copilot.lua new file mode 100644 index 00000000..0869a0a1 --- /dev/null +++ b/lua/custom/plugins/copilot.lua @@ -0,0 +1,13 @@ +return { + 'zbirenbaum/copilot.lua', + cmd = 'Copilot', + build = ':Copilot auth', + opts = { + suggestion = { enabled = false }, + panel = { enabled = false }, + filetypes = { + markdown = true, + help = true, + }, + }, +}