mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
refactor: logging
This commit is contained in:
parent
765773a176
commit
6c7ef7e27a
10 changed files with 130 additions and 80 deletions
|
@ -30,8 +30,9 @@ M.colors = {
|
|||
Button = "CursorLine",
|
||||
ButtonActive = "Visual",
|
||||
TaskOutput = "MsgArea", -- task output
|
||||
TaskError = "ErrorMsg", -- task errors
|
||||
TaskWarning = "WarningMsg", -- task errors
|
||||
Error = "DiagnosticError", -- task errors
|
||||
Warning = "DiagnosticWarn", -- task errors
|
||||
Info = "DiagnosticInfo", -- task errors
|
||||
Dir = "@markup.link", -- directory
|
||||
Url = "@markup.link", -- url
|
||||
Bold = { bold = true },
|
||||
|
|
|
@ -354,6 +354,31 @@ end
|
|||
|
||||
---@param plugin LazyPlugin
|
||||
function M:diagnostics(plugin)
|
||||
local skip = false
|
||||
for _, task in ipairs(plugin._.tasks or {}) do
|
||||
if task:is_running() then
|
||||
self:diagnostic({
|
||||
severity = vim.diagnostic.severity.WARN,
|
||||
message = task.name .. (task:status() and (": " .. task:status()) or ""),
|
||||
})
|
||||
skip = true
|
||||
elseif task:has_errors() then
|
||||
self:diagnostic({
|
||||
message = task.name .. " failed",
|
||||
severity = vim.diagnostic.severity.ERROR,
|
||||
})
|
||||
skip = true
|
||||
elseif task:has_warnings() then
|
||||
self:diagnostic({
|
||||
message = task.name .. " warning",
|
||||
severity = vim.diagnostic.severity.WARN,
|
||||
})
|
||||
skip = true
|
||||
end
|
||||
end
|
||||
if skip then
|
||||
return
|
||||
end
|
||||
if plugin._.updated then
|
||||
if plugin._.updated.from == plugin._.updated.to then
|
||||
self:diagnostic({
|
||||
|
@ -383,24 +408,6 @@ function M:diagnostics(plugin)
|
|||
})
|
||||
end
|
||||
end
|
||||
for _, task in ipairs(plugin._.tasks or {}) do
|
||||
if task:is_running() then
|
||||
self:diagnostic({
|
||||
severity = vim.diagnostic.severity.WARN,
|
||||
message = task.name .. (task.status == "" and "" or (": " .. task.status)),
|
||||
})
|
||||
elseif task.error then
|
||||
self:diagnostic({
|
||||
message = task.name .. " failed",
|
||||
severity = vim.diagnostic.severity.ERROR,
|
||||
})
|
||||
elseif task.warn then
|
||||
self:diagnostic({
|
||||
message = task.name .. " warning",
|
||||
severity = vim.diagnostic.severity.WARN,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
|
@ -463,24 +470,27 @@ function M:tasks(plugin)
|
|||
self:append(" " .. math.floor((task:time()) * 100) / 100 .. "ms", "Bold")
|
||||
self:nl()
|
||||
end
|
||||
if task.error then
|
||||
self:markdown(task.error, "LazyTaskError", { indent = 6 })
|
||||
end
|
||||
if task.warn then
|
||||
self:markdown(task.warn, "LazyTaskWarning", { indent = 6 })
|
||||
end
|
||||
if not task.error and not task.warn and task.name == "log" then
|
||||
|
||||
if not task:has_warnings() and task.name == "log" then
|
||||
self:log(task)
|
||||
end
|
||||
if (self.view:is_selected(plugin) or (task.error or task.warn)) and task.output ~= task.error then
|
||||
self:markdown(vim.trim(task.output), "LazyTaskOutput", { indent = 6 })
|
||||
else
|
||||
local hls = {
|
||||
[vim.log.levels.ERROR] = "LazyError",
|
||||
[vim.log.levels.WARN] = "LazyWarning",
|
||||
[vim.log.levels.INFO] = "LazyInfo",
|
||||
}
|
||||
for _, msg in ipairs(task:get_log()) do
|
||||
if task:has_warnings() or self.view:is_selected(plugin) then
|
||||
self:markdown(msg.msg, hls[msg.level] or "LazyTaskOutput", { indent = 6 })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param task LazyTask
|
||||
function M:log(task)
|
||||
local log = vim.trim(task.output)
|
||||
local log = vim.trim(task:output())
|
||||
if log ~= "" then
|
||||
local lines = vim.split(log, "\n")
|
||||
for _, line in ipairs(lines) do
|
||||
|
|
|
@ -17,7 +17,7 @@ return {
|
|||
{
|
||||
filter = function(plugin)
|
||||
return has_task(plugin, function(task)
|
||||
return task.error ~= nil
|
||||
return task:has_errors()
|
||||
end)
|
||||
end,
|
||||
title = "Failed",
|
||||
|
@ -39,8 +39,7 @@ return {
|
|||
if task.name ~= "log" then
|
||||
return
|
||||
end
|
||||
local lines = vim.split(task.output, "\n")
|
||||
for _, line in ipairs(lines) do
|
||||
for _, line in ipairs(vim.split(task:output(), "\n")) do
|
||||
if line:find("^%w+ %S+!:") then
|
||||
return true
|
||||
end
|
||||
|
@ -71,7 +70,7 @@ return {
|
|||
{
|
||||
filter = function(plugin)
|
||||
return has_task(plugin, function(task)
|
||||
return task.name == "log" and vim.trim(task.output) ~= ""
|
||||
return task.name == "log" and vim.trim(task:output()) ~= ""
|
||||
end)
|
||||
end,
|
||||
title = "Log",
|
||||
|
@ -89,7 +88,7 @@ return {
|
|||
title = "Not Installed",
|
||||
},
|
||||
{
|
||||
filter = function (plugin)
|
||||
filter = function(plugin)
|
||||
return plugin._.outdated
|
||||
end,
|
||||
title = "Outdated",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue