Skip to content

Commit e7f69c1

Browse files
committed
feat(#2415): granular highlight_diagnostics, normalise groups (#2454)
1 parent 78a5836 commit e7f69c1

File tree

5 files changed

+208
-102
lines changed

5 files changed

+208
-102
lines changed

doc/nvim-tree-lua.txt

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ CONTENTS *nvim-tree*
4646
7. Mappings |nvim-tree-mappings|
4747
7.1 Mappings: Default |nvim-tree-mappings-default|
4848
8. Highlight |nvim-tree-highlight|
49+
8.1 Highlight Overhaul |nvim-tree-highlight-overhaul|
4950
9. Events |nvim-tree-events|
5051
10. Prompts |nvim-tree-prompts|
5152
11. OS Specific Restrictions |nvim-tree-os-specific|
@@ -388,7 +389,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
388389
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
389390
symlink_destination = true,
390391
highlight_git = false,
391-
highlight_diagnostics = false,
392+
highlight_diagnostics = "none",
392393
highlight_opened_files = "none",
393394
highlight_modified = "none",
394395
highlight_bookmarks = "none",
@@ -837,9 +838,10 @@ Requires |nvim-tree.git.enable|
837838
Type: `boolean`, Default: `false`
838839

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

844846
*nvim-tree.renderer.highlight_opened_files*
845847
Highlight icons and/or names for |bufloaded()| files using the
@@ -2336,22 +2338,67 @@ Git Folder Text: >
23362338
NvimTreeFolderIgnored NvimTreeFileIgnored
23372339
<
23382340
Diagnostics Icon: >
2339-
NvimTreeLspDiagnosticsError DiagnosticError
2340-
NvimTreeLspDiagnosticsWarning DiagnosticWarn
2341-
NvimTreeLspDiagnosticsInformation DiagnosticInfo
2342-
NvimTreeLspDiagnosticsHint DiagnosticHint
2341+
NvimTreeDiagnosticErrorIcon DiagnosticError
2342+
NvimTreeDiagnosticWarnIcon DiagnosticWarn
2343+
NvimTreeDiagnosticInfoIcon DiagnosticInfo
2344+
NvimTreeDiagnosticHintIcon DiagnosticHint
2345+
<
2346+
Diagnostics File Highlight: >
2347+
NvimTreeDiagnosticErrorFileHL DiagnosticUnderlineError
2348+
NvimTreeDiagnosticWarnFileHL DiagnosticUnderlineWarn
2349+
NvimTreeDiagnosticInfoFileHL DiagnosticUnderlineInfo
2350+
NvimTreeDiagnosticHintFileHL DiagnosticUnderlineHint
23432351
<
2344-
Diagnostics File Text: >
2345-
NvimTreeLspDiagnosticsErrorText NvimTreeLspDiagnosticsError
2346-
NvimTreeLspDiagnosticsWarningText NvimTreeLspDiagnosticsWarning
2347-
NvimTreeLspDiagnosticsInfoText NvimTreeLspDiagnosticsInformation
2348-
NvimTreeLspDiagnosticsHintText NvimTreeLspDiagnosticsHint
2352+
Diagnostics Folder Highlight: >
2353+
NvimTreeDiagnosticErrorFolderHL DiagnosticUnderlineError
2354+
NvimTreeDiagnosticWarnFolderHL DiagnosticUnderlineWarn
2355+
NvimTreeDiagnosticInfoFolderHL DiagnosticUnderlineInfo
2356+
NvimTreeDiagnosticHintFolderHL DiagnosticUnderlineHint
2357+
<
2358+
2359+
==============================================================================
2360+
8.1 HIGHLIGHT OVERHAUL *nvim-tree-highlight-overhaul*
2361+
2362+
2023/10/XX revision xxxxx made significant highlighting changes, some breaking:
2363+
2364+
- Highlight groups named consistently
2365+
- Standard vim highlight groups such |DiagnosticUnderlineError| are now the
2366+
defaults.
2367+
- All `highlight_xxx` e.g. |nvim-tree.renderer.highlight_git| are granular,
2368+
allowing `"none"`, `"icon"`, `"name"` or `"all"`
2369+
- `highlight_xxx` has highlight groups for both File and Folder
2370+
- `highlight_xxx` is additive instead of overwriting. See
2371+
|nvim-tree-opts-renderer| for precedence.
2372+
2373+
Legacy style may be applied: >
2374+
2375+
:hi link NvimTreeDiagnosticErrorFileHL DiagnosticError
2376+
:hi link NvimTreeDiagnosticWarnFileHL DiagnosticWarn
2377+
:hi link NvimTreeDiagnosticInfoFileHL DiagnosticInfo
2378+
:hi link NvimTreeDiagnosticHintFileHL DiagnosticHint
2379+
2380+
:hi link NvimTreeDiagnosticErrorFolderHL DiagnosticError
2381+
:hi link NvimTreeDiagnosticWarnFolderHL DiagnosticWarn
2382+
:hi link NvimTreeDiagnosticInfoFolderHL DiagnosticInfo
2383+
:hi link NvimTreeDiagnosticHintFolderHL DiagnosticHint
23492384
<
2350-
Diagnostics Folder Text: >
2351-
NvimTreeLspDiagnosticsErrorFolderText NvimTreeLspDiagnosticsErrorText
2352-
NvimTreeLspDiagnosticsWarningFolderText NvimTreeLspDiagnosticsWarningText
2353-
NvimTreeLspDiagnosticsInfoFolderText NvimTreeLspDiagnosticsInfoText
2354-
NvimTreeLspDiagnosticsHintFolderText NvimTreeLspDiagnosticsHintText
2385+
Legacy highlight group are still obeyed when they are defined and the current
2386+
highlight group is not, hard linking as follows: >
2387+
2388+
NvimTreeLspDiagnosticsError NvimTreeDiagnosticErrorIcon
2389+
NvimTreeLspDiagnosticsWarning NvimTreeDiagnosticWarnIcon
2390+
NvimTreeLspDiagnosticsInformation NvimTreeDiagnosticInfoIcon
2391+
NvimTreeLspDiagnosticsHint NvimTreeDiagnosticHintIcon
2392+
2393+
NvimTreeLspDiagnosticsErrorText NvimTreeDiagnosticErrorFileHL
2394+
NvimTreeLspDiagnosticsWarningText NvimTreeDiagnosticWarnFileHL
2395+
NvimTreeLspDiagnosticsInformationText NvimTreeDiagnosticInfoFileHL
2396+
NvimTreeLspDiagnosticsHintText NvimTreeDiagnosticHintFileHL
2397+
2398+
NvimTreeLspDiagnosticsErrorFolderText NvimTreeDiagnosticErrorFolderHL
2399+
NvimTreeLspDiagnosticsWarningFolderText NvimTreeDiagnosticWarnFolderHL
2400+
NvimTreeLspDiagnosticsInformationFolderText NvimTreeDiagnosticInfoFolderHL
2401+
NvimTreeLspDiagnosticsHintFolderText NvimTreeDiagnosticHintFolderHL
23552402
<
23562403
==============================================================================
23572404
9. EVENTS *nvim-tree-events*

lua/nvim-tree.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
387387
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
388388
symlink_destination = true,
389389
highlight_git = false,
390-
highlight_diagnostics = false,
390+
highlight_diagnostics = "none",
391391
highlight_opened_files = "none",
392392
highlight_modified = "none",
393393
highlight_bookmarks = "none",
@@ -644,6 +644,7 @@ local ACCEPTED_STRINGS = {
644644
highlight_opened_files = { "none", "icon", "name", "all" },
645645
highlight_modified = { "none", "icon", "name", "all" },
646646
highlight_bookmarks = { "none", "icon", "name", "all" },
647+
highlight_diagnostics = { "none", "icon", "name", "all" },
647648
highlight_clipboard = { "none", "icon", "name", "all" },
648649
icons = {
649650
git_placement = { "before", "after", "signcolumn" },

lua/nvim-tree/colors.lua

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,103 @@
11
local M = {}
22

3+
-- nvim-tree default highlight group links
4+
local DEFAULT_LINKS = {
5+
-- File Text
6+
NvimTreeFolderName = "Directory",
7+
NvimTreeEmptyFolderName = "Directory",
8+
NvimTreeOpenedFolderName = "Directory",
9+
NvimTreeSymlinkFolderName = "Directory",
10+
11+
-- Folder Text
12+
NvimTreeOpenedFileIcon = "NvimTreeOpenedFile",
13+
NvimTreeOpenedFolderIcon = "NvimTreeFolderIcon",
14+
NvimTreeClosedFolderIcon = "NvimTreeFolderIcon",
15+
16+
-- Standard
17+
NvimTreeNormal = "Normal",
18+
NvimTreeNormalFloat = "NormalFloat",
19+
NvimTreeNormalNC = "NvimTreeNormal",
20+
NvimTreeLineNr = "LineNr",
21+
NvimTreeWinSeparator = "WinSeparator",
22+
NvimTreeEndOfBuffer = "EndOfBuffer",
23+
NvimTreePopup = "Normal",
24+
NvimTreeSignColumn = "NvimTreeNormal",
25+
NvimTreeCursorLine = "CursorLine",
26+
NvimTreeCursorColumn = "CursorColumn",
27+
NvimTreeCursorLineNr = "CursorLineNr",
28+
NvimTreeStatusLine = "StatusLine",
29+
NvimTreeStatusLineNC = "StatusLineNC",
30+
31+
-- Clipboard
32+
NvimTreeCutHL = "SpellBad",
33+
NvimTreeCopiedHL = "SpellRare",
34+
35+
-- Bookmark Highlight
36+
NvimTreeBookmarkHL = "SpellLocal",
37+
38+
-- Git Icon
39+
NvimTreeGitIgnored = "Comment",
40+
41+
-- Git File Text
42+
NvimTreeFileDirty = "NvimTreeGitDirty",
43+
NvimTreeFileStaged = "NvimTreeGitStaged",
44+
NvimTreeFileMerge = "NvimTreeGitMerge",
45+
NvimTreeFileRenamed = "NvimTreeGitRenamed",
46+
NvimTreeFileNew = "NvimTreeGitNew",
47+
NvimTreeFileDeleted = "NvimTreeGitDeleted",
48+
NvimTreeFileIgnored = "NvimTreeGitIgnored",
49+
50+
-- Git Folder Text
51+
NvimTreeFolderDirty = "NvimTreeFileDirty",
52+
NvimTreeFolderStaged = "NvimTreeFileStaged",
53+
NvimTreeFolderMerge = "NvimTreeFileMerge",
54+
NvimTreeFolderRenamed = "NvimTreeFileRenamed",
55+
NvimTreeFolderNew = "NvimTreeFileNew",
56+
NvimTreeFolderDeleted = "NvimTreeFileDeleted",
57+
NvimTreeFolderIgnored = "NvimTreeFileIgnored",
58+
59+
-- Diagnostics Icon
60+
NvimTreeDiagnosticErrorIcon = "DiagnosticError",
61+
NvimTreeDiagnosticWarnIcon = "DiagnosticWarn",
62+
NvimTreeDiagnosticInfoIcon = "DiagnosticInfo",
63+
NvimTreeDiagnosticHintIcon = "DiagnosticHint",
64+
65+
-- Diagnostics File Highlight
66+
NvimTreeDiagnosticErrorFileHL = "DiagnosticUnderlineError",
67+
NvimTreeDiagnosticWarnFileHL = "DiagnosticUnderlineWarn",
68+
NvimTreeDiagnosticInfoFileHL = "DiagnosticUnderlineInfo",
69+
NvimTreeDiagnosticHintFileHL = "DiagnosticUnderlineHint",
70+
71+
-- Diagnostics Folder Highlight
72+
NvimTreeDiagnosticErrorFolderHL = "DiagnosticUnderlineError",
73+
NvimTreeDiagnosticWarnFolderHL = "DiagnosticUnderlineWarn",
74+
NvimTreeDiagnosticInfoFolderHL = "DiagnosticUnderlineInfo",
75+
NvimTreeDiagnosticHintFolderHL = "DiagnosticUnderlineHint",
76+
}
77+
78+
-- nvim-tree highlight groups to legacy
79+
local LEGACY_LINKS = {
80+
NvimTreeDiagnosticErrorIcon = "NvimTreeLspDiagnosticsError",
81+
NvimTreeDiagnosticWarnIcon = "NvimTreeLspDiagnosticsWarning",
82+
NvimTreeDiagnosticInfoIcon = "NvimTreeLspDiagnosticsInformation",
83+
NvimTreeDiagnosticHintIcon = "NvimTreeLspDiagnosticsHint",
84+
NvimTreeDiagnosticErrorFileHL = "NvimTreeLspDiagnosticsErrorText",
85+
NvimTreeDiagnosticWarnFileHL = "NvimTreeLspDiagnosticsWarningText",
86+
NvimTreeDiagnosticInfoFileHL = "NvimTreeLspDiagnosticsInformationText",
87+
NvimTreeDiagnosticHintFileHL = "NvimTreeLspDiagnosticsHintText",
88+
NvimTreeDiagnosticErrorFolderHL = "NvimTreeLspDiagnosticsErrorFolderText",
89+
NvimTreeDiagnosticWarnFolderHL = "NvimTreeLspDiagnosticsWarningFolderText",
90+
NvimTreeDiagnosticInfoFolderHL = "NvimTreeLspDiagnosticsInformationFolderText",
91+
NvimTreeDiagnosticHintFolderHL = "NvimTreeLspDiagnosticsHintFolderText",
92+
}
93+
394
local function get_color_from_hl(hl_name, fallback)
495
local id = vim.api.nvim_get_hl_id_by_name(hl_name)
596
if not id then
697
return fallback
798
end
899

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

60-
local function get_links()
61-
return {
62-
FolderName = "Directory",
63-
EmptyFolderName = "Directory",
64-
OpenedFolderName = "Directory",
65-
SymlinkFolderName = "Directory",
66-
OpenedFolderIcon = "NvimTreeFolderIcon",
67-
ClosedFolderIcon = "NvimTreeFolderIcon",
68-
OpenedFileIcon = "NvimTreeOpenedFile",
69-
Normal = "Normal",
70-
NormalFloat = "NormalFloat",
71-
NormalNC = "NvimTreeNormal",
72-
EndOfBuffer = "EndOfBuffer",
73-
CursorLineNr = "CursorLineNr",
74-
LineNr = "LineNr",
75-
CursorLine = "CursorLine",
76-
WinSeparator = "WinSeparator",
77-
CursorColumn = "CursorColumn",
78-
FileDirty = "NvimTreeGitDirty",
79-
FileNew = "NvimTreeGitNew",
80-
FileRenamed = "NvimTreeGitRenamed",
81-
FileMerge = "NvimTreeGitMerge",
82-
FileStaged = "NvimTreeGitStaged",
83-
FileDeleted = "NvimTreeGitDeleted",
84-
FileIgnored = "NvimTreeGitIgnored",
85-
FolderDirty = "NvimTreeFileDirty",
86-
FolderNew = "NvimTreeFileNew",
87-
FolderRenamed = "NvimTreeFileRenamed",
88-
FolderMerge = "NvimTreeFileMerge",
89-
FolderStaged = "NvimTreeFileStaged",
90-
FolderDeleted = "NvimTreeFileDeleted",
91-
FolderIgnored = "NvimTreeFileIgnored",
92-
LspDiagnosticsError = "DiagnosticError",
93-
LspDiagnosticsWarning = "DiagnosticWarn",
94-
LspDiagnosticsInformation = "DiagnosticInfo",
95-
LspDiagnosticsHint = "DiagnosticHint",
96-
LspDiagnosticsErrorText = "NvimTreeLspDiagnosticsError",
97-
LspDiagnosticsWarningText = "NvimTreeLspDiagnosticsWarning",
98-
LspDiagnosticsInformationText = "NvimTreeLspDiagnosticsInformation",
99-
LspDiagnosticsHintText = "NvimTreeLspDiagnosticsHintFile",
100-
LspDiagnosticsErrorFolderText = "NvimTreeLspDiagnosticsErrorText",
101-
LspDiagnosticsWarningFolderText = "NvimTreeLspDiagnosticsWarningText",
102-
LspDiagnosticsInformationFolderText = "NvimTreeLspDiagnosticsInformationText",
103-
LspDiagnosticsHintFolderText = "NvimTreeLspDiagnosticsHintFileText",
104-
Popup = "Normal",
105-
GitIgnored = "Comment",
106-
StatusLine = "StatusLine",
107-
StatusLineNC = "StatusLineNC",
108-
SignColumn = "NvimTreeNormal",
109-
CutHL = "SpellBad",
110-
CopiedHL = "SpellRare",
111-
BookmarkHL = "SpellLocal",
112-
}
113-
end
114-
115152
function M.setup()
116153
local highlight_groups = get_hl_groups()
117154
for k, d in pairs(highlight_groups) do
@@ -121,9 +158,18 @@ function M.setup()
121158
vim.api.nvim_command("hi def NvimTree" .. k .. gui .. fg .. bg)
122159
end
123160

124-
local links = get_links()
125-
for k, d in pairs(links) do
126-
vim.api.nvim_command("hi def link NvimTree" .. k .. " " .. d)
161+
-- hard link override when legacy only is present
162+
for from, to in pairs(LEGACY_LINKS) do
163+
local hl_from = vim.api.nvim_get_hl(0, { name = from })
164+
local hl_to = vim.api.nvim_get_hl(0, { name = to })
165+
if vim.tbl_isempty(hl_from) and not vim.tbl_isempty(hl_to) then
166+
vim.api.nvim_command("hi link " .. from .. " " .. to)
167+
end
168+
end
169+
170+
-- default links
171+
for from, to in pairs(DEFAULT_LINKS) do
172+
vim.api.nvim_command("hi def link " .. from .. " " .. to)
127173
end
128174
end
129175

lua/nvim-tree/legacy.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ local function refactored(opts)
4141

4242
-- 2023/08/26
4343
utils.move_missing_val(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true)
44+
45+
-- 2023/10/08
46+
if type(opts.renderer) == "table" and type(opts.renderer.highlight_diagnostics) == "boolean" then
47+
if opts.renderer.highlight_diagnostics then
48+
opts.renderer.highlight_diagnostics = "name"
49+
else
50+
opts.renderer.highlight_diagnostics = "none"
51+
end
52+
end
4453
end
4554

4655
local function deprecated(opts)

0 commit comments

Comments
 (0)