mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 17:58:51 +02:00
refactor: move cmp status lualine component to util
This commit is contained in:
parent
8f42733ce5
commit
1a4342abae
3 changed files with 48 additions and 37 deletions
|
@ -27,43 +27,7 @@ return {
|
||||||
optional = true,
|
optional = true,
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
local started = false
|
table.insert(opts.sections.lualine_x, 2, require("lazyvim.util").lualine.cmp_source("codeium"))
|
||||||
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,
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ local LazyUtil = require("lazy.core.util")
|
||||||
---@field inject lazyvim.util.inject
|
---@field inject lazyvim.util.inject
|
||||||
---@field news lazyvim.util.news
|
---@field news lazyvim.util.news
|
||||||
---@field json lazyvim.util.json
|
---@field json lazyvim.util.json
|
||||||
|
---@field lualine lazyvim.util.lualine
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@type table<string, string|string[]>
|
---@type table<string, string|string[]>
|
||||||
|
|
46
lua/lazyvim/util/lualine.lua
Normal file
46
lua/lazyvim/util/lualine.lua
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue