Use mason-tool-installer to install packages for conform
This commit is contained in:
parent
e795252784
commit
39d01c52ad
|
@ -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,85 @@ 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
|
-- Strip out lsp config
|
||||||
return {
|
tool[2] = nil
|
||||||
tool[1],
|
tools[tool[1]] = tool
|
||||||
condition = tool.condition,
|
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 ipairs(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
|
||||||
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({
|
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 +94,4 @@ return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"zapling/mason-conform.nvim",
|
|
||||||
opts = {},
|
|
||||||
dependencies = {
|
|
||||||
{ "mason-org/mason.nvim", opts = {} },
|
|
||||||
"stevearc/conform.nvim",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
return {
|
return {
|
||||||
c = { "clang-format" },
|
c = "clang-format",
|
||||||
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",
|
||||||
typescriptreact = { "prettierd" },
|
typescriptreact = "prettierd",
|
||||||
css = { "prettierd" },
|
css = "prettierd",
|
||||||
markdown = { "prettierd" },
|
markdown = "prettierd",
|
||||||
yaml = { "prettierd" },
|
yaml = "prettierd",
|
||||||
lua = { "stylua" },
|
lua = "stylua",
|
||||||
json = { "jq" },
|
json = "jq",
|
||||||
toml = { "taplo" },
|
toml = "taplo",
|
||||||
-- ["*"] = { "injected" },
|
-- ["*"] = { "injected" },
|
||||||
["_"] = { "trim_whitespace", "trim_newlines" },
|
["_"] = "trim_whitespace",
|
||||||
|
"trim_newlines",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user