Use mason-tool-installer to install packages for conform
This commit is contained in:
parent
e795252784
commit
65aa251f02
|
@ -2,9 +2,6 @@
|
|||
local slow_format_filetypes = {}
|
||||
return {
|
||||
"stevearc/conform.nvim",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
},
|
||||
event = { "BufWritePre" },
|
||||
cmd = { "ConformInfo" },
|
||||
keys = {
|
||||
|
|
|
@ -4,27 +4,83 @@ return {
|
|||
dependencies = {
|
||||
{ "mason-org/mason.nvim", opts = {} },
|
||||
"mason-org/mason-lspconfig.nvim",
|
||||
"zapling/mason-conform.nvim",
|
||||
},
|
||||
config = function()
|
||||
local lsp = require("tools.lsp")
|
||||
|
||||
local ensure_installed = vim.tbl_values(vim.tbl_map(function(tool)
|
||||
-- Convert lsp entries to consistent format
|
||||
local tools = {}
|
||||
for _, tool in pairs(lsp) do
|
||||
if type(tool) == "table" then
|
||||
if not tool.system then
|
||||
return {
|
||||
tool[1],
|
||||
condition = tool.condition,
|
||||
}
|
||||
tools[tool[1]] = tool
|
||||
else
|
||||
tools[tool] = { tool }
|
||||
end
|
||||
end
|
||||
|
||||
-- Convert formatters to same format and merge on top of the lsps
|
||||
-- TODO: Clean up this function
|
||||
local formatters_by_ft = require("conform").formatters_by_ft
|
||||
local mapping = require("mason-conform.mapping")
|
||||
for _, formatter in pairs(formatters_by_ft) do
|
||||
local entry = {}
|
||||
if type(formatter) == "table" then
|
||||
for _, tool in pairs(formatter) do
|
||||
local sub_entry = {}
|
||||
local name = nil
|
||||
if type(tool) == "table" then
|
||||
tool[1] = mapping.conform_to_package[tool[1]]
|
||||
name = tool[1]
|
||||
sub_entry = tool
|
||||
else
|
||||
name = mapping.conform_to_package[tool]
|
||||
name = name
|
||||
sub_entry = { name }
|
||||
end
|
||||
if name ~= nil then
|
||||
if entry[name] ~= nil then
|
||||
entry[name] = vim.tbl_extend("keep", entry[name], sub_entry)
|
||||
else
|
||||
entry[name] = sub_entry
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
return tool
|
||||
local name = mapping.conform_to_package[formatter]
|
||||
if name ~= nil then
|
||||
if entry[name] == nil then
|
||||
entry[name] = { name }
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end, lsp))
|
||||
|
||||
for key, value in pairs(entry) do
|
||||
if tools[key] ~= nil then
|
||||
tools[key] = vim.tbl_extend("keep", tools[key], value)
|
||||
else
|
||||
tools[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local ensure_installed = vim.iter(tools)
|
||||
:map(function(_, tool)
|
||||
if type(tool) == "table" then
|
||||
if tool.system then
|
||||
return nil
|
||||
end
|
||||
|
||||
return { tool[1], condition = tool.condition }
|
||||
end
|
||||
return tool
|
||||
end)
|
||||
:totable()
|
||||
|
||||
require("mason-tool-installer").setup({
|
||||
ensure_installed = ensure_installed,
|
||||
auto_update = true,
|
||||
debounde_hours = 24,
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
@ -36,12 +92,4 @@ return {
|
|||
"neovim/nvim-lspconfig",
|
||||
},
|
||||
},
|
||||
{
|
||||
"zapling/mason-conform.nvim",
|
||||
opts = {},
|
||||
dependencies = {
|
||||
{ "mason-org/mason.nvim", opts = {} },
|
||||
"stevearc/conform.nvim",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user