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 <jaime@terreu.com> Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
e9ac136a3a
commit
f39f7b6fcd
@ -793,6 +793,7 @@ Use nvim-tree in a floating window.
|
|||||||
|
|
||||||
Highlight precedence, additive:
|
Highlight precedence, additive:
|
||||||
git < opened < modified < bookmarked < diagnostics < copied < cut
|
git < opened < modified < bookmarked < diagnostics < copied < cut
|
||||||
|
Neovim <= 0.8 will only show the highest.
|
||||||
|
|
||||||
*nvim-tree.renderer.add_trailing*
|
*nvim-tree.renderer.add_trailing*
|
||||||
Appends a trailing slash to folder names.
|
Appends a trailing slash to folder names.
|
||||||
|
|||||||
@ -176,8 +176,15 @@ function M.setup()
|
|||||||
|
|
||||||
-- hard link override when legacy only is present
|
-- hard link override when legacy only is present
|
||||||
for from, to in pairs(LEGACY_LINKS) do
|
for from, to in pairs(LEGACY_LINKS) do
|
||||||
local hl_from = vim.api.nvim_get_hl(0, { name = from })
|
local hl_from
|
||||||
local hl_to = vim.api.nvim_get_hl(0, { name = to })
|
local hl_to
|
||||||
|
if vim.fn.has "nvim-0.9" == 1 then
|
||||||
|
hl_from = vim.api.nvim_get_hl(0, { name = from })
|
||||||
|
hl_to = vim.api.nvim_get_hl(0, { name = to })
|
||||||
|
else
|
||||||
|
hl_from = vim.api.nvim__get_hl_defs(0)[from] or {}
|
||||||
|
hl_to = vim.api.nvim__get_hl_defs(0)[to] or {}
|
||||||
|
end
|
||||||
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
|
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
|
||||||
vim.api.nvim_command("hi link " .. from .. " " .. to)
|
vim.api.nvim_command("hi link " .. from .. " " .. to)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -295,16 +295,24 @@ function Builder:add_highlights(node)
|
|||||||
table.insert(name_groups, name)
|
table.insert(name_groups, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- one or many icon groups
|
-- one or many icon groups; <= 0.8 always uses highest due to lack of a practical nvim_get_hl equivalent
|
||||||
if #icon_groups > 1 then
|
if #icon_groups > 1 then
|
||||||
|
if vim.fn.has "nvim-0.9" == 1 then
|
||||||
icon_hl_group = self:create_combined_group(icon_groups)
|
icon_hl_group = self:create_combined_group(icon_groups)
|
||||||
|
else
|
||||||
|
icon_hl_group = icon_groups[#icon_groups]
|
||||||
|
end
|
||||||
else
|
else
|
||||||
icon_hl_group = icon_groups[1]
|
icon_hl_group = icon_groups[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- one or many name groups
|
-- one or many name groups; <= 0.8 always uses highest due to lack of a practical nvim_get_hl equivalent
|
||||||
if #name_groups > 1 then
|
if #name_groups > 1 then
|
||||||
|
if vim.fn.has "nvim-0.9" == 1 then
|
||||||
name_hl_group = self:create_combined_group(name_groups)
|
name_hl_group = self:create_combined_group(name_groups)
|
||||||
|
else
|
||||||
|
name_hl_group = name_groups[#name_groups]
|
||||||
|
end
|
||||||
else
|
else
|
||||||
name_hl_group = name_groups[1]
|
name_hl_group = name_groups[1]
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user