Skip to content

Commit 1bb84f1

Browse files
committed
fix(#2658): add all highlight groups to :NvimTreeHiTest
1 parent 6b9fd75 commit 1bb84f1

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

Diff for: lua/nvim-tree/appearance/diagnostics.lua

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
local appearance = require "nvim-tree.appearance"
22

3+
-- others with name and links less than this arbitrary value are short
4+
local SHORT_LEN = 50
5+
36
local M = {}
47

58
---@class HighlightDisplay for :NvimTreeHiTest
@@ -55,21 +58,16 @@ end
5558

5659
---Render many groups.
5760
---@param header string before with underline line
58-
---@param groups string[] highlight group names
61+
---@param displays HighlightDisplay[] highlight group
5962
---@param bufnr number to render in
6063
---@param l number line number to start at
6164
---@return number l next line number
62-
local function render_groups(header, groups, bufnr, l)
65+
local function render_displays(header, displays, bufnr, l)
6366
local max_group_len = 0
6467
local max_links_len = 0
6568

66-
---@type HighlightDisplay[]
67-
local displays = {}
68-
6969
-- build all highlight groups, using name only
70-
for _, group in ipairs(groups) do
71-
local display = HighlightDisplay:new(group)
72-
table.insert(displays, display)
70+
for _, display in ipairs(displays) do
7371
max_group_len = math.max(max_group_len, #display.group)
7472
max_links_len = math.max(max_links_len, #display.links)
7573
end
@@ -96,26 +94,39 @@ function M.hi_test()
9694
local l = 0
9795

9896
-- nvim-tree groups, ordered
99-
local groups = {}
97+
local displays = {}
10098
for _, highlight_group in ipairs(appearance.HIGHLIGHT_GROUPS) do
101-
table.insert(groups, highlight_group.group)
99+
local display = HighlightDisplay:new(highlight_group.group)
100+
table.insert(displays, display)
102101
end
103-
l = render_groups("nvim-tree", groups, bufnr, l)
102+
l = render_displays("nvim-tree", displays, bufnr, l)
104103

105104
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { "" })
106105
l = l + 1
107106

108107
-- built in groups, ordered opaquely by nvim
109-
groups = {}
108+
local displays_short, displays_long = {}, {}
110109
local ok, out = pcall(vim.api.nvim_cmd, { cmd = "highlight" }, { output = true })
111110
if ok then
112111
for group in string.gmatch(out, "(%w*)%s+xxx") do
113112
if group:find("NvimTree", 1, true) ~= 1 then
114-
table.insert(groups, group)
113+
local display = HighlightDisplay:new(group)
114+
if #display.group + #display.links > SHORT_LEN then
115+
table.insert(displays_long, display)
116+
else
117+
table.insert(displays_short, display)
118+
end
115119
end
116120
end
117121
end
118-
l = render_groups("neovim", groups, bufnr, l)
122+
123+
-- short ones first
124+
l = render_displays("other, short", displays_short, bufnr, l)
125+
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { "" })
126+
l = l + 1
127+
128+
-- long
129+
l = render_displays("other, long", displays_long, bufnr, l)
119130

120131
-- finalise and focus the buffer
121132
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)

0 commit comments

Comments
 (0)