Fix lualine issue when copilot is disable

This commit is contained in:
Ernesto R. C. Pereda 2023-06-01 22:18:18 -04:00
parent 9c1a5620ed
commit d7d1e30a9e

View file

@ -15,6 +15,11 @@ return {
optional = true, optional = true,
event = "VeryLazy", event = "VeryLazy",
opts = function(_, opts) opts = function(_, opts)
local ok, copilot_api = pcall(require, "copilot.api")
if not ok then
return opts
end
local Util = require("lazyvim.util") local Util = require("lazyvim.util")
local colors = { local colors = {
[""] = Util.fg("Special"), [""] = Util.fg("Special"),
@ -25,7 +30,7 @@ return {
table.insert(opts.sections.lualine_x, 2, { table.insert(opts.sections.lualine_x, 2, {
function() function()
local icon = require("lazyvim.config").icons.kinds.Copilot local icon = require("lazyvim.config").icons.kinds.Copilot
local status = require("copilot.api").status.data local status = copilot_api.status.data
return icon .. (status.message or "") return icon .. (status.message or "")
end, end,
cond = function() cond = function()
@ -33,7 +38,7 @@ return {
return ok and #clients > 0 return ok and #clients > 0
end, end,
color = function() color = function()
local status = require("copilot.api").status.data local status = copilot_api.status.data
return colors[status.status] or colors[""] return colors[status.status] or colors[""]
end, end,
}) })