Skip to content

fix(#2415): nvim 0.8 highlight overhaul support, limited to only show highest highlight precedence #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ Use nvim-tree in a floating window.

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

*nvim-tree.renderer.add_trailing*
Appends a trailing slash to folder names.
Expand Down
11 changes: 9 additions & 2 deletions lua/nvim-tree/appearance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,15 @@ function M.setup()

-- hard link override when legacy only is present
for from, to in pairs(LEGACY_LINKS) do
local hl_from = vim.api.nvim_get_hl(0, { name = from })
local hl_to = vim.api.nvim_get_hl(0, { name = to })
local hl_from
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
vim.api.nvim_command("hi link " .. from .. " " .. to)
end
Expand Down
16 changes: 12 additions & 4 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,24 @@ function Builder:add_highlights(node)
table.insert(name_groups, name)
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
icon_hl_group = self:create_combined_group(icon_groups)
if vim.fn.has "nvim-0.9" == 1 then
icon_hl_group = self:create_combined_group(icon_groups)
else
icon_hl_group = icon_groups[#icon_groups]
end
else
icon_hl_group = icon_groups[1]
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
name_hl_group = self:create_combined_group(name_groups)
if vim.fn.has "nvim-0.9" == 1 then
name_hl_group = self:create_combined_group(name_groups)
else
name_hl_group = name_groups[#name_groups]
Copy link
Member

@alex-courtis alex-courtis Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no practical API to follow links all the way to the actual definitions, so we don't try.

nvim_get_hl_by_name and nvim__get_hl_defs can't follow the links nor give the right data for the setter. vim.fn.synIDtrans is a very tedious and time consuming method to get the real data and not worth the time.

end
else
name_hl_group = name_groups[1]
end
Expand Down