REFACTOR: Updated from older config
This commit is contained in:
@@ -1,42 +1,25 @@
|
||||
local registry = require("mason-registry")
|
||||
local mapping = require("mason-conform.mapping")
|
||||
|
||||
local function auto_install()
|
||||
local config = require("mason-conform").config
|
||||
local formatters_by_ft = require("conform").formatters_by_ft;
|
||||
local mapping = require("mason-conform.mapping")
|
||||
local install = require("mason-conform.install")
|
||||
|
||||
local formatters_to_install = {}
|
||||
for _, formatters in pairs(formatters_by_ft) do
|
||||
for _, formatter in pairs(formatters) do
|
||||
-- Support case where the user has defined multiple formatters
|
||||
-- for said filetype. E.g javascript = { { "prettierd", "prettier" } }
|
||||
if type(formatter) == "table" then
|
||||
for _, f in pairs(formatter) do
|
||||
formatters_to_install[f] = 1
|
||||
end
|
||||
else
|
||||
formatters_to_install[formatter] = 1
|
||||
local ignored = {}
|
||||
for _, name in ipairs(config.ignore_install) do
|
||||
ignored[name] = true
|
||||
end
|
||||
|
||||
for _, name in ipairs(require("mason-conform.formatters").configured()) do
|
||||
if not ignored[name] then
|
||||
local package = mapping.conform_to_package[name]
|
||||
if package ~= nil then
|
||||
install.try_install(package)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Filter out formatters that the user wants to ignore
|
||||
for _, formatter_to_ignore in pairs(config.ignore_install) do
|
||||
formatters_to_install[formatter_to_ignore] = nil
|
||||
end
|
||||
|
||||
for conformFormatter, _ in pairs(formatters_to_install) do
|
||||
local package = mapping.conform_to_package[conformFormatter]
|
||||
if package ~= nil then
|
||||
require("mason-conform.install").try_install(package)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if registry.refresh then
|
||||
return function()
|
||||
registry.refresh(vim.schedule_wrap(auto_install))
|
||||
end
|
||||
else
|
||||
return auto_install
|
||||
---Refresh the mason registry, then install every configured formatter that is
|
||||
---missing. Returns immediately; installation happens on the main loop.
|
||||
return function()
|
||||
require("mason-registry").refresh(vim.schedule_wrap(auto_install))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user