dotfiles/home/private_dot_config/nvim/lua/util/init.lua

109 lines
2.3 KiB
Lua
Raw Normal View History

2023-12-17 23:26:30 -06:00
local function setDefault(t, d)
local mt = {
__index = function()
return d
end,
}
setmetatable(t, mt)
end
2025-01-06 14:51:50 -06:00
-- local function setup_lsp(name)
-- return {
-- "neovim/nvim-lspconfig",
-- opts = {
-- servers = {
-- [name] = { mason = false },
-- },
-- },
-- }
-- end
-- local function setup_lang(defs)
-- setDefault(defs, {})
-- return {
-- {
-- "nvim-treesitter/nvim-treesitter",
-- opts = function(_, opts)
-- opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.treesitter)
-- end,
-- },
-- {
-- "williamboman/mason.nvim",
-- opts = function(_, opts)
-- opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.mason)
-- end,
-- },
-- }
-- end
local function lsp_no_mason(server_name)
return {
[server_name] = {
mason = false,
},
}
end
--- generated with the help of claude
2023-12-17 23:26:30 -06:00
local function setup_lang(defs)
setDefault(defs, {})
2025-01-06 14:51:50 -06:00
local result = {
2023-12-17 23:26:30 -06:00
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
2025-01-06 14:51:50 -06:00
opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.treesitter or {})
2023-12-17 23:26:30 -06:00
end,
},
{
"williamboman/mason.nvim",
opts = function(_, opts)
2025-01-06 14:51:50 -06:00
opts.ensure_installed = vim.list_extend(opts.ensure_installed or {}, defs.mason or {})
2023-12-17 23:26:30 -06:00
end,
},
}
2025-01-06 14:51:50 -06:00
-- Handle LSP configuration
if defs.lsp then
table.insert(result, {
"neovim/nvim-lspconfig",
opts = {
servers = {},
},
})
-- i think the result[#result] syntax is taking the "last" index of result
for _, lsp in ipairs(defs.lsp) do
if type(lsp) == "string" then
-- Regular LSP server
result[#result].opts.servers[lsp] = {mason = false}
elseif type(lsp) == "table" and lsp[1] then
-- LSP server with no Mason
result[#result].opts.servers = vim.tbl_deep_extend("force", result[#result].opts.servers, lsp_no_mason(lsp[1]))
end
end
end
return result
2023-12-17 23:26:30 -06:00
end
2025-01-06 14:51:50 -06:00
local function if_exe(exe, deps)
if vim.fn.executable(exe) == 0 then
return {}
end
return deps
end
2025-01-06 14:51:50 -06:00
local function import_if_exe(exe, mod)
return if_exe(exe, { { import = mod } })
end
2023-12-17 23:26:30 -06:00
return {
setup_lang = setup_lang,
if_exe = if_exe,
2025-01-06 14:51:50 -06:00
import_if_exe = import_if_exe,
2023-12-17 23:26:30 -06:00
}