diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 9f1721e6935..a93e0e946c0 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -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| @@ -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", @@ -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 @@ -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* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index d2552b84a53..918926b2e96 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -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", @@ -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" }, diff --git a/lua/nvim-tree/colors.lua b/lua/nvim-tree/colors.lua index 7487c05e0eb..517f4736b53 100644 --- a/lua/nvim-tree/colors.lua +++ b/lua/nvim-tree/colors.lua @@ -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 @@ -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 @@ -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 diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 6f8c60c7317..2d6dd9f9582 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -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) diff --git a/lua/nvim-tree/renderer/components/diagnostics.lua b/lua/nvim-tree/renderer/components/diagnostics.lua index 5475aa5c5fe..958172ce68a 100644 --- a/lua/nvim-tree/renderer/components/diagnostics.lua +++ b/lua/nvim-tree/renderer/components/diagnostics.lua @@ -1,10 +1,15 @@ local HL_POSITION = require("nvim-tree.enum").HL_POSITION local M = { - HS_FILE = {}, - HS_FOLDER = {}, - ICON = {}, - hl_pos = HL_POSITION.none, + -- highlight strings for the icons + HS_ICON = {}, + + -- highlight groups for HL + HG_FILE = {}, + HG_FOLDER = {}, + + -- position for HL + HL_POS = HL_POSITION.none, } ---Diagnostics text highlight group when highlight_diagnostics. @@ -12,19 +17,19 @@ local M = { ---@return HL_POSITION position none when no status ---@return string|nil group only when status function M.get_highlight(node) - if not node or M.hl_pos == HL_POSITION.none then + if not node or M.HL_POS == HL_POSITION.none then return HL_POSITION.none, nil end local group if node.nodes then - group = M.HS_FOLDER[node.diag_status] + group = M.HG_FOLDER[node.diag_status] else - group = M.HS_FILE[node.diag_status] + group = M.HG_FILE[node.diag_status] end if group then - return M.hl_pos, group + return M.HL_POS, group else return HL_POSITION.none, nil end @@ -35,7 +40,7 @@ end ---@return HighlightedString|nil modified icon function M.get_icon(node) if node and M.config.diagnostics.enable and M.config.renderer.icons.show.diagnostics then - return M.ICON[node.diag_status] + return M.HS_ICON[node.diag_status] end end @@ -46,40 +51,38 @@ function M.setup(opts) } if opts.diagnostics.enable and opts.renderer.highlight_diagnostics then - -- TODO add a HL_POSITION - -- M.hl_pos = HL_POSITION[opts.renderer.highlight_diagnostics] - M.hl_pos = HL_POSITION.name + M.HL_POS = HL_POSITION[opts.renderer.highlight_diagnostics] end - M.HS_FILE[vim.diagnostic.severity.ERROR] = "NvimTreeLspDiagnosticsErrorText" - M.HS_FILE[vim.diagnostic.severity.WARN] = "NvimTreeLspDiagnosticsWarningText" - M.HS_FILE[vim.diagnostic.severity.INFO] = "NvimTreeLspDiagnosticsInfoText" - M.HS_FILE[vim.diagnostic.severity.HINT] = "NvimTreeLspDiagnosticsHintText" + M.HG_FILE[vim.diagnostic.severity.ERROR] = "NvimTreeDiagnosticErrorFileHL" + M.HG_FILE[vim.diagnostic.severity.WARN] = "NvimTreeDiagnosticWarningFileHL" + M.HG_FILE[vim.diagnostic.severity.INFO] = "NvimTreeDiagnosticInfoFileHL" + M.HG_FILE[vim.diagnostic.severity.HINT] = "NvimTreeDiagnosticHintFileHL" - M.HS_FOLDER[vim.diagnostic.severity.ERROR] = "NvimTreeLspDiagnosticsErrorFolderText" - M.HS_FOLDER[vim.diagnostic.severity.WARN] = "NvimTreeLspDiagnosticsWarningFolderText" - M.HS_FOLDER[vim.diagnostic.severity.INFO] = "NvimTreeLspDiagnosticsInfoFolderText" - M.HS_FOLDER[vim.diagnostic.severity.HINT] = "NvimTreeLspDiagnosticsHintFolderText" + M.HG_FOLDER[vim.diagnostic.severity.ERROR] = "NvimTreeDiagnosticErrorFolderHL" + M.HG_FOLDER[vim.diagnostic.severity.WARN] = "NvimTreeDiagnosticWarningFolderHL" + M.HG_FOLDER[vim.diagnostic.severity.INFO] = "NvimTreeDiagnosticInfoFolderHL" + M.HG_FOLDER[vim.diagnostic.severity.HINT] = "NvimTreeDiagnosticHintFolderHL" - M.ICON[vim.diagnostic.severity.ERROR] = { + M.HS_ICON[vim.diagnostic.severity.ERROR] = { str = M.config.diagnostics.icons.error, - hl = { "NvimTreeLspDiagnosticsError" }, + hl = { "NvimTreeDiagnosticErrorIcon" }, } - M.ICON[vim.diagnostic.severity.WARN] = { + M.HS_ICON[vim.diagnostic.severity.WARN] = { str = M.config.diagnostics.icons.warning, - hl = { "NvimTreeLspDiagnosticsWarning" }, + hl = { "NvimTreeDiagnosticWarningIcon" }, } - M.ICON[vim.diagnostic.severity.INFO] = { + M.HS_ICON[vim.diagnostic.severity.INFO] = { str = M.config.diagnostics.icons.info, - hl = { "NvimTreeLspDiagnosticsInfo" }, + hl = { "NvimTreeDiagnosticInfoIcon" }, } - M.ICON[vim.diagnostic.severity.HINT] = { + M.HS_ICON[vim.diagnostic.severity.HINT] = { str = M.config.diagnostics.icons.hint, - hl = { "NvimTreeLspDiagnosticsHint" }, + hl = { "NvimTreeDiagnosticHintIcon" }, } - for _, i in ipairs(M.ICON) do + for _, i in ipairs(M.HS_ICON) do vim.fn.sign_define(i.hl[1], { text = i.str, texthl = i.hl[1] }) end end