remove usage of globals for util functions

This commit is contained in:
siduck 2022-05-29 16:07:47 +05:30
parent 0f013d4e7b
commit cb97cef2a7
18 changed files with 55 additions and 55 deletions

View File

@ -71,7 +71,7 @@ M.bufferline = {
-- close buffer + hide terminal buffer
["<leader>x"] = {
function()
nvchad.close_buffer()
require("core.utils").close_buffer()
end,
" close buffer",
},

View File

@ -1,7 +1,7 @@
local opt = vim.opt
local g = vim.g
g.nvchad_theme = nvchad.load_config().ui.theme
g.nvchad_theme = require("core.utils").load_config().ui.theme
-- use filetype.lua instead of filetype.vim
g.did_load_filetypes = 0
@ -86,4 +86,4 @@ vim.schedule(function()
end)
-- load user options if the file exists
nvchad.load_config().options.user()
require("core.utils").load_config().options.user()

View File

@ -37,7 +37,7 @@ M.options = {
}
-- merge overrides if there are any
M.options = nvchad.load_override(M.options, "wbthomason/packer.nvim")
M.options = require("core.utils").load_override(M.options, "wbthomason/packer.nvim")
M.run = function(plugins)
local present, packer = pcall(require, "packer")
@ -47,8 +47,8 @@ M.run = function(plugins)
end
-- Override with chadrc values
plugins = nvchad.remove_default_plugins(plugins)
plugins = nvchad.merge_plugins(plugins)
plugins = require("core.utils").remove_default_plugins(plugins)
plugins = require("core.utils").merge_plugins(plugins)
packer.init(M.options)

View File

@ -1,8 +1,8 @@
_G.nvchad = {}
local M = {}
local merge_tb = vim.tbl_deep_extend
nvchad.close_buffer = function(force)
M.close_buffer = function(force)
if vim.bo.buftype == "terminal" then
vim.api.nvim_win_hide(0)
return
@ -24,14 +24,14 @@ nvchad.close_buffer = function(force)
vim.cmd(close_cmd)
end
nvchad.load_config = function()
M.load_config = function()
local config = require "core.default_config"
local chadrc_exists, chadrc = pcall(require, "custom.chadrc")
if chadrc_exists then
-- merge user config if it exists and is a table; otherwise display an error
if type(chadrc) == "table" then
nvchad.remove_default_keys()
M.remove_default_keys()
config = merge_tb("force", config, chadrc)
else
error "chadrc must return a table!"
@ -42,7 +42,7 @@ nvchad.load_config = function()
return config
end
nvchad.remove_default_keys = function()
M.remove_default_keys = function()
local chadrc = require "custom.chadrc"
local user_mappings = chadrc.mappings or {}
local user_keys = {}
@ -73,8 +73,8 @@ nvchad.remove_default_keys = function()
end
end
nvchad.load_mappings = function(mappings, mapping_opt)
mappings = mappings or nvchad.load_config().mappings
M.load_mappings = function(mappings, mapping_opt)
mappings = mappings or M.load_config().mappings
-- set mapping function with/without whichkye
local map_func
@ -114,7 +114,7 @@ nvchad.load_mappings = function(mappings, mapping_opt)
end
-- load plugin after entering vim ui
nvchad.packer_lazy_load = function(plugin, timer)
M.packer_lazy_load = function(plugin, timer)
if plugin then
timer = timer or 0
vim.defer_fn(function()
@ -124,8 +124,8 @@ nvchad.packer_lazy_load = function(plugin, timer)
end
-- remove plugins defined in chadrc
nvchad.remove_default_plugins = function(plugins)
local removals = nvchad.load_config().plugins.remove or {}
M.remove_default_plugins = function(plugins)
local removals = M.load_config().plugins.remove or {}
if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
@ -137,8 +137,8 @@ nvchad.remove_default_plugins = function(plugins)
end
-- merge default/user plugin tables
nvchad.merge_plugins = function(default_plugins)
local user_plugins = nvchad.load_config().plugins.user
M.merge_plugins = function(default_plugins)
local user_plugins = M.load_config().plugins.user
-- merge default + user plugin table
default_plugins = merge_tb("force", default_plugins, user_plugins)
@ -154,8 +154,8 @@ nvchad.merge_plugins = function(default_plugins)
return final_table
end
nvchad.load_override = function(default_table, plugin_name)
local user_table = nvchad.load_config().plugins.override[plugin_name]
M.load_override = function(default_table, plugin_name)
local user_table = M.load_config().plugins.override[plugin_name]
if type(user_table) == "table" then
default_table = merge_tb("force", default_table, user_table)
@ -165,3 +165,5 @@ nvchad.load_override = function(default_table, plugin_name)
return default_table
end
return M

View File

@ -72,7 +72,7 @@ options.buttons = {
},
}
options = nvchad.load_override(options, "goolord/alpha-nvim")
options = require("core.utils").load_override(options, "goolord/alpha-nvim")
-- dynamic header padding
local fn = vim.fn

View File

@ -65,6 +65,6 @@ local options = {
}
-- check for any override
options = nvchad.load_override(options, "akinsho/bufferline.nvim")
options = require("core.utils").load_override(options, "akinsho/bufferline.nvim")
bufferline.setup(options)

View File

@ -23,9 +23,9 @@ local cmp_window = require "cmp.utils.window"
cmp_window.info_ = cmp_window.info
cmp_window.info = function(self)
local info = self:info_()
info.scrollable = false
return info
local info = self:info_()
info.scrollable = false
return info
end
local options = {
@ -96,6 +96,6 @@ local options = {
}
-- check for any override
options = nvchad.load_override(options, "hrsh7th/nvim-cmp")
options = require("core.utils").load_override(options, "hrsh7th/nvim-cmp")
cmp.setup(options)

View File

@ -118,6 +118,6 @@ local options = {
}
-- check for any override
options = nvchad.load_override(options, "kyazdani42/nvim-web-devicons")
options = require("core.utils").load_override(options, "kyazdani42/nvim-web-devicons")
devicons.setup(options)

View File

@ -31,6 +31,6 @@ local options = {
max_concurrent_installers = 20,
}
options = nvchad.load_override(options, "williamboman/nvim-lsp-installer")
options = require("core.utils").load_override(options, "williamboman/nvim-lsp-installer")
lsp_installer.setup(options)

View File

@ -22,8 +22,8 @@ M.on_attach = function(client, bufnr)
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
local lsp_mappings = nvchad.load_config().mappings.lspconfig
nvchad.load_mappings({ lsp_mappings }, { buffer = bufnr })
local lsp_mappings = require("core.utils").load_config().mappings.lspconfig
require("core.utils").load_mappings({ lsp_mappings }, { buffer = bufnr })
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
@ -68,7 +68,7 @@ lspconfig.sumneko_lua.setup {
}
-- requires a file containing user's lspconfigs
local addlsp_confs = nvchad.load_config().plugins.options.lspconfig.setup_lspconf
local addlsp_confs = require("core.utils").load_config().plugins.options.lspconfig.setup_lspconf
if #addlsp_confs ~= 0 then
require(addlsp_confs).setup_lsp(M.on_attach, capabilities)

View File

@ -78,6 +78,6 @@ local options = {
}
-- check for any override
options = nvchad.load_override(options, "kyazdani42/nvim-tree.lua")
options = require("core.utils").load_override(options, "kyazdani42/nvim-tree.lua")
nvimtree.setup(options)

View File

@ -27,6 +27,6 @@ local options = {
enable_new_mappings = true,
}
options = nvchad.load_override(options, "NvChad/nvterm")
options = require("core.utils").load_override(options, "NvChad/nvterm")
nvterm.setup(options)

View File

@ -1,5 +1,7 @@
local M = {}
local load_override = require("core.utils").load_override
M.autopairs = function()
local present1, autopairs = pcall(require, "nvim-autopairs")
local present2, cmp = pcall(require, "cmp")
@ -32,7 +34,7 @@ M.better_escape = function()
keys = "<Esc>",
}
options = nvchad.load_override(options, "max397574/better-escape.nvim")
options = load_override(options, "max397574/better-escape.nvim")
escape.setup(options)
end
@ -63,7 +65,7 @@ M.blankline = function()
show_first_indent_level = false,
}
options = nvchad.load_override(options, "lukas-reineke/indent-blankline.nvim")
options = load_override(options, "lukas-reineke/indent-blankline.nvim")
blankline.setup(options)
end
@ -93,7 +95,7 @@ M.colorizer = function()
},
}
options = nvchad.load_override(options, "NvChad/nvim-colorizer.lua")
options = load_override(options, "NvChad/nvim-colorizer.lua")
colorizer.setup(options["filetypes"], options["user_default_options"])
vim.cmd "ColorizerReloadAllBuffers"
@ -149,7 +151,7 @@ M.signature = function()
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
}
options = nvchad.load_override(options, "ray-x/lsp_signature.nvim")
options = load_override(options, "ray-x/lsp_signature.nvim")
lsp_signature.setup(options)
end

