From c8a27d701c5f119a97a2ae619a3138638592ed21 Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 13 Nov 2021 21:59:31 +0530 Subject: [PATCH] cleanup! --- lua/core/custom.lua | 23 +++------------- lua/core/hooks.lua | 44 ++++--------------------------- lua/core/init.lua | 4 --- lua/core/options.lua | 3 --- lua/core/utils.lua | 2 +- lua/plugins/configs/lspconfig.lua | 8 +----- 6 files changed, 10 insertions(+), 74 deletions(-) diff --git a/lua/core/custom.lua b/lua/core/custom.lua index c058061..44c1696 100644 --- a/lua/core/custom.lua +++ b/lua/core/custom.lua @@ -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" diff --git a/lua/core/hooks.lua b/lua/core/hooks.lua index 2602ff7..af70156 100644 --- a/lua/core/hooks.lua +++ b/lua/core/hooks.lua @@ -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 diff --git a/lua/core/init.lua b/lua/core/init.lua index dc1198c..634087f 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -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" diff --git a/lua/core/options.lua b/lua/core/options.lua index 2438b16..5be456d 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -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 diff --git a/lua/core/utils.lua b/lua/core/utils.lua index e9fbd1f..d7fa99b 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -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 diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index be12585..76fe1b0 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -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", })