Skip to content

feat(#2415): granular highlight_diagnostics, normalise groups #2454

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
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
81 changes: 64 additions & 17 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CONTENTS *nvim-tree*
7. Mappings |nvim-tree-mappings|
7.1 Mappings: Default |nvim-tree-mappings-default|
8. Highlight |nvim-tree-highlight|
8.1 Highlight Overhaul |nvim-tree-highlight-overhaul|
9. Events |nvim-tree-events|
10. OS Specific Restrictions |nvim-tree-os-specific|
11. Netrw |nvim-tree-netrw|
Expand Down Expand Up @@ -384,7 +385,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
symlink_destination = true,
highlight_git = false,
highlight_diagnostics = false,
highlight_diagnostics = "none",
highlight_opened_files = "none",
highlight_modified = "none",
highlight_bookmarks = "none",
Expand Down Expand Up @@ -825,9 +826,10 @@ Requires |nvim-tree.git.enable|
Type: `boolean`, Default: `false`

*nvim-tree.renderer.highlight_diagnostics*
Enable highlight for diagnostics using `LspDiagnosticsError*Text` highlight groups.
Enable highlight for diagnostics using `NvimTreeDiagnostic*HL` highlight groups.
Requires |nvim-tree.diagnostics.enable|
Type: `boolean`, Default: `false`
Value can be `"none"`, `"icon"`, `"name"` or `"all"`.
Type: `string`, Default: `"none"`

*nvim-tree.renderer.highlight_opened_files*
Highlight icons and/or names for |bufloaded()| files using the
Expand Down Expand Up @@ -2238,22 +2240,67 @@ Git Folder Text: >
NvimTreeFolderIgnored NvimTreeFileIgnored
<
Diagnostics Icon: >
NvimTreeLspDiagnosticsError DiagnosticError
NvimTreeLspDiagnosticsWarning DiagnosticWarn
NvimTreeLspDiagnosticsInformation DiagnosticInfo
NvimTreeLspDiagnosticsHint DiagnosticHint
NvimTreeDiagnosticErrorIcon DiagnosticError
NvimTreeDiagnosticWarnIcon DiagnosticWarn
NvimTreeDiagnosticInfoIcon DiagnosticInfo
NvimTreeDiagnosticHintIcon DiagnosticHint
<
Diagnostics File Highlight: >
NvimTreeDiagnosticErrorFileHL DiagnosticUnderlineError
NvimTreeDiagnosticWarnFileHL DiagnosticUnderlineWarn
NvimTreeDiagnosticInfoFileHL DiagnosticUnderlineInfo
NvimTreeDiagnosticHintFileHL DiagnosticUnderlineHint
<
Diagnostics File Text: >
NvimTreeLspDiagnosticsErrorText NvimTreeLspDiagnosticsError
NvimTreeLspDiagnosticsWarningText NvimTreeLspDiagnosticsWarning
NvimTreeLspDiagnosticsInfoText NvimTreeLspDiagnosticsInformation
NvimTreeLspDiagnosticsHintText NvimTreeLspDiagnosticsHint
Diagnostics Folder Highlight: >
NvimTreeDiagnosticErrorFolderHL DiagnosticUnderlineError
NvimTreeDiagnosticWarnFolderHL DiagnosticUnderlineWarn
NvimTreeDiagnosticInfoFolderHL DiagnosticUnderlineInfo
NvimTreeDiagnosticHintFolderHL DiagnosticUnderlineHint
<

==============================================================================
8.1 HIGHLIGHT OVERHAUL *nvim-tree-highlight-overhaul*

2023/10/XX revision xxxxx made significant highlighting changes, some breaking:

- Highlight groups named consistently
- Standard vim highlight groups such |DiagnosticUnderlineError| are now the
defaults.
- All `highlight_xxx` e.g. |nvim-tree.renderer.highlight_git| are granular,
allowing `"none"`, `"icon"`, `"name"` or `"all"`
- `highlight_xxx` has highlight groups for both File and Folder
- `highlight_xxx` is additive instead of overwriting. See
|nvim-tree-opts-renderer| for precedence.

Legacy style may be applied: >

:hi link NvimTreeDiagnosticErrorFileHL DiagnosticError
:hi link NvimTreeDiagnosticWarnFileHL DiagnosticWarn
:hi link NvimTreeDiagnosticInfoFileHL DiagnosticInfo
:hi link NvimTreeDiagnosticHintFileHL DiagnosticHint

:hi link NvimTreeDiagnosticErrorFolderHL DiagnosticError
:hi link NvimTreeDiagnosticWarnFolderHL DiagnosticWarn
:hi link NvimTreeDiagnosticInfoFolderHL DiagnosticInfo
:hi link NvimTreeDiagnosticHintFolderHL DiagnosticHint
<
Diagnostics Folder Text: >
NvimTreeLspDiagnosticsErrorFolderText NvimTreeLspDiagnosticsErrorText
NvimTreeLspDiagnosticsWarningFolderText NvimTreeLspDiagnosticsWarningText
NvimTreeLspDiagnosticsInfoFolderText NvimTreeLspDiagnosticsInfoText
NvimTreeLspDiagnosticsHintFolderText NvimTreeLspDiagnosticsHintText
Legacy highlight group are still obeyed when they are defined and the current
highlight group is not, hard linking as follows: >

NvimTreeLspDiagnosticsError NvimTreeDiagnosticErrorIcon
NvimTreeLspDiagnosticsWarning NvimTreeDiagnosticWarnIcon
NvimTreeLspDiagnosticsInformation NvimTreeDiagnosticInfoIcon
NvimTreeLspDiagnosticsHint NvimTreeDiagnosticHintIcon

NvimTreeLspDiagnosticsErrorText NvimTreeDiagnosticErrorFileHL
NvimTreeLspDiagnosticsWarningText NvimTreeDiagnosticWarnFileHL
NvimTreeLspDiagnosticsInformationText NvimTreeDiagnosticInfoFileHL
NvimTreeLspDiagnosticsHintText NvimTreeDiagnosticHintFileHL

NvimTreeLspDiagnosticsErrorFolderText NvimTreeDiagnosticErrorFolderHL
NvimTreeLspDiagnosticsWarningFolderText NvimTreeDiagnosticWarnFolderHL
NvimTreeLspDiagnosticsInformationFolderText NvimTreeDiagnosticInfoFolderHL
NvimTreeLspDiagnosticsHintFolderText NvimTreeDiagnosticHintFolderHL
<
==============================================================================
9. EVENTS *nvim-tree-events*
Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
symlink_destination = true,
highlight_git = false,
highlight_diagnostics = false,
highlight_diagnostics = "none",
highlight_opened_files = "none",
highlight_modified = "none",
highlight_bookmarks = "none",
Expand Down Expand Up @@ -658,6 +658,7 @@ local ACCEPTED_STRINGS = {
highlight_opened_files = { "none", "icon", "name", "all" },
highlight_modified = { "none", "icon", "name", "all" },
highlight_bookmarks = { "none", "icon", "name", "all" },
highlight_diagnostics = { "none", "icon", "name", "all" },
highlight_clipboard = { "none", "icon", "name", "all" },
icons = {
git_placement = { "before", "after", "signcolumn" },
Expand Down
162 changes: 104 additions & 58 deletions lua/nvim-tree/colors.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,103 @@
local M = {}

-- nvim-tree default highlight group links
local DEFAULT_LINKS = {
-- File Text
NvimTreeFolderName = "Directory",
NvimTreeEmptyFolderName = "Directory",
NvimTreeOpenedFolderName = "Directory",
NvimTreeSymlinkFolderName = "Directory",

-- Folder Text
NvimTreeOpenedFileIcon = "NvimTreeOpenedFile",
NvimTreeOpenedFolderIcon = "NvimTreeFolderIcon",
NvimTreeClosedFolderIcon = "NvimTreeFolderIcon",

-- Standard
NvimTreeNormal = "Normal",
NvimTreeNormalFloat = "NormalFloat",
NvimTreeNormalNC = "NvimTreeNormal",
NvimTreeLineNr = "LineNr",
NvimTreeWinSeparator = "WinSeparator",
NvimTreeEndOfBuffer = "EndOfBuffer",
NvimTreePopup = "Normal",
NvimTreeSignColumn = "NvimTreeNormal",
NvimTreeCursorLine = "CursorLine",
NvimTreeCursorColumn = "CursorColumn",
NvimTreeCursorLineNr = "CursorLineNr",
NvimTreeStatusLine = "StatusLine",
NvimTreeStatusLineNC = "StatusLineNC",

-- Clipboard
NvimTreeCutHL = "SpellBad",
NvimTreeCopiedHL = "SpellRare",

-- Bookmark Highlight
NvimTreeBookmarkHL = "SpellLocal",

-- Git Icon
NvimTreeGitIgnored = "Comment",

-- Git File Text
NvimTreeFileDirty = "NvimTreeGitDirty",
NvimTreeFileStaged = "NvimTreeGitStaged",
NvimTreeFileMerge = "NvimTreeGitMerge",
NvimTreeFileRenamed = "NvimTreeGitRenamed",
NvimTreeFileNew = "NvimTreeGitNew",
NvimTreeFileDeleted = "NvimTreeGitDeleted",
NvimTreeFileIgnored = "NvimTreeGitIgnored",

-- Git Folder Text
NvimTreeFolderDirty = "NvimTreeFileDirty",
NvimTreeFolderStaged = "NvimTreeFileStaged",
NvimTreeFolderMerge = "NvimTreeFileMerge",
NvimTreeFolderRenamed = "NvimTreeFileRenamed",
NvimTreeFolderNew = "NvimTreeFileNew",
NvimTreeFolderDeleted = "NvimTreeFileDeleted",
NvimTreeFolderIgnored = "NvimTreeFileIgnored",

-- Diagnostics Icon
NvimTreeDiagnosticErrorIcon = "DiagnosticError",
NvimTreeDiagnosticWarnIcon = "DiagnosticWarn",
NvimTreeDiagnosticInfoIcon = "DiagnosticInfo",
NvimTreeDiagnosticHintIcon = "DiagnosticHint",

-- Diagnostics File Highlight
NvimTreeDiagnosticErrorFileHL = "DiagnosticUnderlineError",
NvimTreeDiagnosticWarnFileHL = "DiagnosticUnderlineWarn",
NvimTreeDiagnosticInfoFileHL = "DiagnosticUnderlineInfo",
NvimTreeDiagnosticHintFileHL = "DiagnosticUnderlineHint",

-- Diagnostics Folder Highlight
NvimTreeDiagnosticErrorFolderHL = "DiagnosticUnderlineError",
NvimTreeDiagnosticWarnFolderHL = "DiagnosticUnderlineWarn",
NvimTreeDiagnosticInfoFolderHL = "DiagnosticUnderlineInfo",
NvimTreeDiagnosticHintFolderHL = "DiagnosticUnderlineHint",
}

-- nvim-tree highlight groups to legacy
local LEGACY_LINKS = {
NvimTreeDiagnosticErrorIcon = "NvimTreeLspDiagnosticsError",
NvimTreeDiagnosticWarnIcon = "NvimTreeLspDiagnosticsWarning",
NvimTreeDiagnosticInfoIcon = "NvimTreeLspDiagnosticsInformation",
NvimTreeDiagnosticHintIcon = "NvimTreeLspDiagnosticsHint",
NvimTreeDiagnosticErrorFileHL = "NvimTreeLspDiagnosticsErrorText",
NvimTreeDiagnosticWarnFileHL = "NvimTreeLspDiagnosticsWarningText",
NvimTreeDiagnosticInfoFileHL = "NvimTreeLspDiagnosticsInformationText",
NvimTreeDiagnosticHintFileHL = "NvimTreeLspDiagnosticsHintText",
NvimTreeDiagnosticErrorFolderHL = "NvimTreeLspDiagnosticsErrorFolderText",
NvimTreeDiagnosticWarnFolderHL = "NvimTreeLspDiagnosticsWarningFolderText",
NvimTreeDiagnosticInfoFolderHL = "NvimTreeLspDiagnosticsInformationFolderText",
NvimTreeDiagnosticHintFolderHL = "NvimTreeLspDiagnosticsHintFolderText",
}

local function get_color_from_hl(hl_name, fallback)
local id = vim.api.nvim_get_hl_id_by_name(hl_name)
if not id then
return fallback
end

-- TODO this is unreachable as nvim_get_hl_id_by_name returns a new ID if not present
local foreground = vim.fn.synIDattr(vim.fn.synIDtrans(id), "fg")
if not foreground or foreground == "" then
return fallback
Expand Down Expand Up @@ -57,61 +149,6 @@ local function get_hl_groups()
}
end

local function get_links()
return {
FolderName = "Directory",
EmptyFolderName = "Directory",
OpenedFolderName = "Directory",
SymlinkFolderName = "Directory",
OpenedFolderIcon = "NvimTreeFolderIcon",
ClosedFolderIcon = "NvimTreeFolderIcon",
OpenedFileIcon = "NvimTreeOpenedFile",
Normal = "Normal",
NormalFloat = "NormalFloat",
NormalNC = "NvimTreeNormal",
EndOfBuffer = "EndOfBuffer",
CursorLineNr = "CursorLineNr",
LineNr = "LineNr",
CursorLine = "CursorLine",
WinSeparator = "WinSeparator",
CursorColumn = "CursorColumn",
FileDirty = "NvimTreeGitDirty",
FileNew = "NvimTreeGitNew",
FileRenamed = "NvimTreeGitRenamed",
FileMerge = "NvimTreeGitMerge",
FileStaged = "NvimTreeGitStaged",
FileDeleted = "NvimTreeGitDeleted",
FileIgnored = "NvimTreeGitIgnored",
FolderDirty = "NvimTreeFileDirty",
FolderNew = "NvimTreeFileNew",
FolderRenamed = "NvimTreeFileRenamed",
FolderMerge = "NvimTreeFileMerge",
FolderStaged = "NvimTreeFileStaged",
FolderDeleted = "NvimTreeFileDeleted",
FolderIgnored = "NvimTreeFileIgnored",
LspDiagnosticsError = "DiagnosticError",
LspDiagnosticsWarning = "DiagnosticWarn",
LspDiagnosticsInformation = "DiagnosticInfo",
LspDiagnosticsHint = "DiagnosticHint",
LspDiagnosticsErrorText = "NvimTreeLspDiagnosticsError",
LspDiagnosticsWarningText = "NvimTreeLspDiagnosticsWarning",
LspDiagnosticsInformationText = "NvimTreeLspDiagnosticsInformation",
LspDiagnosticsHintText = "NvimTreeLspDiagnosticsHintFile",
LspDiagnosticsErrorFolderText = "NvimTreeLspDiagnosticsErrorText",
LspDiagnosticsWarningFolderText = "NvimTreeLspDiagnosticsWarningText",
LspDiagnosticsInformationFolderText = "NvimTreeLspDiagnosticsInformationText",
LspDiagnosticsHintFolderText = "NvimTreeLspDiagnosticsHintFileText",
Popup = "Normal",
GitIgnored = "Comment",
StatusLine = "StatusLine",
StatusLineNC = "StatusLineNC",
SignColumn = "NvimTreeNormal",
CutHL = "SpellBad",
CopiedHL = "SpellRare",
BookmarkHL = "SpellLocal",
}
end

function M.setup()
local highlight_groups = get_hl_groups()
for k, d in pairs(highlight_groups) do
Expand All @@ -121,9 +158,18 @@ function M.setup()
vim.api.nvim_command("hi def NvimTree" .. k .. gui .. fg .. bg)
end

local links = get_links()
for k, d in pairs(links) do
vim.api.nvim_command("hi def link NvimTree" .. k .. " " .. d)
-- 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 })
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
vim.api.nvim_command("hi link " .. from .. " " .. to)
end
end

-- default links
for from, to in pairs(DEFAULT_LINKS) do
vim.api.nvim_command("hi def link " .. from .. " " .. to)
end
end

Expand Down
9 changes: 9 additions & 0 deletions lua/nvim-tree/legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ local function refactored(opts)

-- 2023/08/26
utils.move_missing_val(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true)

-- 2023/10/08
if type(opts.renderer) == "table" and type(opts.renderer.highlight_diagnostics) == "boolean" then
if opts.renderer.highlight_diagnostics then
opts.renderer.highlight_diagnostics = "name"
else
opts.renderer.highlight_diagnostics = "none"
end
end
end

local function deprecated(opts)
Expand Down
Loading