View File

@ -50,7 +50,7 @@ options.icon_styles = {
},
}
options.separator_style = options.icon_styles[nvchad.load_config().plugins.options.statusline.separator_style]
options.separator_style = options.icon_styles[require("core.utils").load_config().plugins.options.statusline.separator_style]
options.main_icon = {
provider = options.separator_style.main_icon,
@ -312,7 +312,7 @@ options.current_line = {
hl = "Feline_CurrentLine",
}
options = nvchad.load_override(options, "feline-nvim/feline.nvim")
options = require("core.utils").load_override(options, "feline-nvim/feline.nvim")
local function add_table(tbl, inject)
if inject then

View File

@ -59,7 +59,7 @@ local options = {
}
-- check for any override
options = nvchad.load_override(options, "nvim-telescope/telescope.nvim")
options = require("core.utils").load_override(options, "nvim-telescope/telescope.nvim")
telescope.setup(options)
-- load extensions

View File

@ -16,6 +16,6 @@ local options = {
}
-- check for any override
options = nvchad.load_override(options, "nvim-treesitter/nvim-treesitter")
options = require("core.utils").load_override(options, "nvim-treesitter/nvim-treesitter")
treesitter.setup(options)

View File

@ -34,15 +34,17 @@ local options = {
},
}
options = nvchad.load_override(options, "folke/which-key.nvim")
options = require("core.utils").load_override(options, "folke/which-key.nvim")
local mappings = nvchad.load_config().mappings
local utils = require "core.utils"
local mappings = utils.load_config().mappings
local mapping_groups = { groups = vim.deepcopy(mappings.groups) }
mappings.disabled = nil
mappings.groups = nil
nvchad.load_mappings()
nvchad.load_mappings(mapping_groups)
utils.load_mappings()
utils.load_mappings(mapping_groups)
wk.setup(options)

