feat: add new treesitter highlights (#217)

* feat: add WinBar and WinBarNC

* feat: add new treesitter highlight groups

* perf: parse necessary values upfront

This commit no longer parses each highlight group, but rather user
config values only.

* fix: titles are no longer dynamically coloured

Closes #216 #218 #219
This commit is contained in:
not 2024-01-26 14:12:54 -06:00 committed by GitHub
commit bf00df18af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 292 additions and 157 deletions

View file

@ -5,7 +5,11 @@ local function set_highlights()
local utilities = require("rose-pine.utilities")
local palette = require("rose-pine.palette")
local styles = config.options.styles
local groups = config.options.groups
local groups = {}
for group, color in pairs(config.options.groups) do
groups[group] = utilities.parse_color(color)
end
local function make_border(fg)
fg = fg or groups.border
@ -16,12 +20,64 @@ local function set_highlights()
}
end
local function make_title(fg)
fg = fg or palette.foam
return { fg = styles.bold and palette.text or fg, bold = styles.bold }
end
local highlights = {}
local legacy_highlights = {
["@attribute.diff"] = { fg = palette.gold },
["@boolean"] = { link = "Boolean" },
["@class"] = { fg = palette.foam },
["@conditional"] = { link = "Conditional" },
["@field"] = { fg = palette.foam },
["@include"] = { link = "Include" },
["@interface"] = { fg = palette.foam },
["@macro"] = { link = "Macro" },
["@method"] = { fg = palette.rose },
["@namespace"] = { link = "Include" },
["@number"] = { link = "Number" },
["@parameter"] = { fg = palette.iris, italic = styles.italic },
["@preproc"] = { link = "PreProc" },
["@punctuation"] = { fg = palette.subtle },
["@punctuation.bracket"] = { link = "@punctuation" },
["@punctuation.delimiter"] = { link = "@punctuation" },
["@punctuation.special"] = { link = "@punctuation" },
["@regexp"] = { link = "String" },
["@repeat"] = { link = "Repeat" },
["@storageclass"] = { link = "StorageClass" },
["@symbol"] = { link = "Identifier" },
["@text"] = { fg = palette.text },
["@text.danger"] = { fg = groups.error },
["@text.diff.add"] = { fg = groups.git_add, bg = groups.git_add, blend = 20 },
["@text.diff.delete"] = { fg = groups.git_delete, bg = groups.git_delete, blend = 20 },
["@text.emphasis"] = { italic = styles.italic },
["@text.environment"] = { link = "Macro" },
["@text.environment.name"] = { link = "Type" },
["@text.math"] = { link = "Special" },
["@text.note"] = { link = "SpecialComment" },
["@text.strike"] = { strikethrough = true },
["@text.strong"] = { bold = styles.bold },
["@text.title"] = { link = "Title" },
["@text.title.1.markdown"] = { link = "markdownH1" },
["@text.title.1.marker.markdown"] = { link = "markdownH1Delimiter" },
["@text.title.2.markdown"] = { link = "markdownH2" },
["@text.title.2.marker.markdown"] = { link = "markdownH2Delimiter" },
["@text.title.3.markdown"] = { link = "markdownH3" },
["@text.title.3.marker.markdown"] = { link = "markdownH3Delimiter" },
["@text.title.4.markdown"] = { link = "markdownH4" },
["@text.title.4.marker.markdown"] = { link = "markdownH4Delimiter" },
["@text.title.5.markdown"] = { link = "markdownH5" },
["@text.title.5.marker.markdown"] = { link = "markdownH5Delimiter" },
["@text.title.6.markdown"] = { link = "markdownH6" },
["@text.title.6.marker.markdown"] = { link = "markdownH6Delimiter" },
["@text.underline"] = { underline = true },
["@text.uri"] = { fg = groups.link },
["@text.warning"] = { fg = groups.warn },
["@todo"] = { link = "Todo" },
local highlights = {
-- lukas-reineke/indent-blankline.nvim
IndentBlanklineChar = { fg = palette.muted, nocombine = true },
IndentBlanklineSpaceChar = { fg = palette.muted, nocombine = true },
IndentBlanklineSpaceCharBlankline = { fg = palette.muted, nocombine = true },
}
local default_highlights = {
ColorColumn = { bg = palette.surface },
Conceal = { bg = "NONE" },
CurSearch = { fg = palette.base, bg = palette.gold },
@ -39,7 +95,7 @@ local function set_highlights()
diffAdded = { link = "DiffAdd" },
diffChanged = { link = "DiffChange" },
diffRemoved = { link = "DiffDelete" },
Directory = make_title(),
Directory = { fg = palette.foam, bold = styles.bold },
-- EndOfBuffer = {},
ErrorMsg = { fg = groups.error, bold = styles.bold },
FloatBorder = make_border(),
@ -85,13 +141,15 @@ local function set_highlights()
TabLine = { fg = palette.subtle, bg = groups.panel },
TabLineFill = { bg = groups.panel },
TabLineSel = { fg = palette.text, bg = palette.overlay, bold = styles.bold },
Title = make_title(),
Title = { fg = palette.foam, bold = styles.bold },
VertSplit = { fg = groups.border },
Visual = { bg = palette.highlight_med },
-- VisualNOS = {},
WarningMsg = { fg = groups.warn, bold = styles.bold },
-- Whitespace = {},
WildMenu = { link = "IncSearch" },
WinBar = { fg = palette.subtle, bg = groups.panel },
WinBarNC = { fg = palette.muted, bg = groups.panel, blend = 60 },
WinSeparator = { fg = groups.border },
DiagnosticError = { fg = groups.error },
@ -155,7 +213,7 @@ local function set_highlights()
String = { fg = palette.gold },
Structure = { fg = palette.foam },
Tag = { fg = palette.foam },
Todo = { fg = palette.iris, bg = palette.iris, blend = 20 },
Todo = { fg = palette.rose, bg = palette.rose, blend = 20 },
Type = { fg = palette.foam },
TypeDef = { link = "Type" },
Underlined = { fg = palette.iris, underline = true },
@ -179,17 +237,17 @@ local function set_highlights()
htmlTagName = { fg = palette.foam },
markdownDelimiter = { fg = palette.subtle },
markdownH1 = { fg = groups.headings.h1, bold = styles.bold },
markdownH1 = { fg = groups.h1, bold = styles.bold },
markdownH1Delimiter = { link = "markdownH1" },
markdownH2 = { fg = groups.headings.h2, bold = styles.bold },
markdownH2 = { fg = groups.h2, bold = styles.bold },
markdownH2Delimiter = { link = "markdownH2" },
markdownH3 = { fg = groups.headings.h3, bold = styles.bold },
markdownH3 = { fg = groups.h3, bold = styles.bold },
markdownH3Delimiter = { link = "markdownH3" },
markdownH4 = { fg = groups.headings.h4, bold = styles.bold },
markdownH4 = { fg = groups.h4, bold = styles.bold },
markdownH4Delimiter = { link = "markdownH4" },
markdownH5 = { fg = groups.headings.h5, bold = styles.bold },
markdownH5 = { fg = groups.h5, bold = styles.bold },
markdownH5Delimiter = { link = "markdownH5" },
markdownH6 = { fg = groups.headings.h6, bold = styles.bold },
markdownH6 = { fg = groups.h6, bold = styles.bold },
markdownH6Delimiter = { link = "markdownH6" },
markdownLinkText = { link = "markdownUrl" },
markdownUrl = { fg = groups.link, sp = groups.link, underline = true },
@ -207,93 +265,144 @@ local function set_highlights()
mkdRule = { fg = palette.subtle },
mkdURL = { link = "markdownUrl" },
["@attribute.diff"] = { fg = palette.gold },
["@boolean"] = { link = "Boolean" },
--- Identifiers
["@variable"] = { fg = palette.text, italic = styles.italic },
["@variable.builtin"] = { fg = palette.text, bold = styles.bold },
["@variable.parameter"] = { fg = palette.iris, italic = styles.italic },
["@variable.member"] = { fg = palette.foam },
["@constant"] = { fg = palette.gold },
["@constant.builtin"] = { fg = palette.gold, bold = styles.bold },
["@constant.macro"] = { fg = palette.gold },
["@module"] = { fg = palette.text },
["@module.builtin"] = { fg = palette.text, bold = styles.bold },
["@label"] = { link = "Label" },
--- Literals
["@string"] = { link = "String" },
-- ["@string.documentation"] = {},
["@string.regexp"] = { fg = palette.iris },
["@string.escape"] = { fg = palette.pine },
["@string.special"] = { link = "String" },
["@string.special.symbol"] = { link = "Identifier" },
["@string.special.url"] = { fg = groups.link },
-- ["@string.special.path"] = {},
["@character"] = { link = "Character" },
["@character.special"] = { link = "Character" },
["@class"] = { fg = palette.foam },
["@comment"] = { link = "Comment" },
["@conditional"] = { link = "Conditional" },
["@constant"] = { link = "Constant" },
["@constant.builtin"] = { fg = palette.love },
["@constant.macro"] = { link = "Constant" },
["@constructor"] = { fg = palette.foam },
["@field"] = { fg = palette.foam },
["@function"] = { link = "Function" },
["@function.builtin"] = { fg = palette.love },
["@boolean"] = { link = "Boolean" },
["@number"] = { link = "Number" },
["@number.float"] = { link = "Number" },
--- Types
["@type"] = { fg = palette.foam },
["@type.builtin"] = { fg = palette.foam, bold = styles.bold },
-- ["@type.definition"] = {},
-- ["@type.qualifier"] = {},
-- ["@attribute"] = {},
["@property"] = { fg = palette.foam, italic = styles.italic },
--- Functions
["@function"] = { fg = palette.rose },
["@function.builtin"] = { fg = palette.rose, bold = styles.bold },
-- ["@function.call"] = {},
["@function.macro"] = { link = "Function" },
["@include"] = { link = "Include" },
["@interface"] = { fg = palette.foam },
["@function.method"] = { fg = palette.rose },
["@function.method.call"] = { fg = palette.iris },
["@constructor"] = { fg = palette.foam },
["@operator"] = { link = "Operator" },
--- Keywords
["@keyword"] = { link = "Keyword" },
-- ["@keyword.coroutine"] = {},
-- ["@keyword.function"] = {},
["@keyword.operator"] = { fg = palette.subtle },
["@label"] = { link = "Label" },
["@keyword.import"] = { fg = palette.pine },
["@keyword.storage"] = { fg = palette.foam },
["@keyword.repeat"] = { fg = palette.pine },
["@keyword.return"] = { fg = palette.pine },
["@keyword.debug"] = { fg = palette.rose },
["@keyword.exception"] = { fg = palette.pine },
["@keyword.conditional"] = { fg = palette.pine },
["@keyword.conditional.ternary"] = { fg = palette.pine },
["@keyword.directive"] = { fg = palette.iris },
["@keyword.directive.define"] = { fg = palette.iris },
--- Punctuation
["@punctuation.delimiter"] = { fg = palette.subtle },
["@punctuation.bracket"] = { fg = palette.subtle },
["@punctuation.special"] = { fg = palette.subtle },
--- Comments
["@comment"] = { link = "Comment" },
-- ["@comment.documentation"] = {},
["@comment.error"] = { fg = groups.error },
["@comment.warning"] = { fg = groups.warn },
["@comment.todo"] = { fg = groups.todo, bg = groups.todo, blend = 20 },
["@comment.hint"] = { fg = groups.hint, bg = groups.hint, blend = 20 },
["@comment.info"] = { fg = groups.info, bg = groups.info, blend = 20 },
["@comment.note"] = { fg = groups.note, bg = groups.note, blend = 20 },
--- Markup
["@markup.strong"] = { bold = styles.bold },
["@markup.italic"] = { italic = styles.italic },
["@markup.strikethrough"] = { strikethrough = true },
["@markup.underline"] = { underline = true },
["@markup.heading"] = { fg = palette.foam, bold = styles.bold },
["@markup.quote"] = { fg = palette.subtle },
["@markup.math"] = { link = "Special" },
["@markup.environment"] = { link = "Macro" },
["@markup.environment.name"] = { link = "@type" },
-- ["@markup.link"] = {},
["@markup.link.label"] = { fg = palette.text },
["@markup.link.url"] = { fg = groups.link },
-- ["@markup.raw"] = { bg = palette.surface },
-- ["@markup.raw.block"] = { bg = palette.surface },
["@markup.list"] = { fg = palette.text },
["@markup.list.checked"] = { fg = palette.foam, bg = palette.foam, blend = 10 },
["@markup.list.unchecked"] = { fg = palette.text },
["@diff.plus"] = { fg = groups.git_add, bg = groups.git_add, blend = 20 },
["@diff.minus"] = { fg = groups.git_delete, bg = groups.git_delete, blend = 20 },
["@diff.delta"] = { bg = groups.git_change, blend = 20 },
["@tag"] = { link = "Tag" },
["@tag.attribute"] = { fg = palette.iris },
["@tag.delimiter"] = { fg = palette.subtle },
--- Non-highlighting captures
-- ["@none"] = {},
["@conceal"] = { link = "Conceal" },
-- ["@spell"] = {},
-- ["@nospell"] = {},
--- Semantic
["@lsp.type.comment"] = {},
["@lsp.type.enum"] = { link = "Type" },
["@lsp.type.enum"] = { link = "@type" },
["@lsp.type.interface"] = { link = "@interface" },
["@lsp.type.keyword"] = { link = "Keyword" },
["@lsp.type.keyword"] = { link = "@keyword" },
["@lsp.type.namespace"] = { link = "@namespace" },
["@lsp.type.parameter"] = { link = "@parameter" },
["@lsp.type.property"] = { link = "@property" },
["@lsp.type.variable"] = {},
["@lsp.typemod.function.defaultLibrary"] = { link = "Special" },
["@lsp.typemod.operator.injected"] = { link = "Operator" },
["@lsp.typemod.string.injected"] = { link = "String" },
["@lsp.typemod.function.defaultLibrary"] = { link = "@function.builtin" },
["@lsp.typemod.operator.injected"] = { link = "@operator" },
["@lsp.typemod.string.injected"] = { link = "@string" },
["@lsp.typemod.variable.defaultLibrary"] = { link = "@variable.builtin" },
["@lsp.typemod.variable.injected"] = { link = "@variable" },
["@macro"] = { link = "Macro" },
["@method"] = { fg = palette.rose },
["@namespace"] = { link = "Include" },
["@number"] = { link = "Number" },
["@operator"] = { link = "Operator" },
["@parameter"] = { fg = palette.iris, italic = styles.italic },
["@preproc"] = { link = "PreProc" },
["@property"] = { fg = palette.foam, italic = styles.italic },
["@punctuation"] = { fg = palette.subtle },
["@punctuation.bracket"] = { link = "@punctuation" },
["@punctuation.delimiter"] = { link = "@punctuation" },
["@punctuation.special"] = { link = "@punctuation" },
["@regexp"] = { link = "String" },
["@repeat"] = { link = "Repeat" },
["@storageclass"] = { link = "StorageClass" },
["@string"] = { link = "String" },
["@string.escape"] = { fg = palette.pine },
["@string.special"] = { link = "String" },
["@symbol"] = { link = "Identifier" },
["@tag"] = { link = "Tag" },
["@tag.attribute"] = { fg = palette.iris },
["@tag.delimiter"] = { fg = palette.subtle },
["@text"] = { fg = palette.text },
["@text.danger"] = { fg = groups.error },
["@text.diff.add"] = { fg = groups.git_add, bg = groups.git_add, blend = 20 },
["@text.diff.delete"] = { fg = groups.git_delete, bg = groups.git_delete, blend = 20 },
["@text.emphasis"] = { italic = styles.italic },
["@text.environment"] = { link = "Macro" },
["@text.environment.name"] = { link = "Type" },
["@text.math"] = { link = "Special" },
["@text.note"] = { link = "SpecialComment" },
["@text.strike"] = { strikethrough = true },
["@text.strong"] = { bold = styles.bold },
["@text.title"] = { link = "Title" },
["@text.title.1.markdown"] = { link = "markdownH1" },
["@text.title.1.marker.markdown"] = { link = "markdownH1Delimiter" },
["@text.title.2.markdown"] = { link = "markdownH2" },
["@text.title.2.marker.markdown"] = { link = "markdownH2Delimiter" },
["@text.title.3.markdown"] = { link = "markdownH3" },
["@text.title.3.marker.markdown"] = { link = "markdownH3Delimiter" },
["@text.title.4.markdown"] = { link = "markdownH4" },
["@text.title.4.marker.markdown"] = { link = "markdownH4Delimiter" },
["@text.title.5.markdown"] = { link = "markdownH5" },
["@text.title.5.marker.markdown"] = { link = "markdownH5Delimiter" },
["@text.title.6.markdown"] = { link = "markdownH6" },
["@text.title.6.marker.markdown"] = { link = "markdownH6Delimiter" },
["@text.underline"] = { underline = true },
["@text.uri"] = { fg = groups.link },
["@text.warning"] = { fg = groups.warn },
["@todo"] = { link = "Todo" },
["@type"] = { link = "Type" },
["@variable"] = { fg = palette.text, italic = styles.italic },
["@variable.builtin"] = { fg = palette.love },
--- Plugins
-- romgrk/barbar.nvim
BufferCurrent = { fg = palette.text, bg = palette.overlay },
BufferCurrentIndex = { fg = palette.text, bg = palette.overlay },
@ -347,7 +456,7 @@ local function set_highlights()
NvimTreeNormal = { link = "Normal" },
NvimTreeOpenedFile = { fg = palette.text, bg = palette.overlay },
NvimTreeOpenedFolderName = { link = "NvimTreeFolderName" },
NvimTreeRootFolder = make_title(),
NvimTreeRootFolder = { fg = palette.foam, bold = styles.bold },
NvimTreeSpecialFile = { link = "NvimTreeNormal" },
NvimTreeWindowPicker = { link = "StatusLineTerm" },
@ -377,11 +486,6 @@ local function set_highlights()
IblScope = { fg = palette.foam },
IblWhitespace = { fg = palette.overlay },
-- for legacy usage
IndentBlanklineChar = { fg = palette.muted, nocombine = true },
IndentBlanklineSpaceChar = { fg = palette.muted, nocombine = true },
IndentBlanklineSpaceCharBlankline = { fg = palette.muted, nocombine = true },
-- hrsh7th/nvim-cmp
CmpItemAbbr = { fg = palette.subtle },
CmpItemAbbrDeprecated = { fg = palette.subtle, strikethrough = true },
@ -438,7 +542,7 @@ local function set_highlights()
NeorgHeading5Title = { link = "markdownH5" },
NeorgHeading6Prefix = { link = "markdownH6Delimiter" },
NeorgHeading6Title = { link = "markdownH6" },
NeorgMarkerTitle = make_title(),
NeorgMarkerTitle = { fg = palette.foam, bold = styles.bold },
-- tami5/lspsaga.nvim (fork of glepnir/lspsaga.nvim)
DefinitionCount = { fg = palette.rose },
@ -453,7 +557,7 @@ local function set_highlights()
LspSagaCodeActionTruncateLine = { link = "LspSagaCodeActionBorder" },
LspSagaDefPreviewBorder = make_border(),
LspSagaDiagnosticBorder = make_border(palette.gold),
LspSagaDiagnosticHeader = make_title(),
LspSagaDiagnosticHeader = { fg = palette.foam, bold = styles.bold },
LspSagaDiagnosticTruncateLine = { link = "LspSagaDiagnosticBorder" },
LspSagaDocTruncateLine = { link = "LspSagaHoverBorder" },
LspSagaFinderSelection = { fg = palette.gold },
@ -497,11 +601,11 @@ local function set_highlights()
TelescopePromptPrefix = { fg = palette.subtle },
TelescopeSelection = { fg = palette.text, bg = palette.overlay },
TelescopeSelectionCaret = { fg = palette.rose, bg = palette.overlay },
TelescopeTitle = make_title(),
TelescopeTitle = { fg = palette.foam, bold = styles.bold },
-- ibhagwan/fzf-lua
FzfLuaNormal = { link = "NormalFloat" },
FwzfLuaTitle = make_title(),
FwzfLuaTitle = { fg = palette.foam, bold = styles.bold },
FzfLuaBorder = make_border(),
FzfLuaHeaderText = { fg = palette.love },
FzfLuaHeaderBind = { fg = palette.rose },
@ -606,7 +710,6 @@ local function set_highlights()
-- github/copilot.vim
CopilotSuggestion = { fg = palette.muted, italic = styles.italic },
}
local transparency_highlights = {
DiagnosticVirtualTextError = { fg = groups.error },
DiagnosticVirtualTextHint = { fg = groups.hint },
@ -626,6 +729,9 @@ local function set_highlights()
TabLineFill = { bg = "NONE" },
TabLineSel = { fg = palette.text, bg = "NONE", bold = styles.bold },
-- ["@markup.raw"] = { bg = "none" },
-- ["@markup.raw.block"] = { bg = "none" },
TelescopeNormal = { fg = palette.subtle, bg = "NONE" },
TelescopePromptNormal = { fg = palette.text, bg = "NONE" },
TelescopeSelection = { fg = palette.text, bg = "NONE", bold = styles.bold },
@ -643,31 +749,57 @@ local function set_highlights()
MiniPickPrompt = { bg = "NONE", bold = styles.bold },
}
if config.options.enable.legacy_highlights then
for group, highlight in pairs(legacy_highlights) do
highlights[group] = highlight
end
end
for group, highlight in pairs(default_highlights) do
highlights[group] = highlight
end
if styles.transparency then
for group, highlight in pairs(transparency_highlights) do
highlights[group] = highlight
end
end
for group, options in pairs(config.options.highlight_groups) do
local default_opts = highlights[group] or {}
-- Reconcile highlights with config
if config.options.highlight_groups ~= nil and next(config.options.highlight_groups) ~= nil then
for group, highlight in pairs(config.options.highlight_groups) do
local existing = highlights[group] or {}
local parsed = vim.tbl_extend("force", {}, highlight)
if (options.inherit == nil or options.inherit) and default_opts ~= nil then -- On merge.
options.inherit = nil -- Don't add this key to the highlight_group after merge.
highlights[group] = vim.tbl_extend("force", default_opts, options)
else -- On overwrite.
options.inherit = nil -- Don't add this key to the highlight_group.
highlights[group] = options
if highlight.fg ~= nil then
parsed.fg = utilities.parse_color(highlight.fg) or highlight.fg
end
if highlight.bg ~= nil then
parsed.bg = utilities.parse_color(highlight.bg) or highlight.bg
end
if highlight.sp ~= nil then
parsed.sp = utilities.parse_color(highlight.sp) or highlight.sp
end
if (highlight.inherit == nil or highlight.inherit) and existing ~= nil then
highlight.inherit = nil
highlights[group] = vim.tbl_extend("force", existing, parsed)
else
highlight.inherit = nil
highlights[group] = parsed
end
end
highlights[group] = vim.tbl_extend("force", highlights[group] or {}, options)
end
for group, highlight in pairs(highlights) do
config.options.before_highlight(group, highlight, palette)
utilities.highlight(group, highlight)
if config.options.before_highlight ~= nil then
config.options.before_highlight(group, highlight, palette)
end
if highlight.blend ~= nil and (highlight.blend >= 0 and highlight.blend <= 100) and highlight.bg ~= nil then
highlight.bg = utilities.blend(highlight.bg, highlight.blend_on or palette.base, highlight.blend / 100)
end
vim.api.nvim_set_hl(0, group, highlight)
end
--- Terminal
if config.options.enable.terminal then
vim.g.terminal_color_0 = palette.overlay -- black
vim.g.terminal_color_8 = palette.subtle -- bright black