This commit is contained in:
siduck 2021-11-13 21:59:31 +05:30
parent fd668e559e
commit c8a27d701c
6 changed files with 10 additions and 74 deletions

View File

@ -1,22 +1,5 @@
local function isModuleAvailable(name) local moduleExists = pcall(require, "custom")
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == "function" then
package.preload[name] = loader
return true
end
end
return false
end
end
local loadIfExists = function(module) if moduleExists then
if isModuleAvailable(module) then require "custom"
require(module)
end end
end
loadIfExists "custom"

View File

@ -1,4 +1,4 @@
local hooks, overrides, M = {}, {}, {} local hooks, M = {}, {}
local allowed_hooks = { local allowed_hooks = {
"install_plugins", "install_plugins",
"setup_mappings", "setup_mappings",
@ -11,13 +11,11 @@ local function has_value(tab, val)
return true return true
end end
end end
return false
end end
M.add = function(name, fn) M.add = function(name, fn)
if not (has_value(allowed_hooks, name)) then if not (has_value(allowed_hooks, name)) then
error("Custom lua uses unallowed hook " .. name) print("Custom lua uses unallowed hook " .. name)
end end
if hooks[name] == nil then if hooks[name] == nil then
hooks[name] = {} hooks[name] = {}
@ -26,43 +24,11 @@ M.add = function(name, fn)
end end
M.run = function(name, args) M.run = function(name, args)
if hooks[name] == nil then if hooks[name] ~= nil then
return
end
for _, hook in pairs(hooks[name]) do for _, hook in pairs(hooks[name]) do
hook(args) hook(args)
end end
end end
M.createOverrides = function(module)
local O = {}
O.get = function(name, default)
local current = default
if overrides[module] and overrides[module][name] then
if type(overrides[module][name]) == "function" then
current = overrides[module][name]
elseif type(overrides[module][name]) == "table" then
for _, override in pairs(overrides[module][name]) do
current = override(current)
end
end
end
return current
end
return O
end
M.override = function(module, name, overwrite)
if overrides[module] == nil then
overrides[module] = {}
end
if overrides[module][name] == nil then
overrides[module][name] = {}
end
table.insert(overrides[module][name], overwrite)
end end
return M return M

View File

@ -5,8 +5,6 @@ local core_modules = {
"core.mappings", "core.mappings",
} }
local hooks = require "core.hooks"
for _, module in ipairs(core_modules) do for _, module in ipairs(core_modules) do
local ok, err = pcall(require, module) local ok, err = pcall(require, module)
if not ok then if not ok then
@ -16,5 +14,3 @@ end
-- set all the non plugin mappings -- set all the non plugin mappings
require("core.mappings").misc() require("core.mappings").misc()
hooks.run "ready"

View File

@ -1,9 +1,6 @@
local opt = vim.opt local opt = vim.opt
local g = vim.g local g = vim.g
-- export user config as a global varibale
g.nvchad_user_config = "chadrc"
local options = require("core.utils").load_config().options local options = require("core.utils").load_config().options
opt.title = true opt.title = true

View File

@ -154,7 +154,7 @@ M.load_config = function(reload)
} }
local default_config = "core.default_config" local default_config = "core.default_config"
local config_name = vim.g.nvchad_user_config or "chadrc" local config_name = "chadrc"
local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. config_name .. ".lua" local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. config_name .. ".lua"
-- unload the modules if force reload -- unload the modules if force reload

View File

@ -1,5 +1,3 @@
local overrides = require("core.hooks").createOverrides "lsp"
local function on_attach(_, bufnr) local function on_attach(_, bufnr)
local function buf_set_keymap(...) local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...) vim.api.nvim_buf_set_keymap(bufnr, ...)
@ -62,7 +60,7 @@ lspSymbol("Information", "")
lspSymbol("Hint", "") lspSymbol("Hint", "")
lspSymbol("Warning", "") lspSymbol("Warning", "")
local lsp_publish_diagnostics_options = overrides.get("publish_diagnostics", { vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = { virtual_text = {
prefix = "", prefix = "",
spacing = 0, spacing = 0,
@ -71,10 +69,6 @@ local lsp_publish_diagnostics_options = overrides.get("publish_diagnostics", {
underline = true, underline = true,
update_in_insert = false, -- update diagnostics insert mode update_in_insert = false, -- update diagnostics insert mode
}) })
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics,
lsp_publish_diagnostics_options
)
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = "single", border = "single",
}) })