From 82fc5296ffb0955911a3e88d320500b209c4bc35 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 8 Nov 2024 15:42:57 +1100 Subject: [PATCH] HighlightDisplay uses classic --- lua/nvim-tree/appearance/diagnostics.lua | 38 +++++++++++++----------- lua/nvim-tree/renderer/builder.lua | 1 - 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lua/nvim-tree/appearance/diagnostics.lua b/lua/nvim-tree/appearance/diagnostics.lua index 5c292104..a5b0dcda 100644 --- a/lua/nvim-tree/appearance/diagnostics.lua +++ b/lua/nvim-tree/appearance/diagnostics.lua @@ -1,45 +1,47 @@ local appearance = require("nvim-tree.appearance") +local Class = require("nvim-tree.classic") + -- others with name and links less than this arbitrary value are short local SHORT_LEN = 50 local M = {} ----@class HighlightDisplay for :NvimTreeHiTest +---@class (exact) HighlightDisplay: Class for :NvimTreeHiTest ---@field group string nvim-tree highlight group name ---@field links string link chain to a concretely defined group ---@field def string :hi concrete definition after following any links -local HighlightDisplay = {} +local HighlightDisplay = Class:extend() ----@param group string nvim-tree highlight group name ----@return HighlightDisplay -function HighlightDisplay:new(group) - local o = {} - setmetatable(o, self) - self.__index = self +---@class HighlightDisplay +---@overload fun(args: HighlightDisplayArgs): HighlightDisplay - o.group = group - local concrete = o.group +---@class (exact) HighlightDisplayArgs +---@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 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 table.insert(links, link) concrete = link link = vim.api.nvim_get_hl(0, { name = link }).link end - o.links = table.concat(links, " ") + self.links = table.concat(links, " ") -- concrete definition local ok, res = pcall(vim.api.nvim_cmd, { cmd = "highlight", args = { concrete } }, { output = true }) if ok and type(res) == "string" then - o.def = res:gsub(".*xxx *", "") + self.def = res:gsub(".*xxx *", "") else - o.def = "" + self.def = "" end - - return o end ---Render one group. @@ -96,7 +98,7 @@ function M.hi_test() -- nvim-tree groups, ordered local displays = {} 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) end l = render_displays("nvim-tree", displays, bufnr, l) @@ -110,7 +112,7 @@ function M.hi_test() if ok then for group in string.gmatch(out, "(%w*)%s+xxx") do 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 table.insert(displays_long, display) else diff --git a/lua/nvim-tree/renderer/builder.lua b/lua/nvim-tree/renderer/builder.lua index 29b3d337..4efa88a2 100644 --- a/lua/nvim-tree/renderer/builder.lua +++ b/lua/nvim-tree/renderer/builder.lua @@ -27,7 +27,6 @@ local pad = require("nvim-tree.renderer.components.padding") ---@field col_end number ---@class (exact) Builder ----@field private __index? table ---@field lines string[] includes icons etc. ---@field hl_args AddHighlightArgs[] line highlights ---@field signs string[] line signs