forked from Snoweuph/Dotfiles_nvim
refactor nvim config
This commit is contained in:
parent
6a44ad582a
commit
ea9c42e1e4
16 changed files with 112 additions and 89 deletions
|
@ -11,7 +11,7 @@ if not vim.loop.fs_stat(lazypath) then
|
|||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
local plugins = require('util.toolchain').plugins
|
||||
local plugins = require('toolchain').plugins
|
||||
table.insert(plugins, 1, { import = 'editor' })
|
||||
|
||||
require('lazy').setup({
|
||||
|
|
|
@ -8,7 +8,7 @@ return {
|
|||
auto_install = true,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
ensure_installed = require('util.toolchain').highlighters,
|
||||
ensure_installed = require('toolchain').highlighters,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local TOOLCHAIN = require('util.toolchain')
|
||||
local TOOLCHAIN = require('toolchain')
|
||||
|
||||
return {
|
||||
{
|
||||
|
@ -26,8 +26,8 @@ return {
|
|||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
local lspconfig = require('lspconfig')
|
||||
|
||||
for _, setup in ipairs(TOOLCHAIN.lsp_setups) do
|
||||
setup(lspconfig, capabilities)
|
||||
for _, lsp in ipairs(TOOLCHAIN.language_servers) do
|
||||
lsp.setup(lspconfig, capabilities)
|
||||
end
|
||||
|
||||
-- Keybinding --
|
||||
|
@ -68,7 +68,7 @@ return {
|
|||
local null_ls = require('null-ls')
|
||||
|
||||
local null_ls_sources = {}
|
||||
for _, setup_function in ipairs(TOOLCHAIN.null_ls) do
|
||||
for _, setup_function in ipairs(TOOLCHAIN.diagnostics) do
|
||||
local conf = setup_function(null_ls)
|
||||
if #conf ~= 0 then
|
||||
for _, _conf in pairs(conf) do
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.config.actions'),
|
||||
diagnostics = require('toolchain.config.diagnostics'),
|
||||
debuggers = require('toolchain.config.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.database.actions'),
|
||||
diagnostics = require('toolchain.database.diagnostics'),
|
||||
debuggers = require('toolchain.database.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.frontend.actions'),
|
||||
diagnostics = require('toolchain.frontend.diagnostics'),
|
||||
debuggers = require('toolchain.frontend.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.generic.actions'),
|
||||
diagnostics = require('toolchain.generic.diagnostics'),
|
||||
debuggers = require('toolchain.generic.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.git.actions'),
|
||||
diagnostics = require('toolchain.git.diagnostics'),
|
||||
debuggers = require('toolchain.git.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.go.actions'),
|
||||
diagnostics = require('toolchain.go.diagnostics'),
|
||||
debuggers = require('toolchain.go.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
106
lua/toolchain/init.lua
Normal file
106
lua/toolchain/init.lua
Normal file
|
@ -0,0 +1,106 @@
|
|||
local TOOLCHAINS = {}
|
||||
|
||||
local config = require('toolchain.config')
|
||||
local database = require('toolchain.database')
|
||||
local frontend = require('toolchain.frontend')
|
||||
local generic = require('toolchain.generic')
|
||||
local git = require('toolchain.git')
|
||||
local go = require('toolchain.go')
|
||||
local lua = require('toolchain.lua')
|
||||
local php = require('toolchain.php')
|
||||
local scripts = require('toolchain.scripts')
|
||||
local text = require('toolchain.text')
|
||||
local web = require('toolchain.web')
|
||||
|
||||
TOOLCHAINS.plugins = {
|
||||
table.unpack(config.requirements.plugins),
|
||||
table.unpack(database.requirements.plugins),
|
||||
table.unpack(frontend.requirements.plugins),
|
||||
table.unpack(generic.requirements.plugins),
|
||||
table.unpack(git.requirements.plugins),
|
||||
table.unpack(go.requirements.plugins),
|
||||
table.unpack(lua.requirements.plugins),
|
||||
table.unpack(php.requirements.plugins),
|
||||
table.unpack(scripts.requirements.plugins),
|
||||
table.unpack(text.requirements.plugins),
|
||||
table.unpack(web.requirements.plugins),
|
||||
}
|
||||
|
||||
TOOLCHAINS.highlighters = {
|
||||
table.unpack(config.requirements.highlighters),
|
||||
table.unpack(database.requirements.highlighters),
|
||||
table.unpack(frontend.requirements.highlighters),
|
||||
table.unpack(generic.requirements.highlighters),
|
||||
table.unpack(git.requirements.highlighters),
|
||||
table.unpack(go.requirements.highlighters),
|
||||
table.unpack(lua.requirements.highlighters),
|
||||
table.unpack(php.requirements.highlighters),
|
||||
table.unpack(scripts.requirements.highlighters),
|
||||
table.unpack(text.requirements.highlighters),
|
||||
table.unpack(web.requirements.highlighters),
|
||||
}
|
||||
|
||||
TOOLCHAINS.language_servers = {
|
||||
table.unpack(config.language_servers),
|
||||
table.unpack(database.language_servers),
|
||||
table.unpack(frontend.language_servers),
|
||||
table.unpack(generic.language_servers),
|
||||
table.unpack(git.language_servers),
|
||||
table.unpack(go.language_servers),
|
||||
table.unpack(lua.language_servers),
|
||||
table.unpack(php.language_servers),
|
||||
table.unpack(scripts.language_servers),
|
||||
table.unpack(text.language_servers),
|
||||
table.unpack(web.language_servers),
|
||||
}
|
||||
|
||||
TOOLCHAINS.diagnostics = {
|
||||
table.unpack(config.diagnostics),
|
||||
table.unpack(database.diagnostics),
|
||||
table.unpack(frontend.diagnostics),
|
||||
table.unpack(generic.diagnostics),
|
||||
table.unpack(git.diagnostics),
|
||||
table.unpack(go.diagnostics),
|
||||
table.unpack(lua.diagnostics),
|
||||
table.unpack(php.diagnostics),
|
||||
table.unpack(scripts.diagnostics),
|
||||
table.unpack(text.diagnostics),
|
||||
table.unpack(web.diagnostics),
|
||||
}
|
||||
|
||||
return TOOLCHAINS
|
||||
|
||||
--Type Definitions
|
||||
|
||||
---@class Toolchain
|
||||
---@field requirements ToolchainRequirements
|
||||
---@field formatters ToolchainFormatters
|
||||
---@field language_servers ToolchainLanguageServers
|
||||
---@field actions ToolchainActions
|
||||
---@field diagnostics ToolchainDiagnostics
|
||||
---@field debuggers ToolchainDebuggers
|
||||
|
||||
---@class ToolchainRequirements
|
||||
---@field plugins LazySpec[]
|
||||
---@field highlighters table
|
||||
---@field language_servers table
|
||||
|
||||
---@class ToolchainLanguageServers
|
||||
---@field requirements string[]
|
||||
---@field setup fun(lspconfig:any, capabilities: any)
|
||||
|
||||
---@class ToolchainFormatters
|
||||
---@field plugins LazySpec[]
|
||||
---@field setup fun(null_ls: any):table
|
||||
|
||||
---@class ToolchainActions
|
||||
---@field plugins LazySpec[]
|
||||
---@field setup fun(null_ls: any):table
|
||||
|
||||
---@class ToolchainDiagnostics
|
||||
---@field plugins LazySpec[]
|
||||
---@field setup fun(null_ls: any):table
|
||||
|
||||
---@class ToolchainDebuggers
|
||||
---@field plugins LazySpec[]
|
||||
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.lua.actions'),
|
||||
diagnostics = require('toolchain.lua.diagnostics'),
|
||||
debuggers = require('toolchain.lua.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.php.actions'),
|
||||
diagnostics = require('toolchain.php.diagnostics'),
|
||||
debuggers = require('toolchain.php.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.scripts.actions'),
|
||||
diagnostics = require('toolchain.scripts.diagnostics'),
|
||||
debuggers = require('toolchain.scripts.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.text.actions'),
|
||||
diagnostics = require('toolchain.text.diagnostics'),
|
||||
debuggers = require('toolchain.text.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ return {
|
|||
actions = require('toolchain.web.actions'),
|
||||
diagnostics = require('toolchain.web.diagnostics'),
|
||||
debuggers = require('toolchain.web.debugger'),
|
||||
should_init = function() return true end,
|
||||
}
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
---@class Toolchain
|
||||
---@field should_init fun():boolean
|
||||
---@field requirements ToolchainRequirements
|
||||
---@field formatters ToolchainFormatters
|
||||
---@field language_servers ToolchainLanguageServers
|
||||
---@field actions ToolchainActions
|
||||
---@field diagnostics ToolchainDiagnostics
|
||||
---@field debuggers ToolchainDebuggers
|
||||
|
||||
---@class ToolchainRequirements
|
||||
---@field plugins LazySpec
|
||||
---@field highlighters table
|
||||
---@field language_servers table
|
||||
|
||||
---@class ToolchainLanguageServers
|
||||
---@field requirements string[]
|
||||
---@field setup fun(lspconfig:any, capabilities: any)
|
||||
|
||||
---@class ToolchainFormatters
|
||||
---@field plugins LazySpec[]
|
||||
---@field setup fun(null_ls: any):table
|
||||
|
||||
---@class ToolchainActions
|
||||
---@field plugins LazySpec[]
|
||||
---@field setup fun(null_ls: any):table
|
||||
|
||||
---@class ToolchainDiagnostics
|
||||
---@field plugins LazySpec[]
|
||||
---@field setup fun(null_ls: any):table
|
||||
|
||||
---@class ToolchainDebuggers
|
||||
---@field plugins LazySpec[]
|
||||
|
||||
local TOOLCHAIN = {
|
||||
---@type LazySpec[]
|
||||
plugins = {},
|
||||
---@type string[]
|
||||
highlighters = {},
|
||||
---@type string[]
|
||||
lsp_requriemts = {},
|
||||
---@type (fun(lspconfig, capabilities))[]
|
||||
lsp_setups = {},
|
||||
---@type (fun(null_ls):any)[]
|
||||
null_ls = {},
|
||||
}
|
||||
|
||||
local path = vim.fn.stdpath('config') .. '/lua/toolchain'
|
||||
|
||||
for _, moduleName in ipairs(vim.fn.readdir(path)) do
|
||||
local submodulePath = 'toolchain' .. '.' .. moduleName
|
||||
|
||||
---@type Toolchain
|
||||
local module = require(submodulePath)
|
||||
|
||||
if module.should_init() then
|
||||
for _, plugin in pairs(module.requirements.plugins) do
|
||||
table.insert(TOOLCHAIN.plugins, plugin)
|
||||
end
|
||||
for _, hl in pairs(module.requirements.highlighters) do
|
||||
table.insert(TOOLCHAIN.highlighters, hl)
|
||||
end
|
||||
for _, lsp in pairs(module.requirements.language_servers) do
|
||||
table.insert(TOOLCHAIN.lsp_requriemts, lsp)
|
||||
end
|
||||
table.insert(TOOLCHAIN.lsp_setups, module.language_servers.setup)
|
||||
table.insert(TOOLCHAIN.null_ls, module.formatters.setup)
|
||||
table.insert(TOOLCHAIN.null_ls, module.actions.setup)
|
||||
table.insert(TOOLCHAIN.null_ls, module.diagnostics.setup)
|
||||
end
|
||||
end
|
||||
|
||||
return TOOLCHAIN
|
Loading…
Reference in a new issue