HighlightDisplay uses classic
This commit is contained in:
parent
9fc7a866ec
commit
82fc5296ff
@ -1,45 +1,47 @@
|
|||||||
local appearance = require("nvim-tree.appearance")
|
local appearance = require("nvim-tree.appearance")
|
||||||
|
|
||||||
|
local Class = require("nvim-tree.classic")
|
||||||
|
|
||||||
-- others with name and links less than this arbitrary value are short
|
-- others with name and links less than this arbitrary value are short
|
||||||
local SHORT_LEN = 50
|
local SHORT_LEN = 50
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class HighlightDisplay for :NvimTreeHiTest
|
---@class (exact) HighlightDisplay: Class for :NvimTreeHiTest
|
||||||
---@field group string nvim-tree highlight group name
|
---@field group string nvim-tree highlight group name
|
||||||
---@field links string link chain to a concretely defined group
|
---@field links string link chain to a concretely defined group
|
||||||
---@field def string :hi concrete definition after following any links
|
---@field def string :hi concrete definition after following any links
|
||||||
local HighlightDisplay = {}
|
local HighlightDisplay = Class:extend()
|
||||||
|
|
||||||
---@param group string nvim-tree highlight group name
|
---@class HighlightDisplay
|
||||||
---@return HighlightDisplay
|
---@overload fun(args: HighlightDisplayArgs): HighlightDisplay
|
||||||
function HighlightDisplay:new(group)
|
|
||||||
local o = {}
|
|
||||||
setmetatable(o, self)
|
|
||||||
self.__index = self
|
|
||||||
|
|
||||||
o.group = group
|
---@class (exact) HighlightDisplayArgs
|
||||||
local concrete = o.group
|
---@field group string nvim-tree highlight group name
|
||||||
|
|
||||||
|
---@param args HighlightDisplayArgs
|
||||||
|
function HighlightDisplay:new(args)
|
||||||
|
self.group = args.group
|
||||||
|
|
||||||
|
local concrete = self.group
|
||||||
|
|
||||||
-- maybe follow links
|
-- maybe follow links
|
||||||
local links = {}
|
local links = {}
|
||||||
local link = vim.api.nvim_get_hl(0, { name = o.group }).link
|
local link = vim.api.nvim_get_hl(0, { name = self.group }).link
|
||||||
while link do
|
while link do
|
||||||
table.insert(links, link)
|
table.insert(links, link)
|
||||||
concrete = link
|
concrete = link
|
||||||
link = vim.api.nvim_get_hl(0, { name = link }).link
|
link = vim.api.nvim_get_hl(0, { name = link }).link
|
||||||
end
|
end
|
||||||
o.links = table.concat(links, " ")
|
self.links = table.concat(links, " ")
|
||||||
|
|
||||||
-- concrete definition
|
-- concrete definition
|
||||||
local ok, res = pcall(vim.api.nvim_cmd, { cmd = "highlight", args = { concrete } }, { output = true })
|
local ok, res = pcall(vim.api.nvim_cmd, { cmd = "highlight", args = { concrete } }, { output = true })
|
||||||
if ok and type(res) == "string" then
|
if ok and type(res) == "string" then
|
||||||
o.def = res:gsub(".*xxx *", "")
|
self.def = res:gsub(".*xxx *", "")
|
||||||
else
|
else
|
||||||
o.def = ""
|
self.def = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Render one group.
|
---Render one group.
|
||||||
@ -96,7 +98,7 @@ function M.hi_test()
|
|||||||
-- nvim-tree groups, ordered
|
-- nvim-tree groups, ordered
|
||||||
local displays = {}
|
local displays = {}
|
||||||
for _, highlight_group in ipairs(appearance.HIGHLIGHT_GROUPS) do
|
for _, highlight_group in ipairs(appearance.HIGHLIGHT_GROUPS) do
|
||||||
local display = HighlightDisplay:new(highlight_group.group)
|
local display = HighlightDisplay({ group = highlight_group.group })
|
||||||
table.insert(displays, display)
|
table.insert(displays, display)
|
||||||
end
|
end
|
||||||
l = render_displays("nvim-tree", displays, bufnr, l)
|
l = render_displays("nvim-tree", displays, bufnr, l)
|
||||||
@ -110,7 +112,7 @@ function M.hi_test()
|
|||||||
if ok then
|
if ok then
|
||||||
for group in string.gmatch(out, "(%w*)%s+xxx") do
|
for group in string.gmatch(out, "(%w*)%s+xxx") do
|
||||||
if group:find("NvimTree", 1, true) ~= 1 then
|
if group:find("NvimTree", 1, true) ~= 1 then
|
||||||
local display = HighlightDisplay:new(group)
|
local display = HighlightDisplay({ group = group })
|
||||||
if #display.group + #display.links > SHORT_LEN then
|
if #display.group + #display.links > SHORT_LEN then
|
||||||
table.insert(displays_long, display)
|
table.insert(displays_long, display)
|
||||||
else
|
else
|
||||||
|
|||||||
@ -27,7 +27,6 @@ local pad = require("nvim-tree.renderer.components.padding")
|
|||||||
---@field col_end number
|
---@field col_end number
|
||||||
|
|
||||||
---@class (exact) Builder
|
---@class (exact) Builder
|
||||||
---@field private __index? table
|
|
||||||
---@field lines string[] includes icons etc.
|
---@field lines string[] includes icons etc.
|
||||||
---@field hl_args AddHighlightArgs[] line highlights
|
---@field hl_args AddHighlightArgs[] line highlights
|
||||||
---@field signs string[] line signs
|
---@field signs string[] line signs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user