Refresh generated neovim config
This commit is contained in:
@ -17,8 +17,8 @@ OPTIONS *conform-option
|
||||
lua = { "stylua" },
|
||||
-- Conform will run multiple formatters sequentially
|
||||
go = { "goimports", "gofmt" },
|
||||
-- Use a sub-list to run only the first available formatter
|
||||
javascript = { { "prettierd", "prettier" } },
|
||||
-- You can also customize some of the format options for the filetype
|
||||
rust = { "rustfmt", lsp_format = "fallback" },
|
||||
-- You can use a function here to determine the formatters dynamically
|
||||
python = function(bufnr)
|
||||
if require("conform").get_formatter_info("ruff_format", bufnr).available then
|
||||
@ -33,6 +33,11 @@ OPTIONS *conform-option
|
||||
-- have other formatters configured.
|
||||
["_"] = { "trim_whitespace" },
|
||||
},
|
||||
-- Set this to change the default values when calling conform.format()
|
||||
-- This will also affect the default values for format_on_save/format_after_save
|
||||
default_format_opts = {
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
-- If this is set, Conform will run the formatter on save.
|
||||
-- It will pass the table to conform.format().
|
||||
-- This can also be a function that returns the table.
|
||||
@ -51,6 +56,8 @@ OPTIONS *conform-option
|
||||
log_level = vim.log.levels.ERROR,
|
||||
-- Conform will notify you when a formatter errors
|
||||
notify_on_error = true,
|
||||
-- Conform will notify you when no formatters are available for the buffer
|
||||
notify_no_formatters = true,
|
||||
-- Custom formatters and overrides for built-in formatters
|
||||
formatters = {
|
||||
my_formatter = {
|
||||
@ -87,7 +94,6 @@ OPTIONS *conform-option
|
||||
-- Set to false to disable merging the config with the base definition
|
||||
inherit = true,
|
||||
-- When inherit = true, add these additional arguments to the beginning of the command.
|
||||
-- When inherit = true, add these additional arguments to the command.
|
||||
-- This can also be a function, like args
|
||||
prepend_args = { "--use-tabs" },
|
||||
-- When inherit = true, add these additional arguments to the end of the command.
|
||||
@ -119,12 +125,32 @@ setup({opts}) *conform.setu
|
||||
{opts} `nil|conform.setupOpts`
|
||||
{formatters_by_ft} `nil|table<string, conform.FiletypeFormatter>` Map
|
||||
of filetype to formatters
|
||||
{format_on_save} `nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts` I
|
||||
f this is set, Conform will run the formatter on
|
||||
{format_on_save} `nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts`
|
||||
If this is set, Conform will run the formatter on
|
||||
save. It will pass the table to conform.format().
|
||||
This can also be a function that returns the table.
|
||||
{format_after_save} `nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts` I
|
||||
f this is set, Conform will run the formatter
|
||||
{default_format_opts} `nil|conform.DefaultFormatOpts` The default
|
||||
options to use when calling conform.format()
|
||||
{timeout_ms} `nil|integer` Time in milliseconds to block for
|
||||
formatting. Defaults to 1000. No effect if
|
||||
async = true.
|
||||
{lsp_format} `nil|conform.LspFormatOpts` Configure if and
|
||||
when LSP should be used for formatting.
|
||||
Defaults to "never".
|
||||
`"never"` never use the LSP for formatting (default)
|
||||
`"fallback"` LSP formatting is used when no other formatters
|
||||
are available
|
||||
`"prefer"` use only LSP formatting when available
|
||||
`"first"` LSP formatting is used when available and then
|
||||
other formatters
|
||||
`"last"` other formatters are used then LSP formatting
|
||||
when available
|
||||
{quiet} `nil|boolean` Don't show any notifications for
|
||||
warnings or failures. Defaults to false.
|
||||
{stop_after_first} `nil|boolean` Only run the first available
|
||||
formatter in the list. Defaults to false.
|
||||
{format_after_save} `nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts`
|
||||
If this is set, Conform will run the formatter
|
||||
asynchronously after save. It will pass the table
|
||||
to conform.format(). This can also be a function
|
||||
that returns the table.
|
||||
@ -133,8 +159,11 @@ setup({opts}) *conform.setu
|
||||
the location of the log file.
|
||||
{notify_on_error} `nil|boolean` Conform will notify you when a
|
||||
formatter errors (default true).
|
||||
{formatters} `nil|table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride>` C
|
||||
ustom formatters and overrides for built-in
|
||||
{notify_no_formatters} `nil|boolean` Conform will notify you when no
|
||||
formatters are available for the buffer (default
|
||||
true).
|
||||
{formatters} `nil|table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride>`
|
||||
Custom formatters and overrides for built-in
|
||||
formatters.
|
||||
|
||||
format({opts}, {callback}): boolean *conform.format*
|
||||
@ -142,32 +171,47 @@ format({opts}, {callback}): boolean *conform.forma
|
||||
|
||||
Parameters:
|
||||
{opts} `nil|conform.FormatOpts`
|
||||
{timeout_ms} `nil|integer` Time in milliseconds to block for
|
||||
formatting. Defaults to 1000. No effect if async = true.
|
||||
{bufnr} `nil|integer` Format this buffer (default 0)
|
||||
{async} `nil|boolean` If true the method won't block. Defaults to
|
||||
false. If the buffer is modified before the formatter
|
||||
completes, the formatting will be discarded.
|
||||
{dry_run} `nil|boolean` If true don't apply formatting changes to
|
||||
the buffer
|
||||
{formatters} `nil|string[]` List of formatters to run. Defaults to all
|
||||
formatters for the buffer filetype.
|
||||
{lsp_format} `nil|"never"|"fallback"|"prefer"|"first"|"last"` "fallbac
|
||||
k" LSP formatting when no other formatters are available,
|
||||
"prefer" only LSP formatting when available, "first" LSP
|
||||
formatting then other formatters, "last" other formatters
|
||||
then LSP.
|
||||
{quiet} `nil|boolean` Don't show any notifications for warnings
|
||||
or failures. Defaults to false.
|
||||
{range} `nil|table` Range to format. Table must contain `start`
|
||||
and `end` keys with {row, col} tuples using (1,0)
|
||||
indexing. Defaults to current selection in visual mode
|
||||
{id} `nil|integer` Passed to |vim.lsp.buf.format| when using
|
||||
LSP formatting
|
||||
{name} `nil|string` Passed to |vim.lsp.buf.format| when using
|
||||
LSP formatting
|
||||
{filter} `nil|fun(client: table): boolean` Passed to
|
||||
|vim.lsp.buf.format| when using LSP formatting
|
||||
{timeout_ms} `nil|integer` Time in milliseconds to block for
|
||||
formatting. Defaults to 1000. No effect if async =
|
||||
true.
|
||||
{bufnr} `nil|integer` Format this buffer (default 0)
|
||||
{async} `nil|boolean` If true the method won't block.
|
||||
Defaults to false. If the buffer is modified before
|
||||
the formatter completes, the formatting will be
|
||||
discarded.
|
||||
{dry_run} `nil|boolean` If true don't apply formatting
|
||||
changes to the buffer
|
||||
{undojoin} `nil|boolean` Use undojoin to merge formatting
|
||||
changes with previous edit (default false)
|
||||
{formatters} `nil|string[]` List of formatters to run. Defaults
|
||||
to all formatters for the buffer filetype.
|
||||
{lsp_format} `nil|conform.LspFormatOpts` Configure if and when
|
||||
LSP should be used for formatting. Defaults to
|
||||
"never".
|
||||
`"never"` never use the LSP for formatting (default)
|
||||
`"fallback"` LSP formatting is used when no other formatters are
|
||||
available
|
||||
`"prefer"` use only LSP formatting when available
|
||||
`"first"` LSP formatting is used when available and then other
|
||||
formatters
|
||||
`"last"` other formatters are used then LSP formatting when
|
||||
available
|
||||
{stop_after_first} `nil|boolean` Only run the first available
|
||||
formatter in the list. Defaults to false.
|
||||
{quiet} `nil|boolean` Don't show any notifications for
|
||||
warnings or failures. Defaults to false.
|
||||
{range} `nil|conform.Range` Range to format. Table must
|
||||
contain `start` and `end` keys with {row, col}
|
||||
tuples using (1,0) indexing. Defaults to current
|
||||
selection in visual mode
|
||||
{start} `integer[]`
|
||||
{end} `integer[]`
|
||||
{id} `nil|integer` Passed to |vim.lsp.buf.format| when
|
||||
using LSP formatting
|
||||
{name} `nil|string` Passed to |vim.lsp.buf.format| when
|
||||
using LSP formatting
|
||||
{filter} `nil|fun(client: table): boolean` Passed to |vim.ls
|
||||
p.buf.format| when using LSP formatting
|
||||
{callback} `nil|fun(err: nil|string, did_edit: nil|boolean)` Called once
|
||||
formatting has completed
|
||||
Returns:
|
||||
@ -179,6 +223,18 @@ list_formatters({bufnr}): conform.FormatterInfo[] *conform.list_formatter
|
||||
Parameters:
|
||||
{bufnr} `nil|integer`
|
||||
|
||||
list_formatters_to_run({bufnr}): conform.FormatterInfo[], boolean *conform.list_formatters_to_run*
|
||||
Get the exact formatters that will be run for a buffer.
|
||||
|
||||
Parameters:
|
||||
{bufnr} `nil|integer`
|
||||
Returns:
|
||||
`conform.FormatterInfo[]`
|
||||
`boolean` lsp Will use LSP formatter
|
||||
|
||||
Note:
|
||||
This accounts for stop_after_first, lsp fallback logic, etc.
|
||||
|
||||
list_all_formatters(): conform.FormatterInfo[] *conform.list_all_formatters*
|
||||
List information about all filetype-configured formatters
|
||||
|
||||
@ -190,12 +246,6 @@ get_formatter_info({formatter}, {bufnr}): conform.FormatterInfo *conform.get_for
|
||||
{formatter} `string` The name of the formatter
|
||||
{bufnr} `nil|integer`
|
||||
|
||||
will_fallback_lsp({options}): boolean *conform.will_fallback_lsp*
|
||||
Check if the buffer will use LSP formatting when lsp_format = "fallback"
|
||||
|
||||
Parameters:
|
||||
{options} `nil|table` Options passed to |vim.lsp.buf.format|
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
FORMATTERS *conform-formatters*
|
||||
|
||||
@ -229,16 +279,19 @@ FORMATTERS *conform-formatter
|
||||
respects readability.
|
||||
`blue` - The slightly less uncompromising Python code formatter.
|
||||
`bpfmt` - Android Blueprint file formatter.
|
||||
`bsfmt` - A code formatter for BrighterScript (and BrightScript).
|
||||
`buf` - A new way of working with Protocol Buffers.
|
||||
`buildifier` - buildifier is a tool for formatting bazel BUILD and .bzl files
|
||||
with a standard convention.
|
||||
`cabal_fmt` - Format cabal files with cabal-fmt
|
||||
`caramel_fmt` - Format Caramel code.
|
||||
`cbfmt` - A tool to format codeblocks inside markdown and org documents.
|
||||
`clang-format` - Tool to format C/C++/… code according to a set of rules and
|
||||
heuristics.
|
||||
`cljstyle` - Formatter for Clojure code.
|
||||
`cmake_format` - Parse cmake listfiles and format them nicely.
|
||||
`codespell` - Check code for common misspellings.
|
||||
`crlfmt` - Formatter for CockroachDB's additions to the Go style guide.
|
||||
`crystal` - Format Crystal code.
|
||||
`csharpier` - The opinionated C# code formatter.
|
||||
`cue_fmt` - Format CUE files using `cue fmt` command.
|
||||
@ -246,12 +299,19 @@ FORMATTERS *conform-formatter
|
||||
`darker` - Run black only on changed lines.
|
||||
`dart_format` - Replace the whitespace in your program with formatting that
|
||||
follows Dart guidelines.
|
||||
`dcm_fix` - Fixes issues produced by dcm analyze, dcm check-unused-code or dcm
|
||||
check-dependencies commands.
|
||||
`dcm_format` - Formats .dart files.
|
||||
`deno_fmt` - Use [Deno](https://deno.land/) to format TypeScript,
|
||||
JavaScript/JSON and markdown.
|
||||
`dfmt` - Formatter for D source code.
|
||||
`djlint` - ✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks -
|
||||
Handlebars - GoLang.
|
||||
`docformatter` - docformatter automatically formats docstrings to follow a
|
||||
subset of the PEP 257 conventions.
|
||||
`docstrfmt` - reStructuredText formatter.
|
||||
`doctoc` - Generates table of contents for markdown files inside local git
|
||||
repository.
|
||||
`dprint` - Pluggable and configurable code formatting platform written in Rust.
|
||||
`easy-coding-standard` - ecs - Use Coding Standard with 0-knowledge of PHP-CS-
|
||||
Fixer and PHP_CodeSniffer.
|
||||
@ -278,6 +338,7 @@ FORMATTERS *conform-formatter
|
||||
`gdformat` - A formatter for Godot's gdscript.
|
||||
`gersemi` - A formatter to make your CMake code the real treasure.
|
||||
`gleam` - ⭐️ A friendly language for building type-safe, scalable systems!
|
||||
`gluon_fmt` - Code formatting for the gluon programming language.
|
||||
`gn` - gn build system.
|
||||
`gofmt` - Formats go programs.
|
||||
`gofumpt` - Enforce a stricter format than gofmt, while being backwards
|
||||
@ -290,10 +351,12 @@ FORMATTERS *conform-formatter
|
||||
`golines` - A golang formatter that fixes long lines.
|
||||
`google-java-format` - Reformats Java source code according to Google Java
|
||||
Style.
|
||||
`grain_format` - Code formatter for the grain programming language.
|
||||
`hcl` - A formatter for HCL files.
|
||||
`hindent` - Haskell pretty printer.
|
||||
`htmlbeautifier` - A normaliser/beautifier for HTML that also understands
|
||||
embedded Ruby. Ideal for tidying up Rails templates.
|
||||
`imba_fmt` - Code formatter for the Imba programming language.
|
||||
`indent` - GNU Indent.
|
||||
`injected` - Format treesitter injected languages.
|
||||
`inko` - A language for building concurrent software with confidence
|
||||
@ -325,6 +388,7 @@ FORMATTERS *conform-formatter
|
||||
`mdslw` - Prepare your markdown for easy diff'ing by adding line breaks after
|
||||
every sentence.
|
||||
`mix` - Format Elixir files using the mix format command.
|
||||
`nickel` - Code formatter for the Nickel programming language.
|
||||
`nimpretty` - nimpretty is a Nim source code beautifier that follows the
|
||||
official style guide.
|
||||
`nixfmt` - nixfmt is a formatter for Nix code, intended to apply a uniform
|
||||
@ -377,6 +441,7 @@ FORMATTERS *conform-formatter
|
||||
`shellcheck` - A static analysis tool for shell scripts.
|
||||
`shellharden` - The corrective bash syntax highlighter.
|
||||
`shfmt` - A shell parser, formatter, and interpreter with `bash` support.
|
||||
`sleek` - Sleek is a CLI tool for formatting SQL.
|
||||
`smlfmt` - A custom parser and code formatter for Standard ML.
|
||||
`snakefmt` - a formatting tool for Snakemake files following the design of
|
||||
Black.
|
||||
@ -398,6 +463,7 @@ FORMATTERS *conform-formatter
|
||||
`swift build`.
|
||||
`swiftformat` - SwiftFormat is a code library and command-line tool for
|
||||
reformatting `swift` code on macOS or Linux.
|
||||
`swiftlint` - A tool to enforce Swift style and conventions.
|
||||
`taplo` - A TOML toolkit written in Rust.
|
||||
`templ` - Formats templ template files.
|
||||
`terraform_fmt` - The terraform-fmt command rewrites `terraform` configuration
|
||||
@ -407,8 +473,8 @@ FORMATTERS *conform-formatter
|
||||
formatting.
|
||||
`tofu_fmt` - The tofu-fmt command rewrites OpenTofu configuration files to a
|
||||
canonical format and style.
|
||||
`trim_newlines` - Trim new lines with awk.
|
||||
`trim_whitespace` - Trim whitespaces with awk.
|
||||
`trim_newlines` - Trim empty lines at the end of the file.
|
||||
`trim_whitespace` - Trim trailing whitespace.
|
||||
`twig-cs-fixer` - Automatically fix Twig Coding Standards issues
|
||||
`typos` - Source code spell checker
|
||||
`typstyle` - Beautiful and reliable typst code formatter.
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
- [Command to toggle format-on-save](#command-to-toggle-format-on-save)
|
||||
- [Automatically run slow formatters async](#automatically-run-slow-formatters-async)
|
||||
- [Lazy loading with lazy.nvim](#lazy-loading-with-lazynvim)
|
||||
- [Leave visual mode after range format](#leave-visual-mode-after-range-format)
|
||||
- [Run the first available formatter followed by more formatters](#run-the-first-available-formatter-followed-by-more-formatters)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
@ -149,22 +151,28 @@ return {
|
||||
-- Customize or remove this keymap to your liking
|
||||
"<leader>f",
|
||||
function()
|
||||
require("conform").format({ async = true, lsp_format = "fallback" })
|
||||
require("conform").format({ async = true })
|
||||
end,
|
||||
mode = "",
|
||||
desc = "Format buffer",
|
||||
},
|
||||
},
|
||||
-- Everything in opts will be passed to setup()
|
||||
-- This will provide type hinting with LuaLS
|
||||
---@module "conform"
|
||||
---@type conform.setupOpts
|
||||
opts = {
|
||||
-- Define your formatters
|
||||
formatters_by_ft = {
|
||||
lua = { "stylua" },
|
||||
python = { "isort", "black" },
|
||||
javascript = { { "prettierd", "prettier" } },
|
||||
javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||
},
|
||||
-- Set default options
|
||||
default_format_opts = {
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
-- Set up format-on-save
|
||||
format_on_save = { timeout_ms = 500, lsp_format = "fallback" },
|
||||
format_on_save = { timeout_ms = 500 },
|
||||
-- Customize formatters
|
||||
formatters = {
|
||||
shfmt = {
|
||||
@ -178,3 +186,51 @@ return {
|
||||
end,
|
||||
}
|
||||
```
|
||||
|
||||
## Leave visual mode after range format
|
||||
|
||||
If you call `conform.format` when in visual mode, conform will perform a range format on the selected region. If you want it to leave visual mode afterwards (similar to the default `gw` or `gq` behavior), use this mapping:
|
||||
|
||||
```lua
|
||||
vim.keymap.set("", "<leader>f", function()
|
||||
require("conform").format({ async = true }, function(err)
|
||||
if not err then
|
||||
local mode = vim.api.nvim_get_mode().mode
|
||||
if vim.startswith(string.lower(mode), "v") then
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end, { desc = "Format code" })
|
||||
```
|
||||
|
||||
## Run the first available formatter followed by more formatters
|
||||
|
||||
With the refactor in [#491](https://github.com/stevearc/conform.nvim/pull/491) it is now easy to
|
||||
just run the first available formatter in a list, but more difficult to do that _and then_ run
|
||||
another formatter. For example, "format first with either `prettierd` or `prettier`, _then_ use the
|
||||
`injected` formatter". Here is how you can easily do that:
|
||||
|
||||
```lua
|
||||
---@param bufnr integer
|
||||
---@param ... string
|
||||
---@return string
|
||||
local function first(bufnr, ...)
|
||||
local conform = require("conform")
|
||||
for i = 1, select("#", ...) do
|
||||
local formatter = select(i, ...)
|
||||
if conform.get_formatter_info(formatter, bufnr).available then
|
||||
return formatter
|
||||
end
|
||||
end
|
||||
return select(1, ...)
|
||||
end
|
||||
|
||||
require("conform").setup({
|
||||
formatters_by_ft = {
|
||||
markdown = function(bufnr)
|
||||
return { first(bufnr, "prettierd", "prettier"), "injected" }
|
||||
end,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
@ -8,7 +8,7 @@ conform.format conform.txt /*conform.format*
|
||||
conform.get_formatter_info conform.txt /*conform.get_formatter_info*
|
||||
conform.list_all_formatters conform.txt /*conform.list_all_formatters*
|
||||
conform.list_formatters conform.txt /*conform.list_formatters*
|
||||
conform.list_formatters_to_run conform.txt /*conform.list_formatters_to_run*
|
||||
conform.nvim conform.txt /*conform.nvim*
|
||||
conform.setup conform.txt /*conform.setup*
|
||||
conform.txt conform.txt /*conform.txt*
|
||||
conform.will_fallback_lsp conform.txt /*conform.will_fallback_lsp*
|
||||
|
||||
Reference in New Issue
Block a user