From e505c2bf88ef0e3fcb2c46195baacd0fcbe79d6f Mon Sep 17 00:00:00 2001 From: tiagovla Date: Mon, 25 Apr 2022 01:22:45 -0300 Subject: [PATCH] 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" --- .lua-format | 1 - README.md | 2 +- lua/tokyodark/highlights.lua | 48 ++++++------------------------------ lua/tokyodark/init.lua | 2 -- 4 files changed, 9 insertions(+), 44 deletions(-) delete mode 100644 .lua-format diff --git a/.lua-format b/.lua-format deleted file mode 100644 index 6218fb8..0000000 --- a/.lua-format +++ /dev/null @@ -1 +0,0 @@ -column_limit: 100 diff --git a/README.md b/README.md index b88bc7a..8879492 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ### About -A clean dark theme written in lua for neovim 0.5. +A clean dark theme written in lua for neovim 0.7. ### Features diff --git a/lua/tokyodark/highlights.lua b/lua/tokyodark/highlights.lua index 9cd8143..992f28a 100644 --- a/lua/tokyodark/highlights.lua +++ b/lua/tokyodark/highlights.lua @@ -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 diff --git a/lua/tokyodark/init.lua b/lua/tokyodark/init.lua index d5fdcb2..4f8f86e 100644 --- a/lua/tokyodark/init.lua +++ b/lua/tokyodark/init.lua @@ -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