feat: add support for global highlight namespace
IMPORTANT: neovim 0.7 or higher is required Custom configs should use the global namespace 0 instead of "tokyodark"
This commit is contained in:
@@ -6,22 +6,10 @@ local M = {}
|
||||
local hl = { langs = {}, plugins = {} }
|
||||
|
||||
local highlight = vim.api.nvim_set_hl
|
||||
local set_hl_ns = vim.api.nvim__set_hl_ns or vim.api.nvim_set_hl_ns
|
||||
local ns = vim.api.nvim_create_namespace("tokyodark")
|
||||
|
||||
local function load_highlights(highlights)
|
||||
for group_name, group_settings in pairs(highlights) do
|
||||
highlight(ns, group_name, group_settings)
|
||||
end
|
||||
end
|
||||
|
||||
local function load_highlights_legacy(highlights)
|
||||
local bg, fg, hl_cmd
|
||||
for group_name, group_settings in pairs(highlights) do
|
||||
bg = group_settings.bg and "guibg=" .. group_settings.bg or "guibg=NONE"
|
||||
fg = group_settings.fg and "guifg=" .. group_settings.fg or "guifg=NONE"
|
||||
hl_cmd = "highlight " .. group_name .. " " .. bg .. " " .. fg
|
||||
vim.cmd(hl_cmd)
|
||||
highlight(0, group_name, group_settings)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,14 +29,11 @@ hl.predef = {
|
||||
YellowItalic = { fg = p.yellow, italic = cfg.italic },
|
||||
}
|
||||
|
||||
hl.legacy = {
|
||||
Normal = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
|
||||
LspReferenceRead = { bg = p.bg3 },
|
||||
LspReferenceWrite = { bg = p.bg3 },
|
||||
LspReferenceText = { bg = p.bg3 },
|
||||
}
|
||||
|
||||
hl.common = {
|
||||
Normal = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
|
||||
NormalNC = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
|
||||
NormalSB = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
|
||||
NormalFloat = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
|
||||
Terminal = { fg = p.fg, bg = cfg.bg and p.none or p.bg0 },
|
||||
EndOfBuffer = { fg = p.bg2, bg = cfg.bg and p.none or p.bg0 },
|
||||
FoldColumn = { fg = p.fg, bg = cfg.bg and p.none or p.bg1 },
|
||||
@@ -163,6 +148,9 @@ hl.plugins.lsp = {
|
||||
DiagnosticSignHint = { fg = u.color_gamma(p.purple, 0.5) },
|
||||
DiagnosticSignInfo = { fg = u.color_gamma(p.blue, 0.5) },
|
||||
DiagnosticSignWarn = { fg = u.color_gamma(p.yellow, 0.5) },
|
||||
LspReferenceRead = { bg = p.bg3 },
|
||||
LspReferenceWrite = { bg = p.bg3 },
|
||||
LspReferenceText = { bg = p.bg3 },
|
||||
}
|
||||
|
||||
hl.plugins.whichkey = {
|
||||
@@ -306,13 +294,7 @@ hl.langs.scala = {
|
||||
scalaKeywordModifier = hl.predef.Red,
|
||||
}
|
||||
|
||||
function M.clear_namespace()
|
||||
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||
set_hl_ns(0)
|
||||
end
|
||||
|
||||
local function load_sync()
|
||||
load_highlights_legacy(hl.legacy)
|
||||
load_highlights(hl.predef)
|
||||
load_highlights(hl.common)
|
||||
load_highlights(hl.syntax)
|
||||
@@ -322,24 +304,10 @@ local function load_sync()
|
||||
for _, group in pairs(hl.plugins) do
|
||||
load_highlights(group)
|
||||
end
|
||||
set_hl_ns(ns)
|
||||
end
|
||||
|
||||
local load_async
|
||||
load_async = vim.loop.new_async(vim.schedule_wrap(function()
|
||||
for _, group in pairs(hl.langs) do
|
||||
load_highlights(group)
|
||||
end
|
||||
for _, group in pairs(hl.plugins) do
|
||||
load_highlights(group)
|
||||
end
|
||||
set_hl_ns(ns)
|
||||
load_async:close()
|
||||
end))
|
||||
|
||||
function M.setup()
|
||||
load_sync()
|
||||
-- load_async:send() TODO: find why it does not work with v0.5 anymore
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -13,8 +13,6 @@ function M.colorscheme()
|
||||
vim.g.colors_name = "tokyodark"
|
||||
highlights.setup()
|
||||
terminal.setup()
|
||||
|
||||
vim.cmd([[au ColorSchemePre * lua require("tokyodark.highlights").clear_namespace()]])
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user