Use mason-tool-installer to install packages for conform
This commit is contained in:
parent
e795252784
commit
8ce9090929
|
@ -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 = {
|
||||||
|
@ -19,7 +16,24 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
formatters_by_ft = require("tools.format"),
|
formatters_by_ft = (function()
|
||||||
|
local formatters = require("tools.format")
|
||||||
|
local formatters_by_ft = {}
|
||||||
|
for lang, formatter in pairs(formatters) do
|
||||||
|
formatters_by_ft[lang] = {}
|
||||||
|
if type(formatter) == "table" then
|
||||||
|
for _, tool in ipairs(formatter) do
|
||||||
|
if type(tool) == "table" then
|
||||||
|
table.insert(formatters_by_ft[lang], tool[1])
|
||||||
|
else
|
||||||
|
table.insert(formatters_by_ft[lang], tool)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return formatters_by_ft
|
||||||
|
end)(),
|
||||||
notify_on_error = false,
|
notify_on_error = false,
|
||||||
format_on_save = function(bufnr)
|
format_on_save = function(bufnr)
|
||||||
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||||
|
|
|
@ -4,27 +4,81 @@ 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
|
local name = tool[1]
|
||||||
return {
|
local entry = {}
|
||||||
tool[1],
|
|
||||||
condition = tool.condition,
|
-- Make a copy and strip out name and lsp config
|
||||||
}
|
for k, v in pairs(tool) do
|
||||||
|
if k ~= 1 and k ~= 2 then
|
||||||
|
entry[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tools[name] = entry
|
||||||
|
else
|
||||||
|
tools[tool] = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Convert formatters to same format and merge on top of the lsps
|
||||||
|
local formatters_by_ft = require("conform").formatters_by_ft
|
||||||
|
local mapping = require("mason-conform.mapping")
|
||||||
|
for _, formatter in pairs(formatters_by_ft) do
|
||||||
|
if type(formatter) == "table" then
|
||||||
|
for _, tool in ipairs(formatter) do
|
||||||
|
local entry = {}
|
||||||
|
local name = nil
|
||||||
|
if type(tool) == "table" then
|
||||||
|
name = mapping.conform_to_package[tool[1]]
|
||||||
|
|
||||||
|
-- Make a copy and strip out name
|
||||||
|
for k, v in pairs(tool) do
|
||||||
|
if k ~= 1 then
|
||||||
|
entry[k] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return tool
|
name = mapping.conform_to_package[tool]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if name ~= nil then
|
||||||
|
tools[name] = vim.tbl_extend("error", tools[name] or {}, entry)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local ensure_installed = vim.iter(tools)
|
||||||
|
:map(function(name, tool)
|
||||||
|
if type(tool) == "table" then
|
||||||
|
if tool.system then
|
||||||
return nil
|
return nil
|
||||||
end, lsp))
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
condition = tool.condition,
|
||||||
|
version = tool.version,
|
||||||
|
auto_update = tool.auto_update,
|
||||||
|
}
|
||||||
|
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 +90,4 @@ return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"zapling/mason-conform.nvim",
|
|
||||||
opts = {},
|
|
||||||
dependencies = {
|
|
||||||
{ "mason-org/mason.nvim", opts = {} },
|
|
||||||
"stevearc/conform.nvim",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ return {
|
||||||
cpp = { "clang-format" },
|
cpp = { "clang-format" },
|
||||||
go = { "goimports", "gofmt" },
|
go = { "goimports", "gofmt" },
|
||||||
python = { "ruff_organize_imports", "ruff_format" },
|
python = { "ruff_organize_imports", "ruff_format" },
|
||||||
rust = { "rustfmt" },
|
rust = { { "rustfmt", system = true } },
|
||||||
javascript = { "prettierd" },
|
javascript = { "prettierd" },
|
||||||
javascriptreact = { "prettierd" },
|
javascriptreact = { "prettierd" },
|
||||||
typescript = { "prettierd" },
|
typescript = { "prettierd" },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user