diff --git a/lua/lazyvim/plugins/extras/coding/codeium.lua b/lua/lazyvim/plugins/extras/coding/codeium.lua index 457535cd..a9f40624 100644 --- a/lua/lazyvim/plugins/extras/coding/codeium.lua +++ b/lua/lazyvim/plugins/extras/coding/codeium.lua @@ -27,43 +27,7 @@ return { optional = true, event = "VeryLazy", opts = function(_, opts) - local started = false - local function status() - if not package.loaded["cmp"] then - return - end - for _, s in ipairs(require("cmp").core.sources) do - if s.name == "codeium" then - if s.source:is_available() then - started = true - else - return started and "error" or nil - end - if s.status == s.SourceStatus.FETCHING then - return "pending" - end - return "ok" - end - end - end - - local Util = require("lazyvim.util") - local colors = { - ok = Util.ui.fg("Special"), - error = Util.ui.fg("DiagnosticError"), - pending = Util.ui.fg("DiagnosticWarn"), - } - table.insert(opts.sections.lualine_x, 2, { - function() - return require("lazyvim.config").icons.kinds.Codeium - end, - cond = function() - return status() ~= nil - end, - color = function() - return colors[status()] or colors.ok - end, - }) + table.insert(opts.sections.lualine_x, 2, require("lazyvim.util").lualine.cmp_source("codeium")) end, }, } diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index ddfa55f8..4a98aee4 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -13,6 +13,7 @@ local LazyUtil = require("lazy.core.util") ---@field inject lazyvim.util.inject ---@field news lazyvim.util.news ---@field json lazyvim.util.json +---@field lualine lazyvim.util.lualine local M = {} ---@type table diff --git a/lua/lazyvim/util/lualine.lua b/lua/lazyvim/util/lualine.lua new file mode 100644 index 00000000..8efcf714 --- /dev/null +++ b/lua/lazyvim/util/lualine.lua @@ -0,0 +1,46 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.lualine +local M = {} + +function M.cmp_source(name, icon) + local started = false + local function status() + if not package.loaded["cmp"] then + return + end + for _, s in ipairs(require("cmp").core.sources) do + if s.name == name then + if s.source:is_available() then + started = true + else + return started and "error" or nil + end + if s.status == s.SourceStatus.FETCHING then + return "pending" + end + return "ok" + end + end + end + + local colors = { + ok = Util.ui.fg("Special"), + error = Util.ui.fg("DiagnosticError"), + pending = Util.ui.fg("DiagnosticWarn"), + } + + return { + function() + return icon or require("lazyvim.config").icons.kinds[name:sub(1, 1):upper() .. name:sub(2)] + end, + cond = function() + return status() ~= nil + end, + color = function() + return colors[status()] or colors.ok + end, + } +end + +return M