diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua index fb9f0c8..55f748b 100644 --- a/nvim/lua/config/lazy.lua +++ b/nvim/lua/config/lazy.lua @@ -12,7 +12,7 @@ require("lazy").setup({ -- add LazyVim and import its plugins { "LazyVim/LazyVim", import = "lazyvim.plugins" }, -- { import = "lazyvim.plugins.extras.coding.codeium" }, - { import = "lazyvim.plugins.extras.coding.copilot" }, + { import = "plugins.coding.copilot" }, { import = "lazyvim.plugins.extras.lang.docker" }, { import = "lazyvim.plugins.extras.lang.go" }, { import = "lazyvim.plugins.extras.lang.java" }, diff --git a/nvim/lua/plugins/coding/copilot.lua b/nvim/lua/plugins/coding/copilot.lua new file mode 100644 index 0000000..6dae184 --- /dev/null +++ b/nvim/lua/plugins/coding/copilot.lua @@ -0,0 +1,87 @@ +return { + + -- copilot + { + "zbirenbaum/copilot.lua", + cmd = "Copilot", + build = ":Copilot auth", + opts = { + suggestion = { enabled = true }, + panel = { enabled = true }, + filetypes = { + yaml = true, + markdown = true, + help = true, + }, + }, + }, + { + "nvim-lualine/lualine.nvim", + optional = true, + event = "VeryLazy", + opts = function(_, opts) + local Util = require("lazyvim.util") + local colors = { + [""] = Util.ui.fg("Special"), + ["Normal"] = Util.ui.fg("Special"), + ["Warning"] = Util.ui.fg("DiagnosticError"), + ["InProgress"] = Util.ui.fg("DiagnosticWarn"), + } + table.insert(opts.sections.lualine_x, 2, { + function() + local icon = require("lazyvim.config").icons.kinds.Copilot + local status = require("copilot.api").status.data + return icon .. (status.message or "") + end, + cond = function() + if not package.loaded["copilot"] then + return + end + local ok, clients = pcall(require("lazyvim.util").lsp.get_clients, { name = "copilot", bufnr = 0 }) + if not ok then + return false + end + return ok and #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, + }, + + -- copilot cmp source + { + "nvim-cmp", + dependencies = { + { + "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 + require("lazyvim.util").lsp.on_attach(function(client) + if client.name == "copilot" then + copilot_cmp._on_insert_enter({}) + end + end) + end, + }, + }, + ---@param opts cmp.ConfigSchema + opts = function(_, opts) + table.insert(opts.sources, 1, { + name = "copilot", + group_index = 1, + priority = 100, + }) + end, + }, +}