Initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
local registry = require("mason-registry")
|
||||||
|
local mapping = require("mason-conform.mapping")
|
||||||
|
|
||||||
|
local function auto_install()
|
||||||
|
local formatters_by_ft = require("conform").formatters_by_ft;
|
||||||
|
|
||||||
|
local formatters_to_install = {}
|
||||||
|
for _, formatters in pairs(formatters_by_ft) do
|
||||||
|
for _, formatter in pairs(formatters) do
|
||||||
|
formatters_to_install[formatter] = 1
|
||||||
|
end
|
||||||
|
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
|
||||||
|
end
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup()
|
||||||
|
require "mason-conform.auto_install" ()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
local registry = require "mason-registry"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function resolve_package(mason_package_name)
|
||||||
|
local Optional = require "mason-core.optional"
|
||||||
|
|
||||||
|
local ok, pkg = pcall(registry.get_package, mason_package_name)
|
||||||
|
if ok then
|
||||||
|
return Optional.of_nilable(pkg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function install_package(pkg, version)
|
||||||
|
local linter_name = pkg.name
|
||||||
|
|
||||||
|
vim.notify(("[mason-conform] installing %s"):format(linter_name))
|
||||||
|
|
||||||
|
return pkg:install({ version = version }):once(
|
||||||
|
"closed",
|
||||||
|
vim.schedule_wrap(function()
|
||||||
|
if pkg:is_installed() then
|
||||||
|
vim.notify(("[mason-conform] %s was successfully installed"):format(linter_name))
|
||||||
|
else
|
||||||
|
vim.notify(
|
||||||
|
("[mason-conform] failed to install %s. Installation logs are available in :Mason and :MasonLog")
|
||||||
|
:format(
|
||||||
|
linter_name
|
||||||
|
),
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.try_install(mason_package_name)
|
||||||
|
local Package = require "mason-core.package"
|
||||||
|
local package_name, version = Package.Parse(mason_package_name)
|
||||||
|
|
||||||
|
resolve_package(package_name)
|
||||||
|
:if_present(
|
||||||
|
function(pkg)
|
||||||
|
if not pkg:is_installed() then
|
||||||
|
install_package(pkg, version)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
:if_not_present(function()
|
||||||
|
vim.notify(
|
||||||
|
("[mason-conform] Formatter %q is not a valid entry in ensure_installed. Make sure to only provide valid formatter names.")
|
||||||
|
:format(
|
||||||
|
package_name
|
||||||
|
),
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- conform formatter to mason package mapping
|
||||||
|
-- https://mason-registry.dev/registry/list
|
||||||
|
M.conform_to_package = {
|
||||||
|
-- alejandra
|
||||||
|
["asmfmt"] = "asmfmt",
|
||||||
|
["ast-grep"] = "ast-grep",
|
||||||
|
-- astyle
|
||||||
|
-- auto_optional
|
||||||
|
-- autocorrect
|
||||||
|
["autoflake"] = "autoflake",
|
||||||
|
["autopep8"] = "autopep8",
|
||||||
|
-- awk
|
||||||
|
-- bean-format
|
||||||
|
["beautysh"] = "beautysh",
|
||||||
|
["bibtex-tidy"] = "bibtex-tidy",
|
||||||
|
-- biome-check
|
||||||
|
["biome"] = "biome",
|
||||||
|
["black"] = "black",
|
||||||
|
["blade-formatter"] = "blade-formatter",
|
||||||
|
["blue"] = "blue",
|
||||||
|
["buf"] = "buf",
|
||||||
|
["buildifier"] = "buildifier",
|
||||||
|
["cbfmt"] = "cbfmt",
|
||||||
|
["clang_format"] = "clang-format",
|
||||||
|
-- cljstyle
|
||||||
|
["cmake_format"] = "cmakelang",
|
||||||
|
["codespell"] = "codespell",
|
||||||
|
["csharpier"] = "csharpier",
|
||||||
|
-- cue_fmt
|
||||||
|
["darker"] = "darker",
|
||||||
|
-- dart_format
|
||||||
|
["deno_fmt"] = "deno",
|
||||||
|
-- dfmt
|
||||||
|
["djlint"] = "djlint",
|
||||||
|
["dprint"] = "dprint",
|
||||||
|
["easy-coding-standard"] = "easy-coding-standard",
|
||||||
|
["elm_format"] = "elm-format",
|
||||||
|
-- erb_format
|
||||||
|
["eslint_d"] = "eslint_d",
|
||||||
|
["fantomas"] = "fantomas",
|
||||||
|
-- fish_indent
|
||||||
|
["fixjson"] = "fixjson",
|
||||||
|
-- fnlfmt
|
||||||
|
["fourmolu"] = "fourmolu",
|
||||||
|
["gci"] = "gci",
|
||||||
|
["gdformat"] = "gdtoolkit",
|
||||||
|
["gersemi"] = "gersemi",
|
||||||
|
-- gn
|
||||||
|
-- gofmt
|
||||||
|
["gofumpt"] = "gofumpt",
|
||||||
|
["goimports-reviser"] = "goimports-reviser",
|
||||||
|
["goimports"] = "goimports",
|
||||||
|
["golines"] = "golines",
|
||||||
|
["google-java-format"] = "google-java-format",
|
||||||
|
["htmlbeautifier"] = "htmlbeautifier",
|
||||||
|
-- indent
|
||||||
|
-- init
|
||||||
|
-- injected
|
||||||
|
["isort"] = "isort",
|
||||||
|
["joker"] = "joker",
|
||||||
|
["jq"] = "jq",
|
||||||
|
["jsonnetfmt"] = "jsonnetfmt",
|
||||||
|
-- just
|
||||||
|
["ktlint"] = "ktlint",
|
||||||
|
["latexindent"] = "latexindent",
|
||||||
|
["markdown-toc"] = "markdown-toc",
|
||||||
|
["markdownlint-cli2"] = "markdownlint-cli2",
|
||||||
|
["markdownlint"] = "markdownlint",
|
||||||
|
["mdformat"] = "mdformat",
|
||||||
|
["mdslw"] = "mdslw",
|
||||||
|
-- mix
|
||||||
|
-- nixfmt
|
||||||
|
["nixpkgs_fmt"] = "nixpkgs-fmt",
|
||||||
|
["ocamlformat"] = "ocamlformat",
|
||||||
|
-- opa_fmt
|
||||||
|
-- packer_fmt
|
||||||
|
-- pangu
|
||||||
|
-- perlimports
|
||||||
|
-- perltidy
|
||||||
|
-- pg_format
|
||||||
|
["php_cs_fixer"] = "php-cs-fixer",
|
||||||
|
["phpcbf"] = "phpcbf",
|
||||||
|
-- phpinsights
|
||||||
|
["pint"] = "pint",
|
||||||
|
["prettier"] = "prettier",
|
||||||
|
["prettierd"] = "prettierd",
|
||||||
|
["pretty-php"] = "pretty-php",
|
||||||
|
-- puppet-lint
|
||||||
|
["reorder-python-imports"] = "reorder-python-imports",
|
||||||
|
-- rescript-format
|
||||||
|
["rubocop"] = "rubocop",
|
||||||
|
["rubyfmt"] = "rubyfmt",
|
||||||
|
-- ruff
|
||||||
|
["ruff_fix"] = "ruff",
|
||||||
|
["ruff_format"] = "ruff",
|
||||||
|
["rufo"] = "rufo",
|
||||||
|
["rustfmt"] = "rustfmt",
|
||||||
|
["rustywind"] = "rustywind",
|
||||||
|
-- scalafmt
|
||||||
|
["shellcheck"] = "shellcheck",
|
||||||
|
["shellharden"] = "shellharden",
|
||||||
|
["shfmt"] = "shfmt",
|
||||||
|
["sql_formatter"] = "sql-formatter",
|
||||||
|
["sqlfluff"] = "sqlfluff",
|
||||||
|
["sqlfmt"] = "sqlfmt",
|
||||||
|
-- squeeze_blanks
|
||||||
|
["standardjs"] = "standardjs",
|
||||||
|
["standardrb"] = "standardrb",
|
||||||
|
["stylelint"] = "stylelint",
|
||||||
|
-- styler
|
||||||
|
["stylua"] = "stylua",
|
||||||
|
-- swift_format
|
||||||
|
-- swiftformat
|
||||||
|
["taplo"] = "taplo",
|
||||||
|
["templ"] = "templ",
|
||||||
|
-- terraform_fmt
|
||||||
|
-- terragrunt_hclfmt
|
||||||
|
["tlint"] = "tlint",
|
||||||
|
-- trim_newlines
|
||||||
|
-- trim_whitespace
|
||||||
|
-- twig-cs-fixer
|
||||||
|
["typos"] = "typos",
|
||||||
|
-- typstfmt
|
||||||
|
-- uncrustify
|
||||||
|
["usort"] = "usort",
|
||||||
|
["xmlformat"] = "xmlformatter",
|
||||||
|
-- xmllint
|
||||||
|
["yamlfix"] = "yamlfix",
|
||||||
|
["yamlfmt"] = "yamlfmt",
|
||||||
|
["yapf"] = "yapf",
|
||||||
|
["yq"] = "yq",
|
||||||
|
-- zigfmt
|
||||||
|
["zprint"] = "zprint",
|
||||||
|
}
|
||||||
|
|
||||||
|
return M
|
||||||
Reference in New Issue
Block a user