Skip to content

Commit

Permalink
performance: avoid reloading config (#2360)
Browse files Browse the repository at this point in the history
* performance: avoid reloading config

* Rm outdated info in readme

---------

Co-authored-by: Sidhanth Rathod <siduck@tutanota.com>
  • Loading branch information
georgejean and siduck committed Oct 6, 2023
1 parent 5261eb3 commit c6a716d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/core/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local opt = vim.opt
local g = vim.g
local config = require("core.utils").load_config()
local config = require("core.utils").config

-------------------------------------- globals -----------------------------------------
g.nvchad_theme = config.ui.theme
Expand Down
13 changes: 8 additions & 5 deletions lua/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ 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
if chadrc then
config.mappings = M.remove_disabled_keys(chadrc.mappings, config.mappings)
config = merge_tb("force", config, chadrc)
config.mappings.disabled = nil
end
end

return config
Expand Down Expand Up @@ -51,6 +52,8 @@ M.remove_disabled_keys = function(chadrc_mappings, default_mappings)
return default_mappings
end

M.config = M.load_config()

M.load_mappings = function(section, mapping_opt)
vim.schedule(function()
local function set_section_map(section_values)
Expand All @@ -74,7 +77,7 @@ M.load_mappings = function(section, mapping_opt)
end
end

local mappings = require("core.utils").load_config().mappings
local mappings = require("core.utils").config.mappings

if type(section) == "string" then
mappings[section]["plugin"] = nil
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/configs/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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("core.utils").config.ui.cmp
local cmp_style = cmp_ui.style

local field_arrangement = {
Expand Down
3 changes: 1 addition & 2 deletions lua/plugins/configs/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = utils.config.ui.lsp

-- 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
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ local default_plugins = {
},
}

local config = require("core.utils").load_config()
local config = require("core.utils").config

if #config.plugins > 0 then
table.insert(default_plugins, { import = config.plugins })
Expand Down

0 comments on commit c6a716d

Please sign in to comment.