1
1
local M = {}
2
2
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
+
3
94
local function get_color_from_hl (hl_name , fallback )
4
95
local id = vim .api .nvim_get_hl_id_by_name (hl_name )
5
96
if not id then
6
97
return fallback
7
98
end
8
99
100
+ -- TODO this is unreachable as nvim_get_hl_id_by_name returns a new ID if not present
9
101
local foreground = vim .fn .synIDattr (vim .fn .synIDtrans (id ), " fg" )
10
102
if not foreground or foreground == " " then
11
103
return fallback
@@ -57,61 +149,6 @@ local function get_hl_groups()
57
149
}
58
150
end
59
151
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
-
115
152
function M .setup ()
116
153
local highlight_groups = get_hl_groups ()
117
154
for k , d in pairs (highlight_groups ) do
@@ -121,9 +158,18 @@ function M.setup()
121
158
vim .api .nvim_command (" hi def NvimTree" .. k .. gui .. fg .. bg )
122
159
end
123
160
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 )
127
173
end
128
174
end
129
175
0 commit comments