From 9913e1665d783d9c4407633bc33475d403aff433 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 25 Sep 2025 11:11:40 +0200 Subject: [PATCH] feat(copilot-native): better lualine status --- .../plugins/extras/ai/copilot-native.lua | 26 ++++++++++++-- lua/lazyvim/util/lualine.lua | 36 ------------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/lua/lazyvim/plugins/extras/ai/copilot-native.lua b/lua/lazyvim/plugins/extras/ai/copilot-native.lua index 8bcb9bfe..85cd0d30 100644 --- a/lua/lazyvim/plugins/extras/ai/copilot-native.lua +++ b/lua/lazyvim/plugins/extras/ai/copilot-native.lua @@ -16,6 +16,7 @@ if LazyVim.has_extra("ai.copilot-native") then end vim.g.ai_cmp = false +local status = {} ---@type table return { desc = "Native Copilot LSP integration. Requires Neovim >= 0.12", @@ -24,10 +25,22 @@ return { "neovim/nvim-lspconfig", opts = { servers = { - copilot = {}, + copilot = { + handlers = { + didChangeStatus = function(err, res, ctx) + if err then + return + end + status[ctx.client_id] = res.kind ~= "Normal" and "error" or res.busy and "pending" or "ok" + if res.status == "Error" then + LazyVim.error("Please use `:LspCopilotSignIn` to sign in to Copilot") + end + end, + }, + }, }, setup = { - copilot = function(_, opts) + copilot = function() vim.lsp.inline_completion.enable() LazyVim.cmp.actions.ai_accept = function() return vim.lsp.inline_completion.get() @@ -43,7 +56,14 @@ return { optional = true, event = "VeryLazy", opts = function(_, opts) - table.insert(opts.sections.lualine_x, 2, LazyVim.lualine.lsp("copilot")) + table.insert( + opts.sections.lualine_x, + 2, + LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function() + local clients = vim.lsp.get_clients({ name = "copilot", bufnr = 0 }) + return #clients > 0 and status[clients[1].id] or nil + end) + ) end, }, } diff --git a/lua/lazyvim/util/lualine.lua b/lua/lazyvim/util/lualine.lua index af4b55f7..a6aa24f3 100644 --- a/lua/lazyvim/util/lualine.lua +++ b/lua/lazyvim/util/lualine.lua @@ -22,42 +22,6 @@ function M.status(icon, status) } end ---- Status indicator for LSP server activity ----@param server string ----@param opts? { methods?: string[], icon?: string } -function M.lsp(server, opts) - opts = opts or {} - local methods = opts.methods or { "textDocument/completion", "textDocument/inlineCompletion" } - local pending = {} ---@type table - vim.api.nvim_create_autocmd("LspRequest", { - group = vim.api.nvim_create_augroup("lazyvim.lualine.lsp." .. server, { clear = true }), - callback = function(args) - ---@class LspRequestData - ---@field client_id number - ---@field request { bufnr: number, method: string, type: "pending" | "cancel" | "complete" | string } - ---@field request_id number - local data = args.data - local client = vim.lsp.get_client_by_id(data.client_id) - if client and client.name == server and vim.tbl_contains(methods, data.request.method) then - pending[data.request_id] = data.request.type == "pending" or nil - end - end, - }) - return { - function() - return opts.icon - or LazyVim.config.icons.kinds[server:sub(1, 1):upper() .. server:sub(2)] - or LazyVim.config.icons.diagnostics.Hint - end, - cond = function() - return #vim.lsp.get_clients({ name = server, bufnr = 0 }) > 0 - end, - color = function() - return { fg = Snacks.util.color(vim.tbl_isempty(pending) and "Special" or "DiagnosticWarn") } - end, - } -end - ---@param name string ---@param icon? string function M.cmp_source(name, icon)