View File

@ -71,9 +71,7 @@ local plugins = {
config = function()
require("plugins.configs.others").gitsigns()
end,
setup = function()
nvchad.packer_lazy_load "gitsigns.nvim"
end,
setup = require("core.utils").packer_lazy_load "gitsigns.nvim",
},
-- lsp stuff
@ -81,7 +79,7 @@ local plugins = {
["williamboman/nvim-lsp-installer"] = {
opt = true,
setup = function()
nvchad.packer_lazy_load "nvim-lsp-installer"
require("core.utils").packer_lazy_load "nvim-lsp-installer"
-- reload the current file so lsp actually starts for it
vim.defer_fn(function()
vim.cmd 'if &ft == "packer" | echo "" | else | silent! e %'
@ -107,9 +105,7 @@ local plugins = {
["andymass/vim-matchup"] = {
opt = true,
setup = function()
nvchad.packer_lazy_load "vim-matchup"
end,
setup = require("core.utils").packer_lazy_load "vim-matchup",
},
["max397574/better-escape.nvim"] = {
@ -202,9 +198,7 @@ local plugins = {
["folke/which-key.nvim"] = {
opt = true,
setup = function()
nvchad.packer_lazy_load "which-key.nvim"
end,
setup = require("core.utils").packer_lazy_load "which-key.nvim",
config = function()
require "plugins.configs.whichkey"
end,