fix(helix): fixed helix theme with new TS groups

This commit is contained in:
Folke Lemaitre 2024-01-20 12:13:51 +01:00
parent ae69a6a08f
commit 2e00d06319
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040

View File

@ -13,8 +13,8 @@ function M.generate(colors)
builtin = "@type.builtin", builtin = "@type.builtin",
enum = { enum = {
"@lsp.type.enum", "@lsp.type.enum",
variant = "@lsp.type.enumMember" variant = "@lsp.type.enumMember",
} },
}, },
-- rust: pattern matching `let Some(_) = ...` -- rust: pattern matching `let Some(_) = ...`
-- ^^^^ -- ^^^^
@ -23,27 +23,27 @@ function M.generate(colors)
"Constant", "Constant",
builtin = { builtin = {
"@constant.builtin", "@constant.builtin",
boolean = "Boolean" boolean = "Boolean",
}, },
character = { character = {
"Character", "Character",
escape = "@string.escape" escape = "@string.escape",
}, },
numeric = { numeric = {
"Number", "Number",
float = "Float", float = "Float",
integer = "Number" integer = "Number",
} },
}, },
string = { string = {
"String", "String",
regexp = "@string.regex", regexp = "@string.regexp",
special = { special = {
"@string.special", "@string.special",
path = nil, path = nil,
url = nil, url = nil,
symbol = nil symbol = nil,
} },
}, },
comment = { comment = {
"@comment", "@comment",
@ -51,17 +51,17 @@ function M.generate(colors)
block = { block = {
nil, nil,
-- not sure about that one -- not sure about that one
documentation = "@string.documentation" documentation = "@string.documentation",
} },
}, },
variable = { variable = {
"@variable", "@variable",
builtin = "@variable.builtin", builtin = "@variable.builtin",
parameter = "@parameter", parameter = "@variable.parameter",
other = { other = {
nil, nil,
member = "@field" member = "@variable.member",
} },
}, },
label = "@label", label = "@label",
keyword = { keyword = {
@ -72,7 +72,7 @@ function M.generate(colors)
["repeat"] = "Repeat", ["repeat"] = "Repeat",
import = nil, import = nil,
["return"] = "@keyword.return", ["return"] = "@keyword.return",
exception = "Exception" exception = "Exception",
}, },
operator = "Statement", operator = "Statement",
directive = "PreProc", directive = "PreProc",
@ -80,8 +80,8 @@ function M.generate(colors)
storage = { storage = {
nil, -- rust: `let` nil, -- rust: `let`
type = nil, -- rust: `struct` & `type` type = nil, -- rust: `struct` & `type`
modifier = nil -- rust: `mut` modifier = nil, -- rust: `mut`
} },
}, },
operator = "Operator", operator = "Operator",
["function"] = { ["function"] = {
@ -90,12 +90,12 @@ function M.generate(colors)
method = "@method", method = "@method",
macro = "@function.macro", macro = "@function.macro",
-- Defined as "preprocessor in C", so using "PreProc", not sure though -- Defined as "preprocessor in C", so using "PreProc", not sure though
special = "PreProc" special = "PreProc",
}, },
tag = { tag = {
"@tag", "@tag",
-- ??? -- ???
builtin = nil builtin = nil,
}, },
namespace = "@namespace", namespace = "@namespace",
special = "Special", special = "Special",
@ -113,41 +113,41 @@ function M.generate(colors)
h6 = nil, h6 = nil,
-- UI -- -- UI --
completion = "Pmenu", completion = "Pmenu",
hover = "PmenuSel" hover = "PmenuSel",
}, },
list = { list = {
"markdownHeadingDelimiter", "markdownHeadingDelimiter",
unnumbered = nil, unnumbered = nil,
numbered = nil, numbered = nil,
checked = nil, checked = nil,
unchecked = nil unchecked = nil,
}, },
bold = "Bold", bold = "Bold",
italic = "Italic", italic = "Italic",
strikethrough = { strikethrough = {
'helix', "helix",
modifiers = { 'crossed_out' } modifiers = { "crossed_out" },
}, },
link = { link = {
"markdownLinkText", "markdownLinkText",
url = "Underlined", url = "Underlined",
label = "markdownCode", label = "markdownCode",
text = "markdownCode" text = "markdownCode",
}, },
quote = nil, quote = nil,
raw = { raw = {
"markdownCode", "markdownCode",
inline = "@text.literal.markdown_inline", inline = "@markup.raw.markdown_inline",
block = "markdownCodeBlock", block = "markdownCodeBlock",
-- UI -- -- UI --
completion = nil, completion = nil,
hover = nil hover = nil,
}, },
-- UI -- -- UI --
normal = { normal = {
nil, nil,
completion = "CmpItemMenu", completion = "CmpItemMenu",
hover = "CmpItemKindDefault" hover = "CmpItemKindDefault",
}, },
}, },
diff = { diff = {
@ -156,13 +156,13 @@ function M.generate(colors)
minus = "diffRemoved", minus = "diffRemoved",
delta = { delta = {
"diffChanged", "diffChanged",
moved = "diffFile" moved = "diffFile",
} },
}, },
ui = { ui = {
background = { background = {
{ "helix", bg = "bg" }, { "helix", bg = "bg" },
separator = nil separator = nil,
}, },
cursor = { cursor = {
"Cursor", "Cursor",
@ -179,15 +179,15 @@ function M.generate(colors)
}, },
debug = { debug = {
breakpoint = nil, breakpoint = nil,
active = nil active = nil,
}, },
gutter = { gutter = {
nil, nil,
selected = nil selected = nil,
}, },
highlight = { highlight = {
nil, nil,
frameline = nil frameline = nil,
}, },
linenr = { linenr = {
"LineNr", "LineNr",
@ -198,17 +198,17 @@ function M.generate(colors)
inactive = "StatusLineNc", inactive = "StatusLineNc",
-- Inspired from lualine -- Inspired from lualine
normal = { normal = {
'helix', "helix",
bg = "blue", bg = "blue",
fg = "black" fg = "black",
}, },
insert = nil, insert = nil,
select = nil, select = nil,
separator = nil separator = nil,
}, },
popup = { popup = {
"TelescopeBorder", "TelescopeBorder",
info = nil info = nil,
}, },
window = "WinSeparator", window = "WinSeparator",
help = nil, help = nil,
@ -228,28 +228,28 @@ function M.generate(colors)
parameter = nil, parameter = nil,
type = nil, type = nil,
}, },
wrap = nil wrap = nil,
}, },
menu = { menu = {
"Pmenu", "Pmenu",
selected = "PmenuSel", selected = "PmenuSel",
scroll = { scroll = {
'helix', "helix",
fg = vim.api.nvim_get_hl(0, { name = "PmenuThumb" }).bg, fg = vim.api.nvim_get_hl(0, { name = "PmenuThumb" }).bg,
bg = vim.api.nvim_get_hl(0, { name = "PmenuSbar" }).bg, bg = vim.api.nvim_get_hl(0, { name = "PmenuSbar" }).bg,
} },
}, },
selection = { selection = {
{ 'helix', bg = "bg_highlight" }, { "helix", bg = "bg_highlight" },
primary = nil primary = nil,
}, },
cursorline = { cursorline = {
primary = nil, primary = nil,
secondary = nil secondary = nil,
}, },
cursorcolumn = { cursorcolumn = {
primary = nil, primary = nil,
secondary = nil secondary = nil,
}, },
}, },
hint = "DiagnosticHint", hint = "DiagnosticHint",
@ -261,15 +261,15 @@ function M.generate(colors)
hint = "DiagnosticUnderlineHint", hint = "DiagnosticUnderlineHint",
info = "DiagnosticUnderlineInfo", info = "DiagnosticUnderlineInfo",
warning = "DiagnosticUnderlineWarn", warning = "DiagnosticUnderlineWarn",
error = "DiagnosticUnderlineError" error = "DiagnosticUnderlineError",
} },
}) })
local config = {} local config = {}
for hx_scope, group in M.pairsByKeys(mapping) do for hx_scope, group in M.pairsByKeys(mapping) do
-- print(hx_scope, util.dump(group)) -- print(hx_scope, util.dump(group))
hx_scope = hx_scope:gsub("%.h(%d)", ".%1") hx_scope = hx_scope:gsub("%.h(%d)", ".%1")
if hx_scope:match('%.') then if hx_scope:match("%.") then
hx_scope = '"' .. hx_scope .. '"' hx_scope = '"' .. hx_scope .. '"'
end end
@ -277,8 +277,8 @@ function M.generate(colors)
goto continue goto continue
end end
if type(group) == "table" and group[1] == 'helix' then if type(group) == "table" and group[1] == "helix" then
table.remove(group, 1); table.remove(group, 1)
table.insert(config, string.format("%s = %s", hx_scope, M.to_toml(group))) table.insert(config, string.format("%s = %s", hx_scope, M.to_toml(group)))
goto continue goto continue
end end
@ -296,16 +296,16 @@ function M.generate(colors)
::continue:: ::continue::
end end
table.insert(config, '\n[palette]'); table.insert(config, "\n[palette]")
for name, color in M.pairsByKeys(M.flatten(colors)) do for name, color in M.pairsByKeys(M.flatten(colors)) do
if name:match('%.') then if name:match("%.") then
name = '"' .. name .. '"' name = '"' .. name .. '"'
end end
if type(color) == 'string' and not string.starts(name, '_') and name ~= 'none' then if type(color) == "string" and not string.starts(name, "_") and name ~= "none" then
table.insert(config, string.format('%s = "%s"', name, color)) table.insert(config, string.format('%s = "%s"', name, color))
end end
end end
return table.concat(config, '\n') return table.concat(config, "\n")
end end
function string.starts(String, Start) function string.starts(String, Start)
@ -315,15 +315,15 @@ end
function M.flatten(t) function M.flatten(t)
local res = {} local res = {}
for k, v in pairs(t) do for k, v in pairs(t) do
if type(v) == 'table' then if type(v) == "table" then
if v[1] ~= 'helix' then if v[1] ~= "helix" then
for k2, v2 in pairs(M.flatten(v)) do for k2, v2 in pairs(M.flatten(v)) do
-- Special case for tables like: -- Special case for tables like:
-- { type = { "@type", enum = "@type.enum" } } -- { type = { "@type", enum = "@type.enum" } }
if k2 == 1 then if k2 == 1 then
res[k] = v2 res[k] = v2
else else
res[k .. '.' .. k2] = v2 res[k .. "." .. k2] = v2
end end
end end
else else
@ -339,7 +339,9 @@ end
-- https://www.lua.org/pil/19.3.html -- https://www.lua.org/pil/19.3.html
function M.pairsByKeys(t, f) function M.pairsByKeys(t, f)
local a = {} local a = {}
for n in pairs(t) do table.insert(a, n) end for n in pairs(t) do
table.insert(a, n)
end
table.sort(a, f) table.sort(a, f)
local i = 0 -- iterator variable local i = 0 -- iterator variable
local iter = function() -- iterator function local iter = function() -- iterator function
@ -369,13 +371,13 @@ function M.to_helix_config(highlight)
end end
if mods.underline then if mods.underline then
style.underline = { style.underline = {
style = "line" style = "line",
} }
end end
if mods.undercurl and highlight.sp then if mods.undercurl and highlight.sp then
style.underline = { style.underline = {
color = M.to_rgb(mods.sp), color = M.to_rgb(mods.sp),
style = "curl" style = "curl",
} }
end end
end end
@ -405,7 +407,7 @@ end
function M.to_toml(style) function M.to_toml(style)
local buffer = {} local buffer = {}
M.insert_as_toml(buffer, style) M.insert_as_toml(buffer, style)
return table.concat(buffer, '') return table.concat(buffer, "")
end end
function M.insert_as_toml(buffer, x) function M.insert_as_toml(buffer, x)
@ -416,7 +418,7 @@ function M.insert_as_toml(buffer, x)
if M.is_array(x) then if M.is_array(x) then
table.insert(buffer, "[") table.insert(buffer, "[")
for _, v in pairs(x) do for _, v in pairs(x) do
M.insert_as_toml(buffer, v); M.insert_as_toml(buffer, v)
table.insert(buffer, ", ") table.insert(buffer, ", ")
end end
table.remove(buffer) table.remove(buffer)
@ -424,8 +426,8 @@ function M.insert_as_toml(buffer, x)
else else
table.insert(buffer, "{ ") table.insert(buffer, "{ ")
for k, v in M.pairsByKeys(x) do for k, v in M.pairsByKeys(x) do
table.insert(buffer, string.format("%s = ", k)); table.insert(buffer, string.format("%s = ", k))
M.insert_as_toml(buffer, v); M.insert_as_toml(buffer, v)
table.insert(buffer, ", ") table.insert(buffer, ", ")
end end
table.remove(buffer) table.remove(buffer)
@ -442,7 +444,9 @@ function M.is_array(t)
local i = 0 local i = 0
for _ in pairs(t) do for _ in pairs(t) do
i = i + 1 i = i + 1
if t[i] == nil then return false end if t[i] == nil then
return false
end
end end
return true return true
end end