diff options
author | kylo252 <[email protected]> | 2021-08-15 17:38:47 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-08-15 20:08:47 +0430 |
commit | 6eb75c5678ddb4d040f644e331e222078b99b3a1 (patch) | |
tree | 9830028d434cb9cc4e830346fc40ce392db29721 | |
parent | f36fd1907fd2480c766d96c65e1aebe69e5c855f (diff) |
[Refactor] Clean-up redundant module-load checks (#1011)
-rw-r--r-- | .pre-commit-config.yaml | 5 | ||||
-rw-r--r-- | lua/core/compe.lua | 7 | ||||
-rw-r--r-- | lua/core/dap.lua | 7 | ||||
-rw-r--r-- | lua/core/gitsigns.lua | 8 | ||||
-rw-r--r-- | lua/core/telescope.lua | 2 | ||||
-rw-r--r-- | lua/core/terminal.lua | 17 | ||||
-rw-r--r-- | lua/core/which-key.lua | 16 | ||||
-rw-r--r-- | lua/plugins.lua | 10 |
8 files changed, 15 insertions, 57 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3e3e7d34..9172b0f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,8 +4,7 @@ repos: - id: shfmt name: shfmt minimum_pre_commit_version: 2.4.0 - language: golang - additional_dependencies: [mvdan.cc/sh/v3/cmd/[email protected]] + language: system entry: shfmt args: [-i=2, -ci, -w] types: [shell] @@ -21,7 +20,7 @@ repos: language: rust entry: stylua types: [lua] - args: [.] + args: ['-'] - id: luacheck name: luacheck language: system diff --git a/lua/core/compe.lua b/lua/core/compe.lua index c2f97e27..b5b37805 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.compe = { enabled = true, @@ -61,11 +60,7 @@ end M.setup = function() vim.g.vsnip_snippet_dir = lvim.vsnip_dir - local status_ok, compe = pcall(require, "compe") - if not status_ok then - Log:get_default().error "Failed to load compe" - return - end + local compe = require "compe" compe.setup(lvim.builtin.compe) diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 4e21cc4c..259ff87e 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.dap = { active = false, @@ -13,11 +12,7 @@ M.config = function() end M.setup = function() - local status_ok, dap = pcall(require, "dap") - if not status_ok then - Log:get_default().error "Failed to load dap" - return - end + local dap = require "dap" vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 9e023762..0c0efa91 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.gitsigns = { signs = { @@ -49,12 +48,7 @@ M.config = function() end M.setup = function() - local status_ok, gitsigns = pcall(require, "gitsigns") - if not status_ok then - Log:get_default().error "Failed to load gitsigns" - return - end - gitsigns.setup(lvim.builtin.gitsigns) + require("gitsigns").setup(lvim.builtin.gitsigns) end return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 30533b65..d31edef9 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" function M.config() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then @@ -114,6 +113,7 @@ end function M.setup() local status_ok, telescope = pcall(require, "telescope") if not status_ok then + local Log = require "core.log" Log:get_default().error "Failed to load telescope" return end diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 818038fd..661e5b3b 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" local utils = require "utils" M.config = function() @@ -46,22 +45,13 @@ M.config = function() end M.setup = function() - local status_ok, terminal = pcall(require, "toggleterm") - if not status_ok then - Log:get_default().error "Failed to load toggleterm" - print(terminal) - return - end + local terminal = require "toggleterm" for _, exec in pairs(lvim.builtin.terminal.execs) do require("core.terminal").add_exec(exec[1], exec[2], exec[3]) end terminal.setup(lvim.builtin.terminal) end -local function is_installed(exe) - return vim.fn.executable(exe) == 1 -end - M.add_exec = function(exec, keymap, name) vim.api.nvim_set_keymap( "n", @@ -85,8 +75,9 @@ end M._exec_toggle = function(exec) local binary = M._split(exec)[1] - if is_installed(binary) ~= true then - print("Please install executable " .. binary .. ". Check documentation for more information") + if vim.fn.executable(binary) ~= 1 then + local Log = require "core.log" + Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end local Terminal = require("toggleterm.terminal").Terminal diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 66e3ffbb..04f892d8 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.which_key = { active = false, @@ -230,14 +229,7 @@ M.config = function() end M.setup = function() - -- if not package.loaded['which-key'] then - -- return - -- end - local status_ok, which_key = pcall(require, "which-key") - if not status_ok then - Log:get_default "Failed to load whichkey" - return - end + local which_key = require "which-key" which_key.setup(lvim.builtin.which_key.setup) @@ -247,10 +239,8 @@ M.setup = function() local mappings = lvim.builtin.which_key.mappings local vmappings = lvim.builtin.which_key.vmappings - local wk = require "which-key" - - wk.register(mappings, opts) - wk.register(vmappings, vopts) + which_key.register(mappings, opts) + which_key.register(vmappings, vopts) end return M diff --git a/lua/plugins.lua b/lua/plugins.lua index 8e497075..5353de5b 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -131,15 +131,9 @@ return { "terrortylor/nvim-comment", event = "BufRead", config = function() - local status_ok, nvim_comment = pcall(require, "nvim_comment") - if not status_ok then - local Log = require "core.log" - Log:get_default().error "Failed to load nvim-comment" - return - end - nvim_comment.setup() + require("nvim_comment").setup() if lvim.builtin.comment.on_config_done then - lvim.builtin.comment.on_config_done(nvim_comment) + lvim.builtin.comment.on_config_done(require "nvim_comment") end end, }, |