Reads the machine profile, loads enabled language modules, and aggregates their server configs, treesitter parsers, mason packages, plugin specs, and per-filetype cmp overrides into a single API for plugin specs to consume.
100 lines
2.4 KiB
Lua
100 lines
2.4 KiB
Lua
-- Language orchestrator: reads the machine profile and aggregates language modules.
|
|
local M = {}
|
|
|
|
-- Load machine profile (falls back to profile_default)
|
|
local function load_profile()
|
|
local ok, profile = pcall(require, 'profile')
|
|
if not ok then
|
|
profile = require('profile_default')
|
|
end
|
|
return profile
|
|
end
|
|
|
|
local _initialized = false
|
|
local _servers = {}
|
|
local _parsers = {}
|
|
local _plugins = {}
|
|
local _mason_packages = {}
|
|
local _cmp_filetypes = {}
|
|
|
|
--- Initialize: load profile, require each language module, aggregate their configs.
|
|
function M.setup()
|
|
if _initialized then return end
|
|
_initialized = true
|
|
|
|
local profile = load_profile()
|
|
|
|
for _, lang_name in ipairs(profile.languages) do
|
|
local ok, lang = pcall(require, 'languages.' .. lang_name)
|
|
if ok then
|
|
-- Collect LSP server configs
|
|
for server_name, config in pairs(lang.servers or {}) do
|
|
_servers[server_name] = config
|
|
end
|
|
|
|
-- Collect treesitter parsers (deduplicated)
|
|
for _, parser in ipairs(lang.parsers or {}) do
|
|
if not vim.tbl_contains(_parsers, parser) then
|
|
table.insert(_parsers, parser)
|
|
end
|
|
end
|
|
|
|
-- Collect additional plugin specs
|
|
for _, plugin in ipairs(lang.plugins or {}) do
|
|
table.insert(_plugins, plugin)
|
|
end
|
|
|
|
-- Collect mason packages (deduplicated)
|
|
for _, pkg in ipairs(lang.mason_packages or {}) do
|
|
if not vim.tbl_contains(_mason_packages, pkg) then
|
|
table.insert(_mason_packages, pkg)
|
|
end
|
|
end
|
|
|
|
-- Collect per-filetype cmp source overrides
|
|
for ft, config in pairs(lang.cmp_filetypes or {}) do
|
|
_cmp_filetypes[ft] = config
|
|
end
|
|
else
|
|
vim.notify('Language module not found: ' .. lang_name, vim.log.levels.WARN)
|
|
end
|
|
end
|
|
end
|
|
|
|
--- Get all aggregated LSP server configs.
|
|
function M.servers()
|
|
M.setup()
|
|
return _servers
|
|
end
|
|
|
|
--- Get all aggregated treesitter parsers.
|
|
function M.parsers()
|
|
M.setup()
|
|
return _parsers
|
|
end
|
|
|
|
--- Get all additional plugin specs from language modules.
|
|
function M.plugins()
|
|
M.setup()
|
|
return _plugins
|
|
end
|
|
|
|
--- Get all mason packages to ensure installed.
|
|
function M.mason_packages()
|
|
M.setup()
|
|
return _mason_packages
|
|
end
|
|
|
|
--- Get per-filetype cmp source overrides.
|
|
function M.cmp_filetypes()
|
|
M.setup()
|
|
return _cmp_filetypes
|
|
end
|
|
|
|
--- Get the loaded machine profile.
|
|
function M.profile()
|
|
return load_profile()
|
|
end
|
|
|
|
return M
|