From 5748536742f630808d05b28be54f370f67eb1cc7 Mon Sep 17 00:00:00 2001 From: Sidhanth Rathod Date: Mon, 16 Oct 2023 07:24:14 +0530 Subject: [PATCH] performance: avoid reloading config table #2360 (#2444) * performance: avoid reloading config (#2360) * performance: avoid reloading config * Rm outdated info in readme --------- Co-authored-by: Sidhanth Rathod * update nvchad load_config result path * update branch names --------- Co-authored-by: georgejean --- lua/core/bootstrap.lua | 2 +- lua/core/init.lua | 7 ++----- lua/core/utils.lua | 4 ++-- lua/nvconfig.lua | 2 ++ lua/plugins/configs/cmp.lua | 2 +- lua/plugins/configs/lspconfig.lua | 3 +-- lua/plugins/init.lua | 6 +++--- 7 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 lua/nvconfig.lua diff --git a/lua/core/bootstrap.lua b/lua/core/bootstrap.lua index c1bab90..20e056e 100644 --- a/lua/core/bootstrap.lua +++ b/lua/core/bootstrap.lua @@ -18,7 +18,7 @@ M.lazy = function(install_path) M.echo " Compiling base46 theme to bytecode ..." local base46_repo = "https://github.com/NvChad/base46" - shell_call { "git", "clone", "--depth", "1", "-b", "v2.0", base46_repo, lazy_path } + shell_call { "git", "clone", "--depth", "1", "-b", "v3.0", base46_repo, lazy_path } vim.opt.rtp:prepend(lazy_path) require("base46").compile() diff --git a/lua/core/init.lua b/lua/core/init.lua index 6f396ac..61de98f 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -1,12 +1,9 @@ local opt = vim.opt local g = vim.g -local config = require("core.utils").load_config() -------------------------------------- globals ----------------------------------------- -g.nvchad_theme = config.ui.theme g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/" g.toggle_theme_icon = "  " -g.transparency = config.ui.transparency -------------------------------------- options ------------------------------------------ opt.laststatus = 3 -- global statusline @@ -83,11 +80,11 @@ autocmd("BufWritePost", { local app_name = vim.env.NVIM_APPNAME and vim.env.NVIM_APPNAME or "nvim" local module = string.gsub(fp, "^.*/" .. app_name .. "/lua/", ""):gsub("/", ".") + require("plenary.reload").reload_module "nvconfig" require("plenary.reload").reload_module "base46" require("plenary.reload").reload_module(module) - require("plenary.reload").reload_module "custom.chadrc" - config = require("core.utils").load_config() + local config = require "nvconfig" vim.g.nvchad_theme = config.ui.theme vim.g.transparency = config.ui.transparency diff --git a/lua/core/utils.lua b/lua/core/utils.lua index 8b2a03d..96fe103 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -7,7 +7,7 @@ M.load_config = function() if chadrc_path then local chadrc = dofile(chadrc_path) - + config.mappings = M.remove_disabled_keys(chadrc.mappings, config.mappings) config = merge_tb("force", config, chadrc) config.mappings.disabled = nil @@ -74,7 +74,7 @@ M.load_mappings = function(section, mapping_opt) end end - local mappings = require("core.utils").load_config().mappings + local mappings = require("nvconfig").mappings if type(section) == "string" then mappings[section]["plugin"] = nil diff --git a/lua/nvconfig.lua b/lua/nvconfig.lua new file mode 100644 index 0000000..df0d4a4 --- /dev/null +++ b/lua/nvconfig.lua @@ -0,0 +1,2 @@ +-- check default config at core/default_config.lua +return require("core.utils").load_config() diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index 19868b6..4af9ed2 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -2,7 +2,7 @@ local cmp = require "cmp" dofile(vim.g.base46_cache .. "cmp") -local cmp_ui = require("core.utils").load_config().ui.cmp +local cmp_ui = require("nvconfig").ui.cmp local cmp_style = cmp_ui.style local field_arrangement = { diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index a605c7e..df7f05b 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -3,14 +3,13 @@ local M = {} -- export on_attach & capabilities for custom lspconfigs M.on_attach = function(client, bufnr) local utils = require "core.utils" - local conf = utils.load_config().ui.lsp + local conf = require "nvconfig" -- semanticTokens if not conf.semantic_tokens and client.supports_method "textDocument/semanticTokens" then client.server_capabilities.semanticTokensProvider = nil end - -- signature if conf.signature and client.server_capabilities.signatureHelpProvider then require("nvchad.signature").setup(client, bufnr) end diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 0e8f84e..2b1b478 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -6,7 +6,7 @@ local default_plugins = { { "NvChad/base46", - branch = "v3.0", + branch = "test", build = function() require("base46").load_all_highlights() end, @@ -14,7 +14,7 @@ local default_plugins = { { "NvChad/ui", - branch = "v3.0", + branch = "test", lazy = false, config = function() require "nvchad" @@ -258,7 +258,7 @@ local default_plugins = { }, } -local config = require("core.utils").load_config() +local config = require "nvconfig" if #config.plugins > 0 then table.insert(default_plugins, { import = config.plugins })