Skip to content

Commit 161b7bd

Browse files
Confidenceman02Jaime Terreualex-courtis
authored and
juefei yan
committed
fix(#2415): nvim 0.8 highlight overhaul support, limited to only show highest highlight precedence (#2642)
* fix: 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` * fix(#2415): nvim 0.8 highlight overhaul support, limited to only show highest highlight precedence --------- Co-authored-by: Jaime Terreu <[email protected]> Co-authored-by: Alexander Courtis <[email protected]>
1 parent 43f3738 commit 161b7bd

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

doc/nvim-tree-lua.txt

+1
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ Use nvim-tree in a floating window.
793793

794794
Highlight precedence, additive:
795795
git < opened < modified < bookmarked < diagnostics < copied < cut
796+
Neovim <= 0.8 will only show the highest.
796797

797798
*nvim-tree.renderer.add_trailing*
798799
Appends a trailing slash to folder names.

lua/nvim-tree/appearance.lua

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

177177
-- hard link override when legacy only is present
178178
for from, to in pairs(LEGACY_LINKS) do
179-
local hl_from = vim.api.nvim_get_hl(0, { name = from })
180-
local hl_to = vim.api.nvim_get_hl(0, { name = to })
179+
local hl_from
180+
local hl_to
181+
if vim.fn.has "nvim-0.9" == 1 then
182+
hl_from = vim.api.nvim_get_hl(0, { name = from })
183+
hl_to = vim.api.nvim_get_hl(0, { name = to })
184+
else
185+
hl_from = vim.api.nvim__get_hl_defs(0)[from] or {}
186+
hl_to = vim.api.nvim__get_hl_defs(0)[to] or {}
187+
end
181188
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
182189
vim.api.nvim_command("hi link " .. from .. " " .. to)
183190
end

lua/nvim-tree/renderer/builder.lua

+12-4
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,24 @@ function Builder:add_highlights(node)
295295
table.insert(name_groups, name)
296296
end
297297

298-
-- one or many icon groups
298+
-- one or many icon groups; <= 0.8 always uses highest due to lack of a practical nvim_get_hl equivalent
299299
if #icon_groups > 1 then
300-
icon_hl_group = self:create_combined_group(icon_groups)
300+
if vim.fn.has "nvim-0.9" == 1 then
301+
icon_hl_group = self:create_combined_group(icon_groups)
302+
else
303+
icon_hl_group = icon_groups[#icon_groups]
304+
end
301305
else
302306
icon_hl_group = icon_groups[1]
303307
end
304308

305-
-- one or many name groups
309+
-- one or many name groups; <= 0.8 always uses highest due to lack of a practical nvim_get_hl equivalent
306310
if #name_groups > 1 then
307-
name_hl_group = self:create_combined_group(name_groups)
311+
if vim.fn.has "nvim-0.9" == 1 then
312+
name_hl_group = self:create_combined_group(name_groups)
313+
else
314+
name_hl_group = name_groups[#name_groups]
315+
end
308316
else
309317
name_hl_group = name_groups[1]
310318
end

0 commit comments

Comments
 (0)