1
0
Fork 1

refactor nvim config

This commit is contained in:
Snoweuph 2024-09-07 17:55:27 +02:00
parent 6a44ad582a
commit ea9c42e1e4
Signed by: Snoweuph
GPG key ID: 4014606F050AEF63
16 changed files with 112 additions and 89 deletions

View file

@ -11,7 +11,7 @@ if not vim.loop.fs_stat(lazypath) then
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
local plugins = require('util.toolchain').plugins local plugins = require('toolchain').plugins
table.insert(plugins, 1, { import = 'editor' }) table.insert(plugins, 1, { import = 'editor' })
require('lazy').setup({ require('lazy').setup({

View file

@ -8,7 +8,7 @@ return {
auto_install = true, auto_install = true,
highlight = { enable = true }, highlight = { enable = true },
indent = { enable = true }, indent = { enable = true },
ensure_installed = require('util.toolchain').highlighters, ensure_installed = require('toolchain').highlighters,
}) })
end, end,
} }

View file

@ -1,4 +1,4 @@
local TOOLCHAIN = require('util.toolchain') local TOOLCHAIN = require('toolchain')
return { return {
{ {
@ -26,8 +26,8 @@ return {
local capabilities = require('cmp_nvim_lsp').default_capabilities() local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require('lspconfig') local lspconfig = require('lspconfig')
for _, setup in ipairs(TOOLCHAIN.lsp_setups) do for _, lsp in ipairs(TOOLCHAIN.language_servers) do
setup(lspconfig, capabilities) lsp.setup(lspconfig, capabilities)
end end
-- Keybinding -- -- Keybinding --
@ -68,7 +68,7 @@ return {
local null_ls = require('null-ls') local null_ls = require('null-ls')
local null_ls_sources = {} 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) local conf = setup_function(null_ls)
if #conf ~= 0 then if #conf ~= 0 then
for _, _conf in pairs(conf) do for _, _conf in pairs(conf) do

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.config.actions'), actions = require('toolchain.config.actions'),
diagnostics = require('toolchain.config.diagnostics'), diagnostics = require('toolchain.config.diagnostics'),
debuggers = require('toolchain.config.debugger'), debuggers = require('toolchain.config.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.database.actions'), actions = require('toolchain.database.actions'),
diagnostics = require('toolchain.database.diagnostics'), diagnostics = require('toolchain.database.diagnostics'),
debuggers = require('toolchain.database.debugger'), debuggers = require('toolchain.database.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.frontend.actions'), actions = require('toolchain.frontend.actions'),
diagnostics = require('toolchain.frontend.diagnostics'), diagnostics = require('toolchain.frontend.diagnostics'),
debuggers = require('toolchain.frontend.debugger'), debuggers = require('toolchain.frontend.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.generic.actions'), actions = require('toolchain.generic.actions'),
diagnostics = require('toolchain.generic.diagnostics'), diagnostics = require('toolchain.generic.diagnostics'),
debuggers = require('toolchain.generic.debugger'), debuggers = require('toolchain.generic.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.git.actions'), actions = require('toolchain.git.actions'),
diagnostics = require('toolchain.git.diagnostics'), diagnostics = require('toolchain.git.diagnostics'),
debuggers = require('toolchain.git.debugger'), debuggers = require('toolchain.git.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.go.actions'), actions = require('toolchain.go.actions'),
diagnostics = require('toolchain.go.diagnostics'), diagnostics = require('toolchain.go.diagnostics'),
debuggers = require('toolchain.go.debugger'), debuggers = require('toolchain.go.debugger'),
should_init = function() return true end,
} }

106
lua/toolchain/init.lua Normal file
View 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[]

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.lua.actions'), actions = require('toolchain.lua.actions'),
diagnostics = require('toolchain.lua.diagnostics'), diagnostics = require('toolchain.lua.diagnostics'),
debuggers = require('toolchain.lua.debugger'), debuggers = require('toolchain.lua.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.php.actions'), actions = require('toolchain.php.actions'),
diagnostics = require('toolchain.php.diagnostics'), diagnostics = require('toolchain.php.diagnostics'),
debuggers = require('toolchain.php.debugger'), debuggers = require('toolchain.php.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.scripts.actions'), actions = require('toolchain.scripts.actions'),
diagnostics = require('toolchain.scripts.diagnostics'), diagnostics = require('toolchain.scripts.diagnostics'),
debuggers = require('toolchain.scripts.debugger'), debuggers = require('toolchain.scripts.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.text.actions'), actions = require('toolchain.text.actions'),
diagnostics = require('toolchain.text.diagnostics'), diagnostics = require('toolchain.text.diagnostics'),
debuggers = require('toolchain.text.debugger'), debuggers = require('toolchain.text.debugger'),
should_init = function() return true end,
} }

View file

@ -6,5 +6,4 @@ return {
actions = require('toolchain.web.actions'), actions = require('toolchain.web.actions'),
diagnostics = require('toolchain.web.diagnostics'), diagnostics = require('toolchain.web.diagnostics'),
debuggers = require('toolchain.web.debugger'), debuggers = require('toolchain.web.debugger'),
should_init = function() return true end,
} }

View file

@ -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