chore: resolve deprecated in 0.11 (#3053)
* chore: resolve deprecated in 0.11 * chore: resolve deprecated in 0.11 * chore: resolve deprecated in 0.11 * chore: resolve deprecated in 0.11 * chore: resolve deprecated in 0.11 * chore: resolve deprecated in 0.11
This commit is contained in:
parent
fca0b67c0b
commit
db7403243d
@ -5,6 +5,8 @@ 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 namespace_hi_test_id = vim.api.nvim_create_namespace("NvimTreeHiTest")
|
||||||
|
|
||||||
---@class (exact) HighlightDisplay: Class 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
|
||||||
@ -52,7 +54,12 @@ function HighlightDisplay:render(bufnr, fmt, l)
|
|||||||
local text = string.format(fmt, self.group, self.links, self.def)
|
local text = string.format(fmt, self.group, self.links, self.def)
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
||||||
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group)
|
|
||||||
|
if vim.fn.has("nvim-0.11") == 1 then
|
||||||
|
vim.hl.range(bufnr, namespace_hi_test_id, self.group, { l, 0 }, { l, #self.group, }, {})
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group) ---@diagnostic disable-line: deprecated
|
||||||
|
end
|
||||||
|
|
||||||
return l + 1
|
return l + 1
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,6 +11,8 @@ local WIN_HL = table.concat({
|
|||||||
"CursorLine:NvimTreeCursorLine",
|
"CursorLine:NvimTreeCursorLine",
|
||||||
}, ",")
|
}, ",")
|
||||||
|
|
||||||
|
local namespace_help_id = vim.api.nvim_create_namespace("NvimTreeHelp")
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
config = {},
|
config = {},
|
||||||
|
|
||||||
@ -82,8 +84,8 @@ end
|
|||||||
|
|
||||||
--- Compute all lines for the buffer
|
--- Compute all lines for the buffer
|
||||||
---@param map table keymap.get_keymap
|
---@param map table keymap.get_keymap
|
||||||
---@return table strings of text
|
---@return string[] lines of text
|
||||||
---@return table arrays of arguments 3-6 for nvim_buf_add_highlight()
|
---@return HighlightRangeArgs[] hl_range_args for lines
|
||||||
---@return number maximum length of text
|
---@return number maximum length of text
|
||||||
local function compute(map)
|
local function compute(map)
|
||||||
local head_lhs = "nvim-tree mappings"
|
local head_lhs = "nvim-tree mappings"
|
||||||
@ -130,10 +132,10 @@ local function compute(map)
|
|||||||
local width = #lines[1]
|
local width = #lines[1]
|
||||||
|
|
||||||
-- header highlight, assume one character keys
|
-- header highlight, assume one character keys
|
||||||
local hl = {
|
local hl_range_args = {
|
||||||
{ "NvimTreeFolderName", 0, 0, #head_lhs },
|
{ higroup = "NvimTreeFolderName", start = { 0, 0, }, finish = { 0, #head_lhs, }, },
|
||||||
{ "NvimTreeFolderName", 0, width - 1, width },
|
{ higroup = "NvimTreeFolderName", start = { 0, width - 1, }, finish = { 0, width, }, },
|
||||||
{ "NvimTreeFolderName", 1, width - 1, width },
|
{ higroup = "NvimTreeFolderName", start = { 1, width - 1, }, finish = { 1, width, }, },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- mappings, left padded 1
|
-- mappings, left padded 1
|
||||||
@ -145,10 +147,10 @@ local function compute(map)
|
|||||||
width = math.max(#line, width)
|
width = math.max(#line, width)
|
||||||
|
|
||||||
-- highlight lhs
|
-- highlight lhs
|
||||||
table.insert(hl, { "NvimTreeFolderName", i + 1, 1, #l.lhs + 1 })
|
table.insert(hl_range_args, { higroup = "NvimTreeFolderName", start = { i + 1, 1, }, finish = { i + 1, #l.lhs + 1, }, })
|
||||||
end
|
end
|
||||||
|
|
||||||
return lines, hl, width
|
return lines, hl_range_args, width
|
||||||
end
|
end
|
||||||
|
|
||||||
--- close the window and delete the buffer, if they exist
|
--- close the window and delete the buffer, if they exist
|
||||||
@ -172,7 +174,7 @@ local function open()
|
|||||||
local map = keymap.get_keymap()
|
local map = keymap.get_keymap()
|
||||||
|
|
||||||
-- text and highlight
|
-- text and highlight
|
||||||
local lines, hl, width = compute(map)
|
local lines, hl_range_args, width = compute(map)
|
||||||
|
|
||||||
-- create the buffer
|
-- create the buffer
|
||||||
M.bufnr = vim.api.nvim_create_buf(false, true)
|
M.bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
@ -187,8 +189,12 @@ local function open()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- highlight it
|
-- highlight it
|
||||||
for _, h in ipairs(hl) do
|
for _, args in ipairs(hl_range_args) do
|
||||||
vim.api.nvim_buf_add_highlight(M.bufnr, -1, h[1], h[2], h[3], h[4])
|
if vim.fn.has("nvim-0.11") == 1 then
|
||||||
|
vim.hl.range(M.bufnr, namespace_help_id, args.higroup, args.start, args.finish, {})
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_add_highlight(M.bufnr, -1, args.higroup, args.start[1], args.start[2], args.finish[2]) ---@diagnostic disable-line: deprecated
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- open a very restricted window
|
-- open a very restricted window
|
||||||
|
|||||||
@ -33,15 +33,9 @@ local BUILTIN_DECORATORS = {
|
|||||||
Cut = CutDecorator,
|
Cut = CutDecorator,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@class (exact) AddHighlightArgs
|
|
||||||
---@field group string[]
|
|
||||||
---@field line number
|
|
||||||
---@field col_start number
|
|
||||||
---@field col_end number
|
|
||||||
|
|
||||||
---@class (exact) Builder
|
---@class (exact) Builder
|
||||||
---@field lines string[] includes icons etc.
|
---@field lines string[] includes icons etc.
|
||||||
---@field hl_args AddHighlightArgs[] line highlights
|
---@field hl_range_args HighlightRangeArgs[] highlights for lines
|
||||||
---@field signs string[] line signs
|
---@field signs string[] line signs
|
||||||
---@field extmarks table[] extra marks for right icon placement
|
---@field extmarks table[] extra marks for right icon placement
|
||||||
---@field virtual_lines table[] virtual lines for hidden count display
|
---@field virtual_lines table[] virtual lines for hidden count display
|
||||||
@ -67,7 +61,7 @@ function Builder:new(args)
|
|||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.depth = 0
|
self.depth = 0
|
||||||
self.hl_args = {}
|
self.hl_range_args = {}
|
||||||
self.combined_groups = {}
|
self.combined_groups = {}
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
self.markers = {}
|
self.markers = {}
|
||||||
@ -106,7 +100,9 @@ end
|
|||||||
---@param start number
|
---@param start number
|
||||||
---@param end_ number|nil
|
---@param end_ number|nil
|
||||||
function Builder:insert_highlight(groups, start, end_)
|
function Builder:insert_highlight(groups, start, end_)
|
||||||
table.insert(self.hl_args, { groups, self.index, start, end_ or -1 })
|
for _, higroup in ipairs(groups) do
|
||||||
|
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start, }, finish = { self.index, end_ or -1, } })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
|
|||||||
@ -79,7 +79,13 @@ local function show()
|
|||||||
---@type vim.api.keyset.extmark_details
|
---@type vim.api.keyset.extmark_details
|
||||||
local details = extmark[4]
|
local details = extmark[4]
|
||||||
|
|
||||||
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col)
|
if type(details) == "table" then
|
||||||
|
if vim.fn.has("nvim-0.12") == 1 then
|
||||||
|
vim.hl.range(0, ns_id, details.hl_group, { 0, col }, { 0, details.end_col, }, {})
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col) ---@diagnostic disable-line: deprecated
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
|
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
|
||||||
end)
|
end)
|
||||||
|
|||||||
@ -11,6 +11,8 @@ local namespace_highlights_id = vim.api.nvim_create_namespace("NvimTreeHighlight
|
|||||||
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
|
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
|
||||||
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
|
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
|
||||||
|
|
||||||
|
---@alias HighlightRangeArgs { higroup:string, start:integer[], finish:integer[] } named arguments for vim.hl.range
|
||||||
|
|
||||||
---@class (exact) Renderer: Class
|
---@class (exact) Renderer: Class
|
||||||
---@field explorer Explorer
|
---@field explorer Explorer
|
||||||
local Renderer = Class:extend()
|
local Renderer = Class:extend()
|
||||||
@ -30,11 +32,11 @@ end
|
|||||||
---@private
|
---@private
|
||||||
---@param bufnr number
|
---@param bufnr number
|
||||||
---@param lines string[]
|
---@param lines string[]
|
||||||
---@param hl_args AddHighlightArgs[]
|
---@param hl_range_args HighlightRangeArgs[]
|
||||||
---@param signs string[]
|
---@param signs string[]
|
||||||
---@param extmarks table[] extra marks for right icon placement
|
---@param extmarks table[] extra marks for right icon placement
|
||||||
---@param virtual_lines table[] virtual lines for hidden count display
|
---@param virtual_lines table[] virtual lines for hidden count display
|
||||||
function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
|
function Renderer:_draw(bufnr, lines, hl_range_args, signs, extmarks, virtual_lines)
|
||||||
if vim.fn.has("nvim-0.10") == 1 then
|
if vim.fn.has("nvim-0.10") == 1 then
|
||||||
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
||||||
else
|
else
|
||||||
@ -42,7 +44,7 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||||
self:render_hl(bufnr, hl_args)
|
self:render_hl(bufnr, hl_range_args)
|
||||||
|
|
||||||
if vim.fn.has("nvim-0.10") == 1 then
|
if vim.fn.has("nvim-0.10") == 1 then
|
||||||
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
||||||
@ -77,16 +79,18 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function Renderer:render_hl(bufnr, hl)
|
---@param bufnr integer
|
||||||
|
---@param hl_range_args HighlightRangeArgs[]
|
||||||
|
function Renderer:render_hl(bufnr, hl_range_args)
|
||||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
|
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
|
||||||
for _, data in ipairs(hl) do
|
for _, args in ipairs(hl_range_args) do
|
||||||
if type(data[1]) == "table" then
|
if vim.fn.has("nvim-0.11") == 1 then
|
||||||
for _, group in ipairs(data[1]) do
|
vim.hl.range(bufnr, namespace_highlights_id, args.higroup, args.start, args.finish, {})
|
||||||
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
|
else
|
||||||
end
|
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, args.higroup, args.start[1], args.start[2], args.finish[2]) ---@diagnostic disable-line: deprecated
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -103,7 +107,7 @@ function Renderer:draw()
|
|||||||
|
|
||||||
local builder = Builder(self.explorer):build()
|
local builder = Builder(self.explorer):build()
|
||||||
|
|
||||||
self:_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
||||||
|
|
||||||
if cursor and #builder.lines >= cursor[1] then
|
if cursor and #builder.lines >= cursor[1] then
|
||||||
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
|
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user