pull/630/head
siduck 3 years ago
parent fd668e559e
commit c8a27d701c

@ -1,22 +1,5 @@
local function isModuleAvailable(name)
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 moduleExists = pcall(require, "custom")
local loadIfExists = function(module)
if isModuleAvailable(module) then
require(module)
end
if moduleExists then
require "custom"
end
loadIfExists "custom"

@ -1,4 +1,4 @@
local hooks, overrides, M = {}, {}, {}
local hooks, M = {}, {}
local allowed_hooks = {
"install_plugins",
"setup_mappings",
@ -11,13 +11,11 @@ local function has_value(tab, val)
return true
end
end
return false
end
M.add = function(name, fn)
if not (has_value(allowed_hooks, name)) then
error("Custom lua uses unallowed hook " .. name)
print("Custom lua uses unallowed hook " .. name)
end
if hooks[name] == nil then
hooks[name] = {}
@ -26,43 +24,11 @@ M.add = function(name, fn)
end
M.run = function(name, args)
if hooks[name] == nil then
return
end
for _, hook in pairs(hooks[name]) do
hook(args)
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
if hooks[name] ~= nil then
for _, hook in pairs(hooks[name]) do
hook(args)
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
return M

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

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

@ -154,7 +154,7 @@ M.load_config = function(reload)
}
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"
-- unload the modules if force reload

@ -1,5 +1,3 @@
local overrides = require("core.hooks").createOverrides "lsp"
local function on_attach(_, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
@ -62,7 +60,7 @@ lspSymbol("Information", "")
lspSymbol("Hint", "")
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 = {
prefix = "",
spacing = 0,
@ -71,10 +69,6 @@ local lsp_publish_diagnostics_options = overrides.get("publish_diagnostics", {
underline = true,
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, {
border = "single",
})

Loading…
Cancel
Save