Skip to content

Commit e18b192

Browse files
author
Jaime Terreu
committed
Add support for get_hl_defs in nvim 0.8
nvim-tree is using `nvim_get_hl` which was introduced in nvim 0.9 to replace the unstable `get_hl_defs` in the following [commit](https://github.com/neovim/neovim/pull/22693/files). Unfortunately this raises an error in 0.8 nvim versions due to the function not existing. ``` Failed to run `config` for nvim-tree.lua ...are/nvim/lazy/nvim-tree.lua/lua/nvim-tree/appearance.lua:199: attempt to call field 'nvim_get_hl' (a nil value) stacktrace: - ~/.config/nvim/lua/confidenceman02/plugins/nvim-tree.lua:14 _in_ **config** - ~/.config/nvim/lua/confidenceman02/lazy.lua:14 ``` - Fall back to get_hl_defs when detecting 0.8 - Set the 'link' property to nil to emulate `link = false` in `builder.lua`
1 parent 7bdb220 commit e18b192

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,15 @@ function M.setup()
196196

197197
-- hard link override when legacy only is present
198198
for from, to in pairs(LEGACY_LINKS) do
199-
local hl_from = vim.api.nvim_get_hl(0, { name = from })
200-
local hl_to = vim.api.nvim_get_hl(0, { name = to })
199+
local hl_from
200+
local hl_to
201+
if vim.fn.has "nvim-0.8" == 1 then
202+
hl_from = vim.api.nvim__get_hl_defs(0)[from] or {}
203+
hl_to = vim.api.nvim__get_hl_defs(0)[to] or {}
204+
else
205+
hl_from = vim.api.nvim_get_hl(0, { name = from })
206+
hl_to = vim.api.nvim_get_hl(0, { name = to })
207+
end
201208
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
202209
vim.api.nvim_command("hi link " .. from .. " " .. to)
203210
end

Diff for: lua/nvim-tree/renderer/builder.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,13 @@ function Builder:create_combined_group(groups)
266266

267267
-- build the highlight, overriding values
268268
for _, group in ipairs(groups) do
269-
local hl = vim.api.nvim_get_hl(0, { name = group, link = false })
269+
local hl
270+
if vim.fn.has "nvim-0.8" == 1 then
271+
hl = vim.api.nvim__get_hl_defs(0)[group] or {}
272+
hl["link"] = nil
273+
else
274+
hl = vim.api.nvim_get_hl(0, { name = group, link = false })
275+
end
270276
combined_hl = vim.tbl_extend("force", combined_hl, hl)
271277
end
272278

0 commit comments

Comments
 (0)