REFACTOR: Updated from older config
This commit is contained in:
@@ -2,8 +2,16 @@
|
||||
|
||||
Automatically install formatters registered with [conform.nvim](https://github.com/stevearc/conform.nvim) via [Mason](https://github.com/williamboman/mason.nvim).
|
||||
|
||||
# Requirements
|
||||
|
||||
- Neovim 0.11+
|
||||
- [mason.nvim](https://github.com/mason-org/mason.nvim) 2.x
|
||||
- [conform.nvim](https://github.com/stevearc/conform.nvim) (9.x or newer)
|
||||
|
||||
# Install
|
||||
|
||||
With [lazy.nvim](https://github.com/folke/lazy.nvim):
|
||||
|
||||
```lua
|
||||
require("lazy").setup({
|
||||
"williamboman/mason.nvim",
|
||||
@@ -12,6 +20,16 @@ require("lazy").setup({
|
||||
})
|
||||
```
|
||||
|
||||
With Neovim's built-in package manager (`:h vim.pack`, Neovim 0.12+):
|
||||
|
||||
```lua
|
||||
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:
|
||||
@@ -31,12 +49,40 @@ require("mason-conform").setup({
|
||||
})
|
||||
```
|
||||
|
||||
All the `formatters_by_ft` shapes supported by conform are understood:
|
||||
|
||||
```lua
|
||||
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](https://github.com/mason-org/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](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](https://github.com/rshkarin/mason-nvim-lint)
|
||||
|
||||
Reference in New Issue
Block a user