mason-conform.nvim
Automatically install formatters registered with conform.nvim via Mason.
Requirements
- Neovim 0.11+
- mason.nvim 2.x
- conform.nvim (9.x or newer)
Install
With lazy.nvim:
require("lazy").setup({
"williamboman/mason.nvim",
"stevearc/conform.nvim",
"zapling/mason-conform.nvim",
})
With Neovim's built-in package manager (:h vim.pack, Neovim 0.12+):
vim.pack.add({
{ src = "https://github.com/mason-org/mason.nvim" },
{ src = "https://github.com/stevearc/conform.nvim" },
{ src = "https://github.com/zapling/mason-conform.nvim" },
})
Setup
It's crucial to setup plugins in the following order:
mason.nvimconform.nvimmason-conform.nvim
Otherwise mason-conform.nvim will not have enough information about configured formatters and
access the mason registry.
Configuration
require("mason-conform").setup({
ignore_install = {'prettier'} -- List of formatters to ignore during install
})
All the formatters_by_ft shapes supported by conform are understood:
require("conform").setup({
formatters_by_ft = {
-- Plain list
lua = { "stylua" },
-- List with inline format options (`lsp_format`, `stop_after_first`, ...)
python = { "autopep8", lsp_format = "fallback" },
-- Legacy nested list ("run the first available formatter")
markdown = { { "prettierd", "prettier" }, "cbfmt" },
-- Function returning a list (conform "first available" recipe)
javascript = function(bufnr)
return { require("conform").get_formatter_info("prettier", bufnr).available and "prettier" or "prettierd" }
end,
},
})
Functions are evaluated without a buffer so that every candidate formatter can be discovered and installed. A function that requires a buffer is skipped instead of raising an error.
Available formatters
Only formatters that are available in the mason registry
can be downloaded automatically. If the formatter is available in the registry and it's not being
downloaded, this plugin might be missing a conform => mason mapping in the file lua/mason-conform/mapping.lua.
Healthcheck
Run :checkhealth mason-conform to verify that Neovim, mason.nvim and conform.nvim are set up
correctly, and to see which configured formatters cannot be installed automatically.
License
mason-conform.nvim is a blatant copy of mason-nvim-lint
which in turn takes heavy insperation from mason-lspconfig.nvim