Skip to content

Commit f142072

Browse files
authored
chore: resolve deprecated api (#574)
* chore: replace deprecated neovim API * chore: replace deprecated neovim API * chore: replace deprecated neovim API
1 parent 5b9b524 commit f142072

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lua/nvim-web-devicons.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ local function get_highlight_ctermfg(icon_data)
191191
local higroup = get_highlight_name(icon_data)
192192

193193
if vim.fn.has "nvim-0.9" == 1 then
194+
--- @type string
194195
--- @diagnostic disable-next-line: undefined-field vim.api.keyset.hl_info specifies cterm, not ctermfg
195196
return vim.api.nvim_get_hl(0, { name = higroup, link = false }).ctermfg
196197
else

lua/nvim-web-devicons/hi-test.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---Run a test similar to :so $VIMRUNTIME/syntax/hitest.vim
22
---Display all icons and their group highlighted, followed by the concrete definition
3-
--
4-
---@class IconDisplay for :NvimTreeHiTest
3+
4+
local namespace_hi_test_id = vim.api.nvim_create_namespace "NvimWebDeviconsHiTest"
5+
6+
---@class (exact) IconDisplay for :NvimTreeHiTest
57
---@field tag string filename, os or extension
68
---@field name string name without prefix
79
---@field icon string icon itself
810
---@field group string|nil :hi group name
911
---@field def string|nil :hi concrete definition
12+
---@field private __index IconDisplay? TODO migrate to classic
1013
local IconDisplay = {}
1114

1215
---@param o IconDisplay
@@ -44,7 +47,11 @@ function IconDisplay:render(bufnr, max_tag_len, max_group_len, l)
4447
local text = string.format(fmt, self.icon, self.tag, self.group, self.def)
4548

4649
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
47-
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, -1)
50+
if vim.fn.has "nvim-0.11" == 1 and vim.hl and vim.hl.range then
51+
vim.hl.range(bufnr, namespace_hi_test_id, self.group, { l, 0 }, { l, -1 }, {})
52+
else
53+
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, -1) ---@diagnostic disable-line: deprecated
54+
end
4855

4956
return l + 1
5057
end

0 commit comments

Comments
 (0)