Skip to content

Commit eab3abe

Browse files
committed
chore: resolve deprecated in 0.11
1 parent fca0b67 commit eab3abe

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lua/nvim-tree/help.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local WIN_HL = table.concat({
1111
"CursorLine:NvimTreeCursorLine",
1212
}, ",")
1313

14+
local namespace_help_id = vim.api.nvim_create_namespace("NvimTreeHelp")
15+
1416
local M = {
1517
config = {},
1618

@@ -82,8 +84,8 @@ end
8284

8385
--- Compute all lines for the buffer
8486
---@param map table keymap.get_keymap
85-
---@return table strings of text
86-
---@return table arrays of arguments 3-6 for nvim_buf_add_highlight()
87+
---@return string[] lines of text
88+
---@return table[] hl for lines: named arguments for vim.hl.range : higroup, start, finish
8789
---@return number maximum length of text
8890
local function compute(map)
8991
local head_lhs = "nvim-tree mappings"
@@ -131,9 +133,9 @@ local function compute(map)
131133

132134
-- header highlight, assume one character keys
133135
local hl = {
134-
{ "NvimTreeFolderName", 0, 0, #head_lhs },
135-
{ "NvimTreeFolderName", 0, width - 1, width },
136-
{ "NvimTreeFolderName", 1, width - 1, width },
136+
{ higroup = "NvimTreeFolderName", start = { 0, 0, }, finish = { 0, #head_lhs, }, },
137+
{ higroup = "NvimTreeFolderName", start = { 0, width - 1, }, finish = { 0, width, }, },
138+
{ higroup = "NvimTreeFolderName", start = { 1, width - 1, }, finish = { 1, width, }, },
137139
}
138140

139141
-- mappings, left padded 1
@@ -145,7 +147,7 @@ local function compute(map)
145147
width = math.max(#line, width)
146148

147149
-- highlight lhs
148-
table.insert(hl, { "NvimTreeFolderName", i + 1, 1, #l.lhs + 1 })
150+
table.insert(hl, { higroup = "NvimTreeFolderName", start = { i + 1, 1, }, finish = { i + 1, #l.lhs + 1, }, })
149151
end
150152

151153
return lines, hl, width
@@ -188,7 +190,11 @@ local function open()
188190

189191
-- highlight it
190192
for _, h in ipairs(hl) do
191-
vim.api.nvim_buf_add_highlight(M.bufnr, -1, h[1], h[2], h[3], h[4])
193+
if vim.fn.has("nvim-0.11") == 1 then
194+
vim.hl.range(M.bufnr, namespace_help_id, h.higroup, h.start, h.finish, {})
195+
else
196+
vim.api.nvim_buf_add_highlight(M.bufnr, -1, h.higroup, h.start[1], h.start[2], h.finish[2]) ---@diagnostic disable-line: deprecated
197+
end
192198
end
193199

194200
-- open a very restricted window

0 commit comments

Comments
 (0)