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 = {}
|
local slow_format_filetypes = {}
|
||||||
return {
|
return {
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
dependencies = {
|
|
||||||
"williamboman/mason.nvim",
|
|
||||||
},
|
|
||||||
event = { "BufWritePre" },
|
event = { "BufWritePre" },
|
||||||
cmd = { "ConformInfo" },
|
cmd = { "ConformInfo" },
|
||||||
keys = {
|
keys = {
|
||||||
|
|
|
@ -4,27 +4,83 @@ return {
|
||||||
dependencies = {
|
dependencies = {
|
||||||
{ "mason-org/mason.nvim", opts = {} },
|
{ "mason-org/mason.nvim", opts = {} },
|
||||||
"mason-org/mason-lspconfig.nvim",
|
"mason-org/mason-lspconfig.nvim",
|
||||||
|
"zapling/mason-conform.nvim",
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local lsp = require("tools.lsp")
|
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 type(tool) == "table" then
|
||||||
if not tool.system then
|
tools[tool[1]] = tool
|
||||||
return {
|
else
|
||||||
tool[1],
|
tools[tool] = { tool }
|
||||||
condition = tool.condition,
|
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
|
end
|
||||||
else
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
return nil
|
||||||
end, lsp))
|
end
|
||||||
|
|
||||||
|
return { tool[1], condition = tool.condition }
|
||||||
|
end
|
||||||
|
return tool
|
||||||
|
end)
|
||||||
|
:totable()
|
||||||
|
|
||||||
require("mason-tool-installer").setup({
|
require("mason-tool-installer").setup({
|
||||||
ensure_installed = ensure_installed,
|
ensure_installed = ensure_installed,
|
||||||
auto_update = true,
|
auto_update = true,
|
||||||
|
debounde_hours = 24,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
@ -36,12 +92,4 @@ return {
|
||||||
"neovim/nvim-lspconfig",
|
"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