mirror of
https://github.com/rose-pine/neovim.git
synced 2025-10-15 12:38:53 +02:00
perf: parse necessary values upfront
This commit no longer parses each highlight group, but rather user config values only.
This commit is contained in:
parent
557b4faaf6
commit
03eccf56f1
4 changed files with 80 additions and 76 deletions
|
|
@ -5,7 +5,11 @@ local function set_highlights()
|
||||||
local utilities = require("rose-pine.utilities")
|
local utilities = require("rose-pine.utilities")
|
||||||
local palette = require("rose-pine.palette")
|
local palette = require("rose-pine.palette")
|
||||||
local styles = config.options.styles
|
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)
|
local function make_border(fg)
|
||||||
fg = fg or groups.border
|
fg = fg or groups.border
|
||||||
|
|
@ -16,10 +20,8 @@ local function set_highlights()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_title(fg)
|
local adaptive_title = { fg = styles.bold and palette.text or palette.foam, bold = styles.bold }
|
||||||
fg = fg or palette.foam
|
local adaptive_border = make_border()
|
||||||
return { fg = styles.bold and palette.text or fg, bold = styles.bold }
|
|
||||||
end
|
|
||||||
|
|
||||||
local highlights = {}
|
local highlights = {}
|
||||||
local legacy_highlights = {
|
local legacy_highlights = {
|
||||||
|
|
@ -96,10 +98,10 @@ local function set_highlights()
|
||||||
diffAdded = { link = "DiffAdd" },
|
diffAdded = { link = "DiffAdd" },
|
||||||
diffChanged = { link = "DiffChange" },
|
diffChanged = { link = "DiffChange" },
|
||||||
diffRemoved = { link = "DiffDelete" },
|
diffRemoved = { link = "DiffDelete" },
|
||||||
Directory = make_title(),
|
Directory = adaptive_title,
|
||||||
-- EndOfBuffer = {},
|
-- EndOfBuffer = {},
|
||||||
ErrorMsg = { fg = groups.error, bold = styles.bold },
|
ErrorMsg = { fg = groups.error, bold = styles.bold },
|
||||||
FloatBorder = make_border(),
|
FloatBorder = adaptive_border,
|
||||||
FloatTitle = { link = "Directory" },
|
FloatTitle = { link = "Directory" },
|
||||||
FoldColumn = { fg = palette.muted },
|
FoldColumn = { fg = palette.muted },
|
||||||
Folded = { fg = palette.text, bg = groups.panel },
|
Folded = { fg = palette.text, bg = groups.panel },
|
||||||
|
|
@ -142,7 +144,7 @@ local function set_highlights()
|
||||||
TabLine = { fg = palette.subtle, bg = groups.panel },
|
TabLine = { fg = palette.subtle, bg = groups.panel },
|
||||||
TabLineFill = { bg = groups.panel },
|
TabLineFill = { bg = groups.panel },
|
||||||
TabLineSel = { fg = palette.text, bg = palette.overlay, bold = styles.bold },
|
TabLineSel = { fg = palette.text, bg = palette.overlay, bold = styles.bold },
|
||||||
Title = make_title(),
|
Title = adaptive_title,
|
||||||
VertSplit = { fg = groups.border },
|
VertSplit = { fg = groups.border },
|
||||||
Visual = { bg = palette.highlight_med },
|
Visual = { bg = palette.highlight_med },
|
||||||
-- VisualNOS = {},
|
-- VisualNOS = {},
|
||||||
|
|
@ -238,17 +240,17 @@ local function set_highlights()
|
||||||
htmlTagName = { fg = palette.foam },
|
htmlTagName = { fg = palette.foam },
|
||||||
|
|
||||||
markdownDelimiter = { fg = palette.subtle },
|
markdownDelimiter = { fg = palette.subtle },
|
||||||
markdownH1 = { fg = groups.headings.h1, bold = styles.bold },
|
markdownH1 = { fg = groups.h1, bold = styles.bold },
|
||||||
markdownH1Delimiter = { link = "markdownH1" },
|
markdownH1Delimiter = { link = "markdownH1" },
|
||||||
markdownH2 = { fg = groups.headings.h2, bold = styles.bold },
|
markdownH2 = { fg = groups.h2, bold = styles.bold },
|
||||||
markdownH2Delimiter = { link = "markdownH2" },
|
markdownH2Delimiter = { link = "markdownH2" },
|
||||||
markdownH3 = { fg = groups.headings.h3, bold = styles.bold },
|
markdownH3 = { fg = groups.h3, bold = styles.bold },
|
||||||
markdownH3Delimiter = { link = "markdownH3" },
|
markdownH3Delimiter = { link = "markdownH3" },
|
||||||
markdownH4 = { fg = groups.headings.h4, bold = styles.bold },
|
markdownH4 = { fg = groups.h4, bold = styles.bold },
|
||||||
markdownH4Delimiter = { link = "markdownH4" },
|
markdownH4Delimiter = { link = "markdownH4" },
|
||||||
markdownH5 = { fg = groups.headings.h5, bold = styles.bold },
|
markdownH5 = { fg = groups.h5, bold = styles.bold },
|
||||||
markdownH5Delimiter = { link = "markdownH5" },
|
markdownH5Delimiter = { link = "markdownH5" },
|
||||||
markdownH6 = { fg = groups.headings.h6, bold = styles.bold },
|
markdownH6 = { fg = groups.h6, bold = styles.bold },
|
||||||
markdownH6Delimiter = { link = "markdownH6" },
|
markdownH6Delimiter = { link = "markdownH6" },
|
||||||
markdownLinkText = { link = "markdownUrl" },
|
markdownLinkText = { link = "markdownUrl" },
|
||||||
markdownUrl = { fg = groups.link, sp = groups.link, underline = true },
|
markdownUrl = { fg = groups.link, sp = groups.link, underline = true },
|
||||||
|
|
@ -355,7 +357,7 @@ local function set_highlights()
|
||||||
["@markup.strikethrough"] = { strikethrough = true },
|
["@markup.strikethrough"] = { strikethrough = true },
|
||||||
["@markup.underline"] = { underline = true },
|
["@markup.underline"] = { underline = true },
|
||||||
|
|
||||||
["@markup.heading"] = make_title(),
|
["@markup.heading"] = adaptive_title,
|
||||||
|
|
||||||
["@markup.quote"] = { fg = palette.subtle },
|
["@markup.quote"] = { fg = palette.subtle },
|
||||||
["@markup.math"] = { link = "Special" },
|
["@markup.math"] = { link = "Special" },
|
||||||
|
|
@ -457,7 +459,7 @@ local function set_highlights()
|
||||||
NvimTreeNormal = { link = "Normal" },
|
NvimTreeNormal = { link = "Normal" },
|
||||||
NvimTreeOpenedFile = { fg = palette.text, bg = palette.overlay },
|
NvimTreeOpenedFile = { fg = palette.text, bg = palette.overlay },
|
||||||
NvimTreeOpenedFolderName = { link = "NvimTreeFolderName" },
|
NvimTreeOpenedFolderName = { link = "NvimTreeFolderName" },
|
||||||
NvimTreeRootFolder = make_title(),
|
NvimTreeRootFolder = adaptive_title,
|
||||||
NvimTreeSpecialFile = { link = "NvimTreeNormal" },
|
NvimTreeSpecialFile = { link = "NvimTreeNormal" },
|
||||||
NvimTreeWindowPicker = { link = "StatusLineTerm" },
|
NvimTreeWindowPicker = { link = "StatusLineTerm" },
|
||||||
|
|
||||||
|
|
@ -543,22 +545,22 @@ local function set_highlights()
|
||||||
NeorgHeading5Title = { link = "markdownH5" },
|
NeorgHeading5Title = { link = "markdownH5" },
|
||||||
NeorgHeading6Prefix = { link = "markdownH6Delimiter" },
|
NeorgHeading6Prefix = { link = "markdownH6Delimiter" },
|
||||||
NeorgHeading6Title = { link = "markdownH6" },
|
NeorgHeading6Title = { link = "markdownH6" },
|
||||||
NeorgMarkerTitle = make_title(),
|
NeorgMarkerTitle = adaptive_title,
|
||||||
|
|
||||||
-- tami5/lspsaga.nvim (fork of glepnir/lspsaga.nvim)
|
-- tami5/lspsaga.nvim (fork of glepnir/lspsaga.nvim)
|
||||||
DefinitionCount = { fg = palette.rose },
|
DefinitionCount = { fg = palette.rose },
|
||||||
DefinitionIcon = { fg = palette.rose },
|
DefinitionIcon = { fg = palette.rose },
|
||||||
DefintionPreviewTitle = { fg = palette.rose, bold = styles.bold },
|
DefintionPreviewTitle = { fg = palette.rose, bold = styles.bold },
|
||||||
LspFloatWinBorder = make_border(),
|
LspFloatWinBorder = adaptive_border,
|
||||||
LspFloatWinNormal = { bg = groups.panel },
|
LspFloatWinNormal = { bg = groups.panel },
|
||||||
LspSagaAutoPreview = { fg = palette.subtle },
|
LspSagaAutoPreview = { fg = palette.subtle },
|
||||||
LspSagaCodeActionBorder = make_border(palette.rose),
|
LspSagaCodeActionBorder = make_border(palette.rose),
|
||||||
LspSagaCodeActionContent = { fg = palette.foam },
|
LspSagaCodeActionContent = { fg = palette.foam },
|
||||||
LspSagaCodeActionTitle = { fg = palette.gold, bold = styles.bold },
|
LspSagaCodeActionTitle = { fg = palette.gold, bold = styles.bold },
|
||||||
LspSagaCodeActionTruncateLine = { link = "LspSagaCodeActionBorder" },
|
LspSagaCodeActionTruncateLine = { link = "LspSagaCodeActionBorder" },
|
||||||
LspSagaDefPreviewBorder = make_border(),
|
LspSagaDefPreviewBorder = adaptive_border,
|
||||||
LspSagaDiagnosticBorder = make_border(palette.gold),
|
LspSagaDiagnosticBorder = make_border(palette.gold),
|
||||||
LspSagaDiagnosticHeader = make_title(),
|
LspSagaDiagnosticHeader = adaptive_title,
|
||||||
LspSagaDiagnosticTruncateLine = { link = "LspSagaDiagnosticBorder" },
|
LspSagaDiagnosticTruncateLine = { link = "LspSagaDiagnosticBorder" },
|
||||||
LspSagaDocTruncateLine = { link = "LspSagaHoverBorder" },
|
LspSagaDocTruncateLine = { link = "LspSagaHoverBorder" },
|
||||||
LspSagaFinderSelection = { fg = palette.gold },
|
LspSagaFinderSelection = { fg = palette.gold },
|
||||||
|
|
@ -595,26 +597,26 @@ local function set_highlights()
|
||||||
HopUnmatched = { fg = palette.muted },
|
HopUnmatched = { fg = palette.muted },
|
||||||
|
|
||||||
-- nvim-telescope/telescope.nvim
|
-- nvim-telescope/telescope.nvim
|
||||||
TelescopeBorder = make_border(),
|
TelescopeBorder = adaptive_border,
|
||||||
TelescopeMatching = { fg = palette.rose },
|
TelescopeMatching = { fg = palette.rose },
|
||||||
TelescopeNormal = { link = "NormalFloat" },
|
TelescopeNormal = { link = "NormalFloat" },
|
||||||
TelescopePromptNormal = { link = "TelescopeNormal" },
|
TelescopePromptNormal = { link = "TelescopeNormal" },
|
||||||
TelescopePromptPrefix = { fg = palette.subtle },
|
TelescopePromptPrefix = { fg = palette.subtle },
|
||||||
TelescopeSelection = { fg = palette.text, bg = palette.overlay },
|
TelescopeSelection = { fg = palette.text, bg = palette.overlay },
|
||||||
TelescopeSelectionCaret = { fg = palette.rose, bg = palette.overlay },
|
TelescopeSelectionCaret = { fg = palette.rose, bg = palette.overlay },
|
||||||
TelescopeTitle = make_title(),
|
TelescopeTitle = adaptive_title,
|
||||||
|
|
||||||
-- ibhagwan/fzf-lua
|
-- ibhagwan/fzf-lua
|
||||||
FzfLuaNormal = { link = "NormalFloat" },
|
FzfLuaNormal = { link = "NormalFloat" },
|
||||||
FwzfLuaTitle = make_title(),
|
FwzfLuaTitle = adaptive_title,
|
||||||
FzfLuaBorder = make_border(),
|
FzfLuaBorder = adaptive_border,
|
||||||
FzfLuaHeaderText = { fg = palette.love },
|
FzfLuaHeaderText = { fg = palette.love },
|
||||||
FzfLuaHeaderBind = { fg = palette.rose },
|
FzfLuaHeaderBind = { fg = palette.rose },
|
||||||
FzfLuaBufFlagCur = { fg = palette.subtle },
|
FzfLuaBufFlagCur = { fg = palette.subtle },
|
||||||
FzfLuaBufFlagAlt = { fg = palette.subtle },
|
FzfLuaBufFlagAlt = { fg = palette.subtle },
|
||||||
|
|
||||||
-- rcarriga/nvim-notify
|
-- rcarriga/nvim-notify
|
||||||
NotifyDEBUGBorder = make_border(),
|
NotifyDEBUGBorder = adaptive_border,
|
||||||
NotifyDEBUGIcon = { link = "NotifyDEBUGTitle" },
|
NotifyDEBUGIcon = { link = "NotifyDEBUGTitle" },
|
||||||
NotifyDEBUGTitle = { fg = palette.muted },
|
NotifyDEBUGTitle = { fg = palette.muted },
|
||||||
NotifyERRORBorder = make_border(groups.error),
|
NotifyERRORBorder = make_border(groups.error),
|
||||||
|
|
@ -637,7 +639,7 @@ local function set_highlights()
|
||||||
DapUIBreakpointsLine = { link = "DapUIBreakpointsPath" },
|
DapUIBreakpointsLine = { link = "DapUIBreakpointsPath" },
|
||||||
DapUIBreakpointsPath = { fg = palette.foam },
|
DapUIBreakpointsPath = { fg = palette.foam },
|
||||||
DapUIDecoration = { link = "DapUIBreakpointsPath" },
|
DapUIDecoration = { link = "DapUIBreakpointsPath" },
|
||||||
DapUIFloatBorder = make_border(),
|
DapUIFloatBorder = adaptive_border,
|
||||||
DapUIFrameName = { fg = palette.text },
|
DapUIFrameName = { fg = palette.text },
|
||||||
DapUILineNumber = { link = "DapUIBreakpointsPath" },
|
DapUILineNumber = { link = "DapUIBreakpointsPath" },
|
||||||
DapUIModifiedValue = { fg = palette.foam, bold = styles.bold },
|
DapUIModifiedValue = { fg = palette.foam, bold = styles.bold },
|
||||||
|
|
@ -763,25 +765,41 @@ local function set_highlights()
|
||||||
highlights[group] = highlight
|
highlights[group] = highlight
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if config.options.highlight_groups ~= nil and next(config.options.highlight_groups) ~= nil then
|
|
||||||
vim.print(config.options.highlight_groups)
|
|
||||||
for group, options in pairs(config.options.highlight_groups) do
|
|
||||||
local default_opts = highlights[group] or {}
|
|
||||||
|
|
||||||
if (options.inherit == nil or options.inherit) and default_opts ~= nil then
|
-- Reconcile highlights with config
|
||||||
options.inherit = nil
|
if config.options.highlight_groups ~= nil and next(config.options.highlight_groups) ~= nil then
|
||||||
highlights[group] = vim.tbl_extend("force", default_opts, options)
|
for group, highlight in pairs(config.options.highlight_groups) do
|
||||||
else
|
local existing = highlights[group] or {}
|
||||||
options.inherit = nil
|
local parsed = vim.tbl_extend("force", {}, highlight)
|
||||||
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
|
end
|
||||||
|
|
||||||
highlights[group] = vim.tbl_extend("force", highlights[group] or {}, options)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for group, highlight in pairs(highlights) do
|
for group, highlight in pairs(highlights) do
|
||||||
config.options.before_highlight(group, highlight, palette)
|
if config.options.before_highlight ~= nil then
|
||||||
utilities.highlight(group, highlight)
|
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
|
end
|
||||||
|
|
||||||
--- Terminal
|
--- Terminal
|
||||||
|
|
|
||||||
|
|
@ -59,15 +59,13 @@ config.options = {
|
||||||
git_text = "rose",
|
git_text = "rose",
|
||||||
git_untracked = "subtle",
|
git_untracked = "subtle",
|
||||||
|
|
||||||
---@type table<string, string | PaletteColor>
|
---@type string | PaletteColor
|
||||||
headings = {
|
h1 = "iris",
|
||||||
h1 = "iris",
|
h2 = "foam",
|
||||||
h2 = "foam",
|
h3 = "rose",
|
||||||
h3 = "rose",
|
h4 = "gold",
|
||||||
h4 = "gold",
|
h5 = "pine",
|
||||||
h5 = "pine",
|
h6 = "foam",
|
||||||
h6 = "foam",
|
|
||||||
},
|
|
||||||
|
|
||||||
---@deprecated Replaced by `options.highlight_groups["Normal"]`
|
---@deprecated Replaced by `options.highlight_groups["Normal"]`
|
||||||
-- background = "base",
|
-- background = "base",
|
||||||
|
|
@ -152,6 +150,14 @@ local function migrate(options)
|
||||||
h6 = options.groups.headings,
|
h6 = options.groups.headings,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
if type(options.groups.headings) == "table" then
|
||||||
|
options.groups.h1 = options.groups.headings.h1 or options.groups.h1
|
||||||
|
options.groups.h2 = options.groups.headings.h2 or options.groups.h2
|
||||||
|
options.groups.h3 = options.groups.headings.h3 or options.groups.h3
|
||||||
|
options.groups.h4 = options.groups.headings.h4 or options.groups.h4
|
||||||
|
options.groups.h5 = options.groups.headings.h5 or options.groups.h5
|
||||||
|
options.groups.h6 = options.groups.headings.h6 or options.groups.h6
|
||||||
|
end
|
||||||
|
|
||||||
return options
|
return options
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ local function color_to_rgb(color)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param color string Palette key or hex value
|
---@param color string Palette key or hex value
|
||||||
local function parse_color(color)
|
function utilities.parse_color(color)
|
||||||
if color == nil then
|
if color == nil then
|
||||||
return print("Invalid color")
|
return print("Invalid color: " .. color)
|
||||||
end
|
end
|
||||||
|
|
||||||
color = color:lower()
|
color = color:lower()
|
||||||
|
|
@ -32,7 +32,7 @@ end
|
||||||
---@param fg string Foreground color
|
---@param fg string Foreground color
|
||||||
---@param bg string Background color
|
---@param bg string Background color
|
||||||
---@param alpha number Between 0 (background) and 1 (foreground)
|
---@param alpha number Between 0 (background) and 1 (foreground)
|
||||||
local function blend(fg, bg, alpha)
|
function utilities.blend(fg, bg, alpha)
|
||||||
local fg_rgb = color_to_rgb(fg)
|
local fg_rgb = color_to_rgb(fg)
|
||||||
local bg_rgb = color_to_rgb(bg)
|
local bg_rgb = color_to_rgb(bg)
|
||||||
|
|
||||||
|
|
@ -44,22 +44,4 @@ local function blend(fg, bg, alpha)
|
||||||
return string.format("#%02X%02X%02X", blend_channel(1), blend_channel(2), blend_channel(3))
|
return string.format("#%02X%02X%02X", blend_channel(1), blend_channel(2), blend_channel(3))
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param group string
|
|
||||||
---@param highlight table<string, any>
|
|
||||||
function utilities.highlight(group, highlight, blend_on)
|
|
||||||
local fg = highlight.fg and parse_color(highlight.fg) or "NONE"
|
|
||||||
local bg = highlight.bg and parse_color(highlight.bg) or "NONE"
|
|
||||||
local sp = highlight.sp and parse_color(highlight.sp) or "NONE"
|
|
||||||
|
|
||||||
if highlight.blend ~= nil and (highlight.blend >= 0 and highlight.blend <= 100) and bg ~= nil then
|
|
||||||
bg = blend(bg, blend_on or require("rose-pine.palette").base, highlight.blend / 100)
|
|
||||||
end
|
|
||||||
|
|
||||||
highlight.fg = fg
|
|
||||||
highlight.bg = bg
|
|
||||||
highlight.sp = sp
|
|
||||||
|
|
||||||
vim.api.nvim_set_hl(0, group, highlight)
|
|
||||||
end
|
|
||||||
|
|
||||||
return utilities
|
return utilities
|
||||||
|
|
|
||||||
14
readme.md
14
readme.md
|
|
@ -94,14 +94,12 @@ require('rose-pine').setup({
|
||||||
git_text = "rose",
|
git_text = "rose",
|
||||||
git_untracked = "subtle",
|
git_untracked = "subtle",
|
||||||
|
|
||||||
headings = {
|
h1 = "iris",
|
||||||
h1 = "iris",
|
h2 = "foam",
|
||||||
h2 = "foam",
|
h3 = "rose",
|
||||||
h3 = "rose",
|
h4 = "gold",
|
||||||
h4 = "gold",
|
h5 = "pine",
|
||||||
h5 = "pine",
|
h6 = "foam",
|
||||||
h6 = "foam",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
highlight_groups = {
|
highlight_groups = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue