Skip to content

Commit

Permalink
feat: new render features like profile etc
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 24, 2022
1 parent d7dbe1a commit 48199f8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
8 changes: 7 additions & 1 deletion lua/lazy/view/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ M.colors = {
Muted = "Comment",
Normal = "NormalFloat",
Commit = "@variable.builtin",
Key = "@comment",
Key = "Conceal",
Value = "@string",
ProgressDone = {
bold = true,
Expand All @@ -16,6 +16,12 @@ M.colors = {
},
ProgressTodo = "LineNr",
Special = "@punctuation.special",
LoaderPlugin = "Special",
LoaderEvent = "Constant",
LoaderKeys = "Statement",
LoaderStart = "@field",
LoaderSource = "Character",
LoaderCmd = "Operator"
}

M.did_setup = false
Expand Down
65 changes: 49 additions & 16 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
local Config = require("lazy.core.config")
local Util = require("lazy.core.util")
local Manager = require("lazy.manager")
local Util = require("lazy.util")
local Sections = require("lazy.view.sections")
local Loader = require("lazy.core.loader")
local State = require("lazy.core.state")

local Text = require("lazy.view.text")

Expand Down Expand Up @@ -32,10 +33,10 @@ function M:update()
self._diagnostics = {}
self.plugin_range = {}

Manager.check_clean()
State.update_state(true)

self.plugins = vim.tbl_values(Config.plugins)
vim.list_extend(self.plugins, vim.tbl_values(Manager.to_clean))
vim.list_extend(self.plugins, vim.tbl_values(Config.to_clean))
table.sort(self.plugins, function(a, b)
return a.name < b.name
end)
Expand Down Expand Up @@ -167,18 +168,37 @@ function M:reason(plugin)
end
end
end
self:append(" " .. math.floor((reason.time or 0) / 1e6 * 100) / 100 .. "ms ", "Bold")
self:append(" " .. math.floor((reason.time or 0) / 1e6 * 100) / 100 .. "ms", "Bold")
self:append(" ")
-- self:append(" (", "Conceal")
local first = true
for key, value in pairs(reason) do
if key == "require" then
self:append("require", "@function.builtin")
self:append("(", "@punctuation.bracket")
self:append('"' .. value .. '"', "@string")
self:append(")", "@punctuation.bracket")
-- self:append("require", "@function.builtin")
-- self:append("(", "@punctuation.bracket")
-- self:append('"' .. value .. '"', "@string")
-- self:append(")", "@punctuation.bracket")
elseif key ~= "time" then
self:append(key .. " ", "@field")
self:append(value .. " ", "@string")
if first then
first = false
else
self:append(" ")
end
if key == "event" then
value = value:match("User (.*)") or value
end
local hl = "LazyLoader" .. key:sub(1, 1):upper() .. key:sub(2)
local icon = Config.options.view.icons[key]
if icon then
self:append(icon .. " ", hl)
self:append(value, hl)
else
self:append(key .. " ", "@field")
self:append(value, hl)
end
end
end
-- self:append(")", "Conceal")
end

---@param plugin LazyPlugin
Expand Down Expand Up @@ -249,8 +269,11 @@ function M:log(task)
local log = vim.trim(task.output)
if log ~= "" then
local lines = vim.split(log, "\n")
for l, line in ipairs(lines) do
for _, line in ipairs(lines) do
local ref, msg, time = line:match("^(%w+) (.*) (%(.*%))$")
if msg:find("^%S+!:") then
self:diagnostic({ message = "Breaking Changes", severity = vim.diagnostic.severity.WARN })
end
self:append(ref .. " ", "LazyCommit", { indent = 6 })
self:append(vim.trim(msg)):highlight({
["#%d+"] = "Number",
Expand All @@ -273,19 +296,29 @@ function M:details(plugin)
table.insert(props, { "uri", (plugin.uri:gsub("%.git$", "")), "@text.reference" })
local git = Util.git_info(plugin.dir)
if git then
table.insert(props, { "commit ", git.hash:sub(1, 7), "LazyCommit" })
table.insert(props, { "branch ", git.branch })
table.insert(props, { "commit", git.hash:sub(1, 7), "LazyCommit" })
table.insert(props, { "branch", git.branch })
end
if Util.file_exists(plugin.dir .. "/README.md") then
table.insert(props, { "readme ", "README.md" })
table.insert(props, { "readme", "README.md" })
end

for _, loader in ipairs(Loader.types) do
if plugin[loader] then
table.insert(props, {
loader,
type(plugin[loader]) == "string" and plugin[loader] or table.concat(plugin[loader], ", "),
"@string",
})
end
end

local width = 0
for _, prop in ipairs(props) do
width = math.max(width, #prop[1])
end
for _, prop in ipairs(props) do
self:append(prop[1] .. string.rep(" ", width - #prop[1]), "LazyKey", { indent = 6 })
self:append(prop[1] .. string.rep(" ", width - #prop[1] + 1), "LazyKey", { indent = 6 })
self:append(prop[2], prop[3] or "LazyValue")
self:nl()
end
Expand Down

0 comments on commit 48199f8

Please sign in to comment.