diff --git a/lua/base46/init.lua b/lua/base46/init.lua index 846406f..244caf1 100644 --- a/lua/base46/init.lua +++ b/lua/base46/init.lua @@ -1,7 +1,6 @@ local M = {} local g = vim.g local config = require "nvconfig" -local base46_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") if not vim.g.nvchad_theme then vim.g.nvchad_theme = config.ui.theme @@ -71,7 +70,7 @@ M.extend_default_hl = function(highlights) end -- transparency - if vim.g.transparency then + if config.ui.transparency then local glassy = require "base46.glassy" for key, value in pairs(glassy) do @@ -92,9 +91,8 @@ M.extend_default_hl = function(highlights) end end -M.load_highlight = function(group, is_extended) - local str = is_extended and "extended_" or "" - group = require("base46." .. str .. "integrations." .. group) +M.load_integrationTB = function(group) + group = require("base46.integrations." .. group) M.extend_default_hl(group) return group end @@ -140,24 +138,8 @@ M.compile = function() vim.fn.mkdir(vim.g.base46_cache, "p") end - -- All integration modules, each file returns a table - local hl_files = base46_path .. "/integrations" - - for _, file in ipairs(vim.fn.readdir(hl_files)) do - -- skip caching some files - if file ~= "statusline" or file ~= "treesitter" then - local filename = vim.fn.fnamemodify(file, ":r") - M.saveStr_to_cache(filename, M.load_highlight(filename)) - end - end - - -- look for custom cached highlight files - local extended_integrations = config.ui.extended_integrations - - if extended_integrations then - for _, filename in ipairs(extended_integrations) do - M.saveStr_to_cache(filename, M.load_highlight(filename, true)) - end + for _, filename in ipairs(config.base46.integrations) do + M.saveStr_to_cache(filename, M.load_integrationTB(filename)) end end @@ -165,8 +147,8 @@ M.load_all_highlights = function() require("plenary.reload").reload_module "base46" M.compile() - for _, file in ipairs(vim.fn.readdir(vim.g.base46_cache)) do - dofile(vim.g.base46_cache .. file) + for _, filename in ipairs(config.base46.integrations) do + dofile(vim.g.base46_cache .. filename) end -- update blankline @@ -182,36 +164,28 @@ end M.toggle_theme = function() local themes = config.ui.theme_toggle - local theme1 = themes[1] - local theme2 = themes[2] - if g.nvchad_theme ~= theme1 and g.nvchad_theme ~= theme2 then + if g.nvchad_theme ~= themes[1] and g.nvchad_theme ~= themes[2] then vim.notify "Set your current theme to one of those mentioned in the theme_toggle table (chadrc)" return end - if g.nvchad_theme == theme1 then + if g.nvchad_theme == themes[1] then g.toggle_theme_icon = "  " - vim.g.nvchad_theme = theme2 - require("nvchad.utils").replace_word('theme = "' .. theme1, 'theme = "' .. theme2) + g.nvchad_theme = themes[2] else - vim.g.nvchad_theme = theme1 g.toggle_theme_icon = "  " - require("nvchad.utils").replace_word('theme = "' .. theme2, 'theme = "' .. theme1) + g.nvchad_theme = themes[1] end + require("nvchad.utils").change_key_val("theme", g.nvchad_theme) M.load_all_highlights() end M.toggle_transparency = function() - g.transparency = not g.transparency + config.ui.transparency = not config.ui.transparency M.load_all_highlights() - - -- write transparency value to chadrc - local old_data = "transparency = " .. tostring(config.ui.transparency) - local new_data = "transparency = " .. tostring(g.transparency) - - require("nvchad.utils").replace_word(old_data, new_data) + require("nvchad.utils").change_key_val("transparency", config.ui.transparency) end return M diff --git a/lua/base46/integrations/defaults.lua b/lua/base46/integrations/defaults.lua index 1904f39..2f5b775 100644 --- a/lua/base46/integrations/defaults.lua +++ b/lua/base46/integrations/defaults.lua @@ -245,9 +245,13 @@ local defaults = { -- merge statusilne & hl_add tables! local merge_tb = require("base46").merge_tb -defaults = merge_tb(defaults, require("base46").load_highlight "statusline") +defaults = merge_tb(defaults, require("base46").load_integrationTB "statusline") -local hexify_ColorStrs = require("base46").turn_str_to_color local user_new_highlights = require("nvconfig").ui.hl_add -return merge_tb(defaults, hexify_ColorStrs(user_new_highlights)) +if user_new_highlights then + local hexify_ColorStrs = require("base46").turn_str_to_color + defaults = merge_tb(defaults, hexify_ColorStrs(user_new_highlights)) +end + +return defaults diff --git a/lua/base46/integrations/semantic_tokens.lua b/lua/base46/integrations/semantic_tokens.lua new file mode 100644 index 0000000..56cb808 --- /dev/null +++ b/lua/base46/integrations/semantic_tokens.lua @@ -0,0 +1,22 @@ +local theme = require("base46").get_theme_tb "base_16" + +return { + ["@lsp.type.class"] = { link = "Structure" }, + ["@lsp.type.decorator"] = { link = "Function" }, + ["@lsp.type.enum"] = { link = "Type" }, + ["@lsp.type.enumMember"] = { link = "Constant" }, + ["@lsp.type.function"] = { link = "@function" }, + ["@lsp.type.interface"] = { link = "Structure" }, + ["@lsp.type.macro"] = { link = "@macro" }, + ["@lsp.type.method"] = { link = "@method" }, + ["@lsp.type.namespace"] = { link = "@namespace" }, + ["@lsp.type.parameter"] = { link = "@parameter" }, + ["@lsp.type.property"] = { link = "@property" }, + ["@lsp.type.struct"] = { link = "Structure" }, + ["@lsp.type.type"] = { link = "@type" }, + ["@lsp.type.typeParamater"] = { link = "TypeDef" }, + ["@lsp.type.variable"] = { link = "@variable" }, + ["@event"] = { fg = theme.base08 }, + ["@modifier"] = { fg = theme.base08 }, + ["@regexp"] = { fg = theme.base0F }, +} diff --git a/lua/base46/integrations/syntax.lua b/lua/base46/integrations/syntax.lua index dbcb79a..7291681 100644 --- a/lua/base46/integrations/syntax.lua +++ b/lua/base46/integrations/syntax.lua @@ -116,32 +116,5 @@ local syntax = { } local merge_tb = require("base46").merge_tb -local lsp_semantic_tokens = require("nvconfig").ui.lsp_semantic_tokens - -if vim.version().minor >= 9 and lsp_semantic_tokens then - local semantic_hls = { - ["@lsp.type.class"] = { link = "Structure" }, - ["@lsp.type.decorator"] = { link = "Function" }, - ["@lsp.type.enum"] = { link = "Type" }, - ["@lsp.type.enumMember"] = { link = "Constant" }, - ["@lsp.type.function"] = { link = "@function" }, - ["@lsp.type.interface"] = { link = "Structure" }, - ["@lsp.type.macro"] = { link = "@macro" }, - ["@lsp.type.method"] = { link = "@method" }, - ["@lsp.type.namespace"] = { link = "@namespace" }, - ["@lsp.type.parameter"] = { link = "@parameter" }, - ["@lsp.type.property"] = { link = "@property" }, - ["@lsp.type.struct"] = { link = "Structure" }, - ["@lsp.type.type"] = { link = "@type" }, - ["@lsp.type.typeParamater"] = { link = "TypeDef" }, - ["@lsp.type.variable"] = { link = "@variable" }, - - -- ["@event"] = { fg = theme.base08 }, - -- ["@modifier"] = { fg = theme.base08 }, - -- ["@regexp"] = { fg = theme.base0F }, - } - - syntax = merge_tb(syntax, semantic_hls) -end - -return merge_tb(syntax, require("base46").load_highlight "treesitter") + +return merge_tb(syntax, require("base46").load_integrationTB "treesitter")