Browse Source

refact: Switched `is_plugin_disabled` to `is_module_enabled`

my-config
connorgmeean 3 years ago
parent
commit
71e0edb528
  1. 2
      init.lua
  2. 6
      lua/doom/core/functions.lua
  3. 4
      lua/doom/core/init.lua
  4. 10
      lua/doom/modules/core/doom/init.lua
  5. 20
      lua/doom/modules/core/nest/init.lua
  6. 4
      lua/doom/modules/core/treesitter/init.lua
  7. 6
      lua/doom/modules/features/auto_install/init.lua
  8. 8
      lua/doom/modules/features/dashboard/init.lua
  9. 6
      lua/doom/modules/features/explorer/init.lua
  10. 9
      lua/doom/modules/features/lsp/init.lua
  11. 6
      lua/doom/modules/features/statusline/init.lua
  12. 4
      lua/doom/modules/features/telescope/init.lua
  13. 6
      lua/doom/modules/langs/utils.lua
  14. 2
      lua/doom/utils/init.lua
  15. 2
      modules.lua

2
init.lua

@ -20,7 +20,7 @@ utils.load_modules("doom", { "modules" })
vim.defer_fn(function()
-- Start dashboard if it is enabled and an empty buffer is opened initially.
if
not require("doom.utils").is_plugin_disabled("dashboard")
require("doom.utils").is_module_enabled("dashboard")
and (vim.api.nvim_buf_get_number(0) > 1
or vim.api.nvim_buf_get_lines(0, 0, 1, false)[1]:len() == 0)
and vim.api.nvim_buf_get_name(0):len() == 0 -- Empty buffer name

6
lua/doom/core/functions.lua

@ -4,7 +4,7 @@ local utils = require("doom.utils")
local fs = require("doom.utils.fs")
local system = require("doom.core.system")
local async = require("doom.utils.async")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
local functions = {}
@ -383,7 +383,7 @@ functions.toggle_background = function()
end
-- Only define if lsp enabled, it only makes sense there.
if not is_plugin_disabled("lsp") then
if is_module_enabled("lsp") then
-- Toggle completion (by running cmp setup again).
functions.toggle_completion = function()
_doom.cmp_enable = not _doom.cmp_enable
@ -440,7 +440,7 @@ functions.change_number = function()
end
-- Toggle autopairs.
if not is_plugin_disabled("autopairs") then
if is_module_enabled("autopairs") then
functions.toggle_autopairs = function()
local autopairs = require("nvim-autopairs")
if autopairs.state.disabled then

4
lua/doom/core/init.lua

@ -3,13 +3,13 @@
--- (ui, options, doomrc, etc)
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
-- Required setup modules.
local core_modules = { "commands", "ui" }
-- If the explorer is disabled, the user probably wants a better netrw.
-- Otherwise, don't bother configuring it.
if is_plugin_disabled("explorer") then
if is_module_enabled("explorer") then
table.insert(core_modules, "netrw")
end
utils.load_modules("doom.core", core_modules)

10
lua/doom/modules/core/doom/init.lua

@ -3,7 +3,6 @@ local required = {}
required.settings = {
mapper = {},
}
local is_plugin_disabled = require("doom.utils").is_plugin_disabled
required.uses = {
["packer.nvim"] = {
@ -27,7 +26,6 @@ required.uses = {
},
["nvim-mapper"] = {
"lazytanuki/nvim-mapper",
before = is_plugin_disabled("telescope") or "telescope.nvim",
},
['nvim-web-devicons'] = {
'kyazdani42/nvim-web-devicons',
@ -43,7 +41,7 @@ end
required.binds = function ()
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
local binds = {
{ "ZZ", require("doom.core.functions").quit_doom, name = "Fast exit" },
@ -124,7 +122,7 @@ required.binds = function ()
table.insert(binds, { esc_seq, "<ESC>", mode = "i" })
end
if is_plugin_disabled("explorer") then
if is_module_enabled("explorer") then
table.insert(binds, { "<F3>", ":Lexplore%s<CR>", name = "Toggle explorer" })
table.insert(binds, {
"<leader>",
@ -314,7 +312,7 @@ required.binds = function ()
end
required.autocmds = function ()
local is_plugin_disabled = require("doom.utils").is_plugin_disabled
local is_module_enabled = require("doom.utils").is_module_enabled
local autocmds = {}
@ -340,7 +338,7 @@ required.autocmds = function ()
})
end
if is_plugin_disabled("explorer") then
if is_module_enabled("explorer") then
table.insert(autocmds, {
"FileType",
"netrw",

20
lua/doom/modules/core/nest/init.lua

@ -14,21 +14,35 @@ nest.uses = {
nest.configs = {}
nest.configs["nest.nvim"] = function()
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
local nest_package = require("nest")
nest_package.enable(require("nest.integrations.mapper"))
if not is_plugin_disabled("whichkey") then
if is_module_enabled("whichkey") then
local whichkey_integration = require("nest.integrations.whichkey")
nest_package.enable(whichkey_integration)
end
for _, module in pairs(doom.modules) do
local last_module = '';
local ok, err = xpcall(function()
for module_name, module in pairs(doom.modules) do
last_module = module_name
if module.binds then
nest_package.applyKeymaps(type(module.binds) == 'function' and module.binds() or module.binds)
end
end
end, debug.traceback)
if not ok and err then
local log = require("doom.utils.logging")
log.error(
string.format(
"There was an error setting keymaps for module '%s'. Traceback:\n%s",
last_module,
err
)
)
end
end
return nest

4
lua/doom/modules/core/treesitter/init.lua

@ -60,10 +60,10 @@ treesitter.uses = {
treesitter.configs = {}
treesitter.configs["nvim-treesitter"] = function()
local is_plugin_disabled = require("doom.utils").is_plugin_disabled
local is_module_enabled = require("doom.utils").is_module_enabled
require("nvim-treesitter.configs").setup(vim.tbl_deep_extend("force", doom.modules.treesitter.settings.treesitter, {
autopairs = {
enable = not is_plugin_disabled("autopairs"),
enable = is_module_enabled("autopairs"),
},
}))

6
lua/doom/modules/features/auto_install/init.lua

@ -5,7 +5,7 @@ auto_install.settings = {
dap_dir = vim.fn.stdpath("data") .. "/dap-install",
}
local is_plugin_disabled = require("doom.utils").is_plugin_disabled
local is_module_enabled = require("doom.utils").is_module_enabled
auto_install.uses = {
["DAPInstall.nvim"] = {
@ -17,7 +17,7 @@ auto_install.uses = {
"DIList",
"DIUninstall",
},
disabled = is_plugin_disabled("dap"),
disabled = not is_module_enabled("dap"),
module = "dap-install",
disable = true,
},
@ -25,7 +25,7 @@ auto_install.uses = {
"williamboman/nvim-lsp-installer",
commit = "29154c2fe1147c8eed5d54a419841e5637a8c3b2",
opt = true,
disabled = is_plugin_disabled("lsp"),
disabled = not is_module_enabled("lsp"),
module = "nvim-lsp-install",
},
}

8
lua/doom/modules/features/dashboard/init.lua

@ -67,15 +67,15 @@ dashboard.uses = {
dashboard.configs = {}
dashboard.configs["dashboard-nvim"] = function()
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
if not is_plugin_disabled("auto_session") then
if is_module_enabled("auto_session") then
vim.g.dashboard_session_directory = doom.modules.auto_session.settings.dir
end
if not is_plugin_disabled("telescope") then
if is_module_enabled("telescope") then
vim.g.dashboard_default_executive = "telescope"
end
if not is_plugin_disabled("auto_session") then
if is_module_enabled("auto_session") then
doom.modules.dashboard.settings.entries.a = {
description = { " Load Last Session SPC s r" },
command = [[lua require("persistence").load({ last = true })]],

6
lua/doom/modules/features/explorer/init.lua

@ -93,7 +93,7 @@ explorer.uses = {
explorer.configs = {}
explorer.configs["nvim-tree.lua"] = function()
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
local tree_cb = require("nvim-tree.config").nvim_tree_callback
@ -132,7 +132,7 @@ explorer.configs["nvim-tree.lua"] = function()
vim.g.nvim_tree_show_icons = show_icons
local override_icons = {}
if not is_plugin_disabled("lsp") then
if is_module_enabled("lsp") then
override_icons = {
lsp = {
hint = doom.modules.lsp.settings.icons.hint,
@ -149,7 +149,7 @@ explorer.configs["nvim-tree.lua"] = function()
enable = false,
},
}
if not is_plugin_disabled("lsp") then
if is_module_enabled("lsp") then
override_table = {
diagnostics = {
enable = true,

9
lua/doom/modules/features/lsp/init.lua

@ -77,7 +77,7 @@ lsp.settings = {
},
}
local is_plugin_disabled = require("doom.utils").is_plugin_disabled
local is_module_enabled = require("doom.utils").is_module_enabled
lsp.uses = {
["nvim-lspconfig"] = {
"neovim/nvim-lspconfig",
@ -94,7 +94,7 @@ lsp.uses = {
["nvim-cmp"] = {
"hrsh7th/nvim-cmp",
commit = "1001683bee3a52a7b7e07ba9d391472961739c7b",
after = not is_plugin_disabled("snippets") and "LuaSnip" or nil,
after = is_module_enabled("snippets") and "LuaSnip" or nil,
},
["cmp-nvim-lua"] = {
"hrsh7th/cmp-nvim-lua",
@ -120,13 +120,12 @@ lsp.uses = {
"saadparwaiz1/cmp_luasnip",
commit = "d6f837f4e8fe48eeae288e638691b91b97d1737f",
after = "nvim-cmp",
disabled = is_plugin_disabled("snippets"),
disabled = not is_module_enabled("snippets"),
},
["lsp_signature.nvim"] = {
"ray-x/lsp_signature.nvim",
commit = "f7c308e99697317ea572c6d6bafe6d4be91ee164",
after = "nvim-lspconfig",
opt = true,
},
}
@ -197,7 +196,7 @@ lsp.configs["nvim-lspconfig"] = function()
end
lsp.configs["nvim-cmp"] = function()
local utils = require("doom.utils")
local snippets_enabled = not utils.is_plugin_disabled("snippets")
local snippets_enabled = utils.is_module_enabled("snippets")
local cmp = require("cmp")
local luasnip = snippets_enabled and require("luasnip")

6
lua/doom/modules/features/statusline/init.lua

@ -24,7 +24,7 @@ statusline.uses = {
statusline.configs = {}
statusline.configs["galaxyline.nvim"] = function()
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
local gl = require("galaxyline")
local colors = require("galaxyline.themes.colors").get_color
@ -45,7 +45,7 @@ statusline.configs["galaxyline.nvim"] = function()
gl.short_line_list = doom.modules.statusline.settings.short_line_list
if not is_plugin_disabled("dashboard") and not doom.modules.statusline.settings.on_dashboard then
if is_module_enabled("dashboard") and not doom.modules.statusline.settings.on_dashboard then
table.insert(gl.exclude_filetypes, "dashboard")
end
@ -297,7 +297,7 @@ statusline.configs["galaxyline.nvim"] = function()
},
}
if not is_plugin_disabled("lsp") then
if is_module_enabled("lsp") then
table.insert(default_sections.left, {
DiagnosticError = {
provider = "DiagnosticError",

4
lua/doom/modules/features/telescope/init.lua

@ -92,7 +92,7 @@ end
telescope.binds = function ()
local utils = require("doom.utils")
local is_plugin_disabled = utils.is_plugin_disabled
local is_module_enabled = utils.is_module_enabled
local binds = {
"<leader>",
@ -168,7 +168,7 @@ telescope.binds = function ()
},
},
}
if not is_plugin_disabled("lsp") then
if is_module_enabled("lsp") then
table.insert(binds, {
"<leader>",
name = "+prefix",

6
lua/doom/modules/langs/utils.lua

@ -24,7 +24,7 @@ end
module.use_lsp = function(lsp_name, _opts)
local utils = require('doom.utils')
if utils.is_plugin_disabled("lsp") then
if utils.is_module_enabled("lsp") then
return
end
local lsp = require('lspconfig')
@ -40,7 +40,7 @@ module.use_lsp = function(lsp_name, _opts)
-- Combine default on_attach with provided on_attach
local on_attach_functions = {}
if not utils.is_plugin_disabled("illuminate") then
if utils.is_module_enabled("illuminate") then
table.insert(on_attach_functions, utils.illuminate_attach)
end
if (opts.config and opts.config.on_attach) then
@ -74,7 +74,7 @@ module.use_lsp = function(lsp_name, _opts)
end
-- Auto install if possible
if not utils.is_plugin_disabled('auto_install') and not opts.no_installer then
if utils.is_module_enabled('auto_install') and not opts.no_installer then
local lsp_installer = require("nvim-lsp-installer.servers")
local server_available, server = lsp_installer.get_server(lsp_name)
if server_available then

2
lua/doom/utils/init.lua

@ -211,7 +211,7 @@ end
--- Check if the given plugin is disabled in doom-nvim/modules.lua
--- @param plugin string The plugin identifier, e.g. statusline
--- @return boolean
utils.is_plugin_disabled = function(plugin)
utils.is_module_enabled = function(plugin)
local modules = require("doom.core.config.modules").modules
-- Iterate over all modules sections (e.g. ui) and their plugins

2
modules.lua

@ -27,7 +27,7 @@ return {
"todo_comments", -- Highlight TODO: comments
-- UI
"fidget", -- Check status of LSP loading
"lsp_progress", -- Check status of LSP loading
"tabline", -- Tab bar buffer switcher
"dashboard", -- A pretty dashboard upon opening
"trouble", -- A pretty diagnostic viewer

Loading…
Cancel
Save