Refresh generated neovim config
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
#!/nix/store/4bj2kxdm1462fzcc2i2s4dn33g2angcc-bash-5.2p32/bin/bash
|
||||
set -e
|
||||
make fastlint
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
#!/nix/store/4bj2kxdm1462fzcc2i2s4dn33g2angcc-bash-5.2p32/bin/bash
|
||||
set -e
|
||||
IFS=' '
|
||||
while read local_ref _local_sha _remote_ref _remote_sha; do
|
||||
|
||||
@ -50,7 +50,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- nvim_tag: v0.8.3
|
||||
- nvim_tag: v0.9.4
|
||||
- nvim_tag: v0.10.0
|
||||
|
||||
|
||||
@ -1,5 +1,78 @@
|
||||
# Changelog
|
||||
|
||||
## [7.0.0](https://github.com/stevearc/conform.nvim/compare/v6.1.0...v7.0.0) (2024-07-23)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* drop support for nvim 0.8
|
||||
|
||||
### cleanup
|
||||
|
||||
* drop support for nvim 0.8 ([54ea60d](https://github.com/stevearc/conform.nvim/commit/54ea60d1591486e7e56183addf1f45b03244386d))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add sleek, a SQL formatter ([#496](https://github.com/stevearc/conform.nvim/issues/496)) ([8925292](https://github.com/stevearc/conform.nvim/commit/8925292a1e18430a0176671552394d819642b9d9))
|
||||
* allow configuring conform.format() args on a per-filetype basis ([3a0e9b4](https://github.com/stevearc/conform.nvim/commit/3a0e9b44076514ffba6c81ca28685107928b55f7))
|
||||
* allow customizing format() defaults ([d7de350](https://github.com/stevearc/conform.nvim/commit/d7de350233e8f686b9affac9c1e106a6602f5fe8))
|
||||
* deprecate will_fallback_lsp in favor of list_formatters_to_run ([1b590cd](https://github.com/stevearc/conform.nvim/commit/1b590cda290bbabdb116397cb241d20530281b87))
|
||||
* format parameter to only run the first available formatter ([0b3d259](https://github.com/stevearc/conform.nvim/commit/0b3d25969e2da2f5de90cc02ccd6446aa68dd895))
|
||||
* notify when no formatters available for a buffer ([8c226d9](https://github.com/stevearc/conform.nvim/commit/8c226d917918ffe92e0f30f4e13acfc088a5faa7))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* crash in nvim-notify ([c16c749](https://github.com/stevearc/conform.nvim/commit/c16c749612fb34a9c1dcc6e4a0f40e24e37d5cfb))
|
||||
* ensure only expected options get passed through ([834d42c](https://github.com/stevearc/conform.nvim/commit/834d42c17687541750447046b94193d47386665d))
|
||||
* warn user when they are attempting unsupported behavior ([8b0e62b](https://github.com/stevearc/conform.nvim/commit/8b0e62b731429ecd89cdb6c6b8f004f8468bcf71))
|
||||
|
||||
## [6.1.0](https://github.com/stevearc/conform.nvim/compare/v6.0.0...v6.1.0) (2024-07-19)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add Swiftlint formatter ([#484](https://github.com/stevearc/conform.nvim/issues/484)) ([bf94a7c](https://github.com/stevearc/conform.nvim/commit/bf94a7cee31df9525239bc7d5ca4910009dfa4ee))
|
||||
* add undojoin as a format option ([#488](https://github.com/stevearc/conform.nvim/issues/488)) ([1d1362b](https://github.com/stevearc/conform.nvim/commit/1d1362b0261d06a0b91872e916c172320bbb988a))
|
||||
* **shfmt:** add automatic indentation detection ([#481](https://github.com/stevearc/conform.nvim/issues/481)) ([cd75be8](https://github.com/stevearc/conform.nvim/commit/cd75be867f2331b22905f47d28c0c270a69466aa))
|
||||
* support doctoc ([#489](https://github.com/stevearc/conform.nvim/issues/489)) ([4f476ba](https://github.com/stevearc/conform.nvim/commit/4f476ba2247bfa5fe46ad52d934536d271d75431))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **biome-check:** use --write instead of deprecated --apply ([#482](https://github.com/stevearc/conform.nvim/issues/482)) ([0cdd6a7](https://github.com/stevearc/conform.nvim/commit/0cdd6a7c66a57560c91c816a567bd1d247be53c3))
|
||||
* display stdout as error message if stderr is empty ([#486](https://github.com/stevearc/conform.nvim/issues/486)) ([310e2e9](https://github.com/stevearc/conform.nvim/commit/310e2e95a4f832163f3f7a9fedebb1a4afc0db69))
|
||||
* **npm-groovy-lint:** ignore exit code 1 ([#477](https://github.com/stevearc/conform.nvim/issues/477)) ([c26dadf](https://github.com/stevearc/conform.nvim/commit/c26dadf8a47a547768d1048a0d698ecec33494ce))
|
||||
* **shfmt:** don't pass indentation if .editorconfig is present ([#492](https://github.com/stevearc/conform.nvim/issues/492)) ([acc7d93](https://github.com/stevearc/conform.nvim/commit/acc7d93f4a080fec587a99fcb36cffa29adc4bad))
|
||||
|
||||
## [6.0.0](https://github.com/stevearc/conform.nvim/compare/v5.9.0...v6.0.0) (2024-06-25)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* expand options for LSP formatting ([#456](https://github.com/stevearc/conform.nvim/issues/456))
|
||||
|
||||
### Features
|
||||
|
||||
* add support for caramel fmt ([#469](https://github.com/stevearc/conform.nvim/issues/469)) ([c35f52b](https://github.com/stevearc/conform.nvim/commit/c35f52b04e4436d5525102b2d61150679c967100))
|
||||
* **djlint:** use tabstop to set indentation ([#467](https://github.com/stevearc/conform.nvim/issues/467)) ([ac6e142](https://github.com/stevearc/conform.nvim/commit/ac6e142a10c8817762f55a35ed6cb9632671ec79)), closes [#457](https://github.com/stevearc/conform.nvim/issues/457)
|
||||
* expand options for LSP formatting ([#456](https://github.com/stevearc/conform.nvim/issues/456)) ([9228b2f](https://github.com/stevearc/conform.nvim/commit/9228b2ff4efd58b6e081defec643bf887ebadff6))
|
||||
* support brighterscript-formatter ([#468](https://github.com/stevearc/conform.nvim/issues/468)) ([89af7f0](https://github.com/stevearc/conform.nvim/commit/89af7f00b6e52647c7b0e04eb8cc9bc9cab91e3e))
|
||||
* support crlfmt ([#470](https://github.com/stevearc/conform.nvim/issues/470)) ([7394d49](https://github.com/stevearc/conform.nvim/commit/7394d4989cd08ddb72e526c43afae7dd3111d553))
|
||||
* support dcm fix and dcm format ([#471](https://github.com/stevearc/conform.nvim/issues/471)) ([b67f273](https://github.com/stevearc/conform.nvim/commit/b67f2732a2d0276454c7623204741d908de5358a))
|
||||
* support docformatter ([#472](https://github.com/stevearc/conform.nvim/issues/472)) ([b5ae342](https://github.com/stevearc/conform.nvim/commit/b5ae342ab28919a8083b589a587b030ad859592e))
|
||||
* support gluon fmt ([#473](https://github.com/stevearc/conform.nvim/issues/473)) ([d1f9bd4](https://github.com/stevearc/conform.nvim/commit/d1f9bd4823628d26a10b98acc9b3b6dbc7b1c053))
|
||||
* support grain format ([#474](https://github.com/stevearc/conform.nvim/issues/474)) ([d2afc5d](https://github.com/stevearc/conform.nvim/commit/d2afc5de7a24dcde7af13209b91d8e3b87a89661))
|
||||
* support imba fmt ([#475](https://github.com/stevearc/conform.nvim/issues/475)) ([6856aed](https://github.com/stevearc/conform.nvim/commit/6856aed6d7abf94735739d44a459aef977c2ab44))
|
||||
* support nickel format ([#476](https://github.com/stevearc/conform.nvim/issues/476)) ([241c892](https://github.com/stevearc/conform.nvim/commit/241c892b265f7a5906584b34c5be36b48c09a4b8))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* deprecate typstfmt formatter ([#458](https://github.com/stevearc/conform.nvim/issues/458)) ([6e5d476](https://github.com/stevearc/conform.nvim/commit/6e5d476e97dbd251cc2233d42fd238c810404701))
|
||||
* LSP fallback behavior when formatters not availble ([bde3bee](https://github.com/stevearc/conform.nvim/commit/bde3bee1773c96212b6c49f009e05174f932c23a))
|
||||
|
||||
## [5.9.0](https://github.com/stevearc/conform.nvim/compare/v5.8.0...v5.9.0) (2024-06-10)
|
||||
|
||||
|
||||
|
||||
@ -18,16 +18,16 @@ Lightweight yet powerful formatter plugin for Neovim
|
||||
- [setup(opts)](#setupopts)
|
||||
- [format(opts, callback)](#formatopts-callback)
|
||||
- [list_formatters(bufnr)](#list_formattersbufnr)
|
||||
- [list_formatters_to_run(bufnr)](#list_formatters_to_runbufnr)
|
||||
- [list_all_formatters()](#list_all_formatters)
|
||||
- [get_formatter_info(formatter, bufnr)](#get_formatter_infoformatter-bufnr)
|
||||
- [will_fallback_lsp(options)](#will_fallback_lspoptions)
|
||||
- [Acknowledgements](#acknowledgements)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
## Requirements
|
||||
|
||||
- Neovim 0.8+
|
||||
- Neovim 0.9+ (for older versions, use a [nvim-0.x branch](https://github.com/stevearc/conform.nvim/branches))
|
||||
|
||||
## Features
|
||||
|
||||
@ -129,8 +129,10 @@ require("conform").setup({
|
||||
lua = { "stylua" },
|
||||
-- Conform will run multiple formatters sequentially
|
||||
python = { "isort", "black" },
|
||||
-- Use a sub-list to run only the first available formatter
|
||||
javascript = { { "prettierd", "prettier" } },
|
||||
-- You can customize some of the format options for the filetype (:help conform.format)
|
||||
rust = { "rustfmt", lsp_format = "fallback" },
|
||||
-- Conform will run the first available formatter
|
||||
javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||
},
|
||||
})
|
||||
```
|
||||
@ -196,24 +198,31 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [blade-formatter](https://github.com/shufo/blade-formatter) - An opinionated blade template formatter for Laravel that respects readability.
|
||||
- [blue](https://github.com/grantjenks/blue) - The slightly less uncompromising Python code formatter.
|
||||
- [bpfmt](https://source.android.com/docs/setup/reference/androidbp) - Android Blueprint file formatter.
|
||||
- [bsfmt](https://github.com/rokucommunity/brighterscript-formatter) - A code formatter for BrighterScript (and BrightScript).
|
||||
- [buf](https://buf.build/docs/reference/cli/buf/format) - A new way of working with Protocol Buffers.
|
||||
- [buildifier](https://github.com/bazelbuild/buildtools/tree/master/buildifier) - buildifier is a tool for formatting bazel BUILD and .bzl files with a standard convention.
|
||||
- [cabal_fmt](https://hackage.haskell.org/package/cabal-fmt) - Format cabal files with cabal-fmt
|
||||
- [caramel_fmt](https://caramel.run/manual/reference/cli/fmt.html) - Format Caramel code.
|
||||
- [cbfmt](https://github.com/lukas-reineke/cbfmt) - A tool to format codeblocks inside markdown and org documents.
|
||||
- [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html) - Tool to format C/C++/… code according to a set of rules and heuristics.
|
||||
- [cljstyle](https://github.com/greglook/cljstyle) - Formatter for Clojure code.
|
||||
- [cmake_format](https://github.com/cheshirekow/cmake_format) - Parse cmake listfiles and format them nicely.
|
||||
- [codespell](https://github.com/codespell-project/codespell) - Check code for common misspellings.
|
||||
- [crlfmt](https://github.com/cockroachdb/crlfmt) - Formatter for CockroachDB's additions to the Go style guide.
|
||||
- [crystal](https://crystal-lang.org/) - Format Crystal code.
|
||||
- [csharpier](https://github.com/belav/csharpier) - The opinionated C# code formatter.
|
||||
- [cue_fmt](https://cuelang.org) - Format CUE files using `cue fmt` command.
|
||||
- [d2](https://github.com/terrastruct/d2) - D2 is a modern diagram scripting language that turns text to diagrams.
|
||||
- [darker](https://github.com/akaihola/darker) - Run black only on changed lines.
|
||||
- [dart_format](https://dart.dev/tools/dart-format) - Replace the whitespace in your program with formatting that follows Dart guidelines.
|
||||
- [dcm_fix](https://dcm.dev/docs/cli/formatting/fix/) - Fixes issues produced by dcm analyze, dcm check-unused-code or dcm check-dependencies commands.
|
||||
- [dcm_format](https://dcm.dev/docs/cli/formatting/format/) - Formats .dart files.
|
||||
- [deno_fmt](https://deno.land/manual/tools/formatter) - Use [Deno](https://deno.land/) to format TypeScript, JavaScript/JSON and markdown.
|
||||
- [dfmt](https://github.com/dlang-community/dfmt) - Formatter for D source code.
|
||||
- [djlint](https://github.com/Riverside-Healthcare/djLint) - ✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang.
|
||||
- [docformatter](https://pypi.org/project/docformatter/) - docformatter automatically formats docstrings to follow a subset of the PEP 257 conventions.
|
||||
- [docstrfmt](https://github.com/LilSpazJoekp/docstrfmt) - reStructuredText formatter.
|
||||
- [doctoc](https://github.com/thlorenz/doctoc) - Generates table of contents for markdown files inside local git repository.
|
||||
- [dprint](https://github.com/dprint/dprint) - Pluggable and configurable code formatting platform written in Rust.
|
||||
- [easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) - ecs - Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer.
|
||||
- [efmt](https://github.com/sile/efmt) - Erlang code formatter.
|
||||
@ -234,6 +243,7 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [gdformat](https://github.com/Scony/godot-gdscript-toolkit) - A formatter for Godot's gdscript.
|
||||
- [gersemi](https://github.com/BlankSpruce/gersemi) - A formatter to make your CMake code the real treasure.
|
||||
- [gleam](https://github.com/gleam-lang/gleam) - ⭐️ A friendly language for building type-safe, scalable systems!
|
||||
- [gluon_fmt](https://github.com/gluon-lang/gluon) - Code formatting for the gluon programming language.
|
||||
- [gn](https://gn.googlesource.com/gn/) - gn build system.
|
||||
- [gofmt](https://pkg.go.dev/cmd/gofmt) - Formats go programs.
|
||||
- [gofumpt](https://github.com/mvdan/gofumpt) - Enforce a stricter format than gofmt, while being backwards compatible. That is, gofumpt is happy with a subset of the formats that gofmt is happy with.
|
||||
@ -241,9 +251,11 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [goimports-reviser](https://github.com/incu6us/goimports-reviser) - Right imports sorting & code formatting tool (goimports alternative).
|
||||
- [golines](https://github.com/segmentio/golines) - A golang formatter that fixes long lines.
|
||||
- [google-java-format](https://github.com/google/google-java-format) - Reformats Java source code according to Google Java Style.
|
||||
- [grain_format](https://grain-lang.org/docs/tooling/grain_cli#grain-format) - Code formatter for the grain programming language.
|
||||
- [hcl](https://github.com/hashicorp/hcl) - A formatter for HCL files.
|
||||
- [hindent](https://github.com/mihaimaruseac/hindent) - Haskell pretty printer.
|
||||
- [htmlbeautifier](https://github.com/threedaymonk/htmlbeautifier) - A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates.
|
||||
- [imba_fmt](https://imba.io/) - Code formatter for the Imba programming language.
|
||||
- [indent](https://www.gnu.org/software/indent/) - GNU Indent.
|
||||
- [injected](doc/advanced_topics.md#injected-language-formatting-code-blocks) - Format treesitter injected languages.
|
||||
- [inko](https://inko-lang.org/) - A language for building concurrent software with confidence
|
||||
@ -267,6 +279,7 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [mdsf](https://github.com/hougesen/mdsf) - Format markdown code blocks using your favorite code formatters.
|
||||
- [mdslw](https://github.com/razziel89/mdslw) - Prepare your markdown for easy diff'ing by adding line breaks after every sentence.
|
||||
- [mix](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) - Format Elixir files using the mix format command.
|
||||
- [nickel](https://nickel-lang.org/) - Code formatter for the Nickel programming language.
|
||||
- [nimpretty](https://github.com/nim-lang/nim) - nimpretty is a Nim source code beautifier that follows the official style guide.
|
||||
- [nixfmt](https://github.com/serokell/nixfmt) - nixfmt is a formatter for Nix code, intended to apply a uniform style.
|
||||
- [nixpkgs_fmt](https://github.com/nix-community/nixpkgs-fmt) - nixpkgs-fmt is a Nix code formatter for nixpkgs.
|
||||
@ -306,6 +319,7 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [shellcheck](https://github.com/koalaman/shellcheck) - A static analysis tool for shell scripts.
|
||||
- [shellharden](https://github.com/anordal/shellharden) - The corrective bash syntax highlighter.
|
||||
- [shfmt](https://github.com/mvdan/sh) - A shell parser, formatter, and interpreter with `bash` support.
|
||||
- [sleek](https://github.com/nrempel/sleek) - Sleek is a CLI tool for formatting SQL.
|
||||
- [smlfmt](https://github.com/shwestrick/smlfmt) - A custom parser and code formatter for Standard ML.
|
||||
- [snakefmt](https://github.com/snakemake/snakefmt) - a formatting tool for Snakemake files following the design of Black.
|
||||
- [sql_formatter](https://github.com/sql-formatter-org/sql-formatter) - A whitespace formatter for different query languages.
|
||||
@ -320,14 +334,15 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [stylua](https://github.com/JohnnyMorganz/StyLua) - An opinionated code formatter for Lua.
|
||||
- [swift_format](https://github.com/apple/swift-format) - Swift formatter from apple. Requires building from source with `swift build`.
|
||||
- [swiftformat](https://github.com/nicklockwood/SwiftFormat) - SwiftFormat is a code library and command-line tool for reformatting `swift` code on macOS or Linux.
|
||||
- [swiftlint](https://github.com/realm/SwiftLint) - A tool to enforce Swift style and conventions.
|
||||
- [taplo](https://github.com/tamasfe/taplo) - A TOML toolkit written in Rust.
|
||||
- [templ](https://templ.guide/commands-and-tools/cli/#formatting-templ-files) - Formats templ template files.
|
||||
- [terraform_fmt](https://www.terraform.io/docs/cli/commands/fmt.html) - The terraform-fmt command rewrites `terraform` configuration files to a canonical format and style.
|
||||
- [terragrunt_hclfmt](https://terragrunt.gruntwork.io/docs/reference/cli-options/#hclfmt) - Format hcl files into a canonical format.
|
||||
- [tlint](https://github.com/tighten/tlint) - Tighten linter for Laravel conventions with support for auto-formatting.
|
||||
- [tofu_fmt](https://opentofu.org/docs/cli/commands/fmt/) - The tofu-fmt command rewrites OpenTofu configuration files to a canonical format and style.
|
||||
- [trim_newlines](https://www.gnu.org/software/gawk/manual/gawk.html) - Trim new lines with awk.
|
||||
- [trim_whitespace](https://www.gnu.org/software/gawk/manual/gawk.html) - Trim whitespaces with awk.
|
||||
- [trim_newlines](https://github.com/stevearc/conform.nvim/blob/master/lua/conform/formatters/trim_whitespace.lua) - Trim empty lines at the end of the file.
|
||||
- [trim_whitespace](https://github.com/stevearc/conform.nvim/blob/master/lua/conform/formatters/trim_whitespace.lua) - Trim trailing whitespace.
|
||||
- [twig-cs-fixer](https://github.com/VincentLanglet/Twig-CS-Fixer) - Automatically fix Twig Coding Standards issues
|
||||
- [typos](https://github.com/crate-ci/typos) - Source code spell checker
|
||||
- [typstyle](https://github.com/Enter-tainer/typstyle) - Beautiful and reliable typst code formatter.
|
||||
@ -419,6 +434,8 @@ require("conform").formatters.shfmt = {
|
||||
- [Command to toggle format-on-save](doc/recipes.md#command-to-toggle-format-on-save)
|
||||
- [Automatically run slow formatters async](doc/recipes.md#automatically-run-slow-formatters-async)
|
||||
- [Lazy loading with lazy.nvim](doc/recipes.md#lazy-loading-with-lazynvim)
|
||||
- [Leave visual mode after range format](doc/recipes.md#leave-visual-mode-after-range-format)
|
||||
- [Run the first available formatter followed by more formatters](doc/recipes.md#run-the-first-available-formatter-followed-by-more-formatters)
|
||||
|
||||
<!-- /RECIPES -->
|
||||
|
||||
@ -445,8 +462,8 @@ require("conform").setup({
|
||||
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
|
||||
@ -461,6 +478,11 @@ require("conform").setup({
|
||||
-- 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.
|
||||
@ -479,6 +501,8 @@ require("conform").setup({
|
||||
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 = {
|
||||
@ -515,7 +539,6 @@ require("conform").setup({
|
||||
-- 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.
|
||||
@ -564,9 +587,11 @@ require("conform").formatters.my_formatter = {
|
||||
| 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` | 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. |
|
||||
| | default_format_opts | `nil\|conform.DefaultFormatOpts` | The default options to use when calling conform.format() |
|
||||
| | 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. |
|
||||
| | log_level | `nil\|integer` | Set the log level (e.g. `vim.log.levels.DEBUG`). Use `:ConformInfo` to see the location of the log file. |
|
||||
| | notify_on_error | `nil\|boolean` | Conform will notify you when a formatter errors (default true). |
|
||||
| | 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)
|
||||
@ -574,21 +599,28 @@ require("conform").formatters.my_formatter = {
|
||||
`format(opts, callback): boolean` \
|
||||
Format a buffer
|
||||
|
||||
| Param | Type | Desc | |
|
||||
| -------- | ---------------------------------------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 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"` | "fallback" 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 |
|
||||
| callback | `nil\|fun(err: nil\|string, did_edit: nil\|boolean)` | Called once formatting has completed | |
|
||||
| Param | Type | Desc | |
|
||||
| -------- | ---------------------------------------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 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 |
|
||||
| | 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 |
|
||||
| | 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 |
|
||||
| callback | `nil\|fun(err: nil\|string, did_edit: nil\|boolean)` | Called once formatting has completed | |
|
||||
|
||||
Returns:
|
||||
|
||||
@ -605,6 +637,27 @@ Retrieve the available formatters for a buffer
|
||||
| ----- | -------------- | ---- |
|
||||
| bufnr | `nil\|integer` | |
|
||||
|
||||
### list_formatters_to_run(bufnr)
|
||||
|
||||
`list_formatters_to_run(bufnr): conform.FormatterInfo[], boolean` \
|
||||
Get the exact formatters that will be run for a buffer.
|
||||
|
||||
| Param | Type | Desc |
|
||||
| ----- | -------------- | ---- |
|
||||
| bufnr | `nil\|integer` | |
|
||||
|
||||
Returns:
|
||||
|
||||
| Type | Desc |
|
||||
| ----------------------- | -------------------------- |
|
||||
| conform.FormatterInfo[] | |
|
||||
| boolean | lsp Will use LSP formatter |
|
||||
|
||||
**Note:**
|
||||
<pre>
|
||||
This accounts for stop_after_first, lsp fallback logic, etc.
|
||||
</pre>
|
||||
|
||||
### list_all_formatters()
|
||||
|
||||
`list_all_formatters(): conform.FormatterInfo[]` \
|
||||
@ -620,15 +673,6 @@ Get information about a formatter (including availability)
|
||||
| --------- | -------------- | ------------------------- |
|
||||
| formatter | `string` | The name of the formatter |
|
||||
| bufnr | `nil\|integer` | |
|
||||
|
||||
### will_fallback_lsp(options)
|
||||
|
||||
`will_fallback_lsp(options): boolean` \
|
||||
Check if the buffer will use LSP formatting when lsp_format = "fallback"
|
||||
|
||||
| Param | Type | Desc |
|
||||
| ------- | ------------ | ------------------------------------ |
|
||||
| options | `nil\|table` | Options passed to vim.lsp.buf.format |
|
||||
<!-- /API -->
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
@ -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*
|
||||
|
||||
@ -7,7 +7,7 @@ return {
|
||||
},
|
||||
command = util.from_node_modules("biome"),
|
||||
stdin = true,
|
||||
args = { "check", "--apply", "--stdin-file-path", "$FILENAME" },
|
||||
args = { "check", "--write", "--stdin-file-path", "$FILENAME" },
|
||||
cwd = util.root_file({
|
||||
"biome.json",
|
||||
"biome.jsonc",
|
||||
|
||||
@ -6,10 +6,9 @@ return {
|
||||
description = "✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang.",
|
||||
},
|
||||
command = "djlint",
|
||||
args = {
|
||||
"--reformat",
|
||||
"-",
|
||||
},
|
||||
args = function(_, ctx)
|
||||
return { "--reformat", "--indent", ctx.shiftwidth, "-" }
|
||||
end,
|
||||
cwd = util.root_file({
|
||||
".djlintrc",
|
||||
}),
|
||||
|
||||
@ -136,12 +136,6 @@ return {
|
||||
-- (defaults to the value from formatters_by_ft)
|
||||
lang_to_formatters = {},
|
||||
},
|
||||
condition = function(self, ctx)
|
||||
local ok, parser = pcall(vim.treesitter.get_parser, ctx.buf)
|
||||
-- Require Neovim 0.9 because the treesitter API has changed significantly
|
||||
---@diagnostic disable-next-line: invisible
|
||||
return ok and parser._injection_query and vim.fn.has("nvim-0.9") == 1
|
||||
end,
|
||||
format = function(self, ctx, lines, callback)
|
||||
local conform = require("conform")
|
||||
local errors = require("conform.errors")
|
||||
@ -284,13 +278,21 @@ return {
|
||||
---@type string[]
|
||||
local formatter_names
|
||||
if type(ft_formatters) == "function" then
|
||||
formatter_names = ft_formatters(ctx.buf)
|
||||
else
|
||||
local formatters = require("conform").resolve_formatters(ft_formatters, ctx.buf, false)
|
||||
formatter_names = vim.tbl_map(function(f)
|
||||
return f.name
|
||||
end, formatters)
|
||||
ft_formatters = ft_formatters(ctx.buf)
|
||||
end
|
||||
local stop_after_first = ft_formatters.stop_after_first
|
||||
if stop_after_first == nil then
|
||||
stop_after_first = conform.default_format_opts.stop_after_first
|
||||
end
|
||||
if stop_after_first == nil then
|
||||
stop_after_first = false
|
||||
end
|
||||
|
||||
local formatters =
|
||||
conform.resolve_formatters(ft_formatters, ctx.buf, false, stop_after_first)
|
||||
formatter_names = vim.tbl_map(function(f)
|
||||
return f.name
|
||||
end, formatters)
|
||||
local idx = num_format
|
||||
log.debug("Injected format %s:%d:%d: %s", lang, start_lnum, end_lnum, formatter_names)
|
||||
log.trace("Injected format lines %s", input_lines)
|
||||
|
||||
@ -6,10 +6,10 @@ return {
|
||||
},
|
||||
command = "markdown-toc",
|
||||
stdin = false,
|
||||
args = function(self, ctx)
|
||||
args = function(_, ctx)
|
||||
-- use the indentation set in the current buffer, effectively allowing us to
|
||||
-- use values from .editorconfig
|
||||
local indent = vim.bo[ctx.buf].expandtab and (" "):rep(vim.bo[ctx.buf].tabstop) or "\t"
|
||||
local indent = vim.bo[ctx.buf].expandtab and (" "):rep(ctx.shiftwidth) or "\t"
|
||||
return { "--indent=" .. indent, "-i", "$FILENAME" }
|
||||
end,
|
||||
}
|
||||
|
||||
@ -5,5 +5,15 @@ return {
|
||||
description = "A shell parser, formatter, and interpreter with `bash` support.",
|
||||
},
|
||||
command = "shfmt",
|
||||
args = { "-filename", "$FILENAME" },
|
||||
args = function(_, ctx)
|
||||
local args = { "-filename", "$FILENAME" }
|
||||
local has_editorconfig = vim.fs.find(".editorconfig", { path = ctx.dirname, upward = true })[1]
|
||||
~= nil
|
||||
-- If there is an editorconfig, don't pass any args because shfmt will apply settings from there
|
||||
-- when no command line args are passed.
|
||||
if not has_editorconfig and vim.bo[ctx.buf].expandtab then
|
||||
vim.list_extend(args, { "-i", ctx.shiftwidth })
|
||||
end
|
||||
return args
|
||||
end,
|
||||
}
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
---@type conform.FileFormatterConfig
|
||||
---@type conform.FileLuaFormatterConfig
|
||||
return {
|
||||
meta = {
|
||||
url = "https://www.gnu.org/software/gawk/manual/gawk.html",
|
||||
description = "Trim new lines with awk.",
|
||||
url = "https://github.com/stevearc/conform.nvim/blob/master/lua/conform/formatters/trim_whitespace.lua",
|
||||
description = "Trim empty lines at the end of the file.",
|
||||
},
|
||||
command = "awk",
|
||||
args = { 'NF{print s $0; s=""; next} {s=s ORS}' },
|
||||
format = function(self, ctx, lines, callback)
|
||||
local out_lines = vim.deepcopy(lines)
|
||||
while #out_lines > 0 and out_lines[#out_lines] == "" do
|
||||
table.remove(out_lines)
|
||||
end
|
||||
callback(nil, out_lines)
|
||||
end,
|
||||
}
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
---@type conform.FileFormatterConfig
|
||||
---@type conform.FileLuaFormatterConfig
|
||||
return {
|
||||
meta = {
|
||||
url = "https://www.gnu.org/software/gawk/manual/gawk.html",
|
||||
description = "Trim whitespaces with awk.",
|
||||
url = "https://github.com/stevearc/conform.nvim/blob/master/lua/conform/formatters/trim_whitespace.lua",
|
||||
description = "Trim trailing whitespace.",
|
||||
},
|
||||
command = "awk",
|
||||
args = { '{ sub(/[ \t]+$/, ""); print }' },
|
||||
format = function(self, ctx, lines, callback)
|
||||
local out_lines = {}
|
||||
for _, line in ipairs(lines) do
|
||||
local trimmed = line:gsub("%s+$", "")
|
||||
table.insert(out_lines, trimmed)
|
||||
end
|
||||
callback(nil, out_lines)
|
||||
end,
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ local health_start = vim.health.start or vim.health.report_start
|
||||
local health_warn = vim.health.warn or vim.health.report_warn
|
||||
local health_info = vim.health.info or vim.health.report_info
|
||||
local health_ok = vim.health.ok or vim.health.report_ok
|
||||
local islist = vim.islist or vim.tbl_islist
|
||||
|
||||
---@param name string
|
||||
---@return string[]
|
||||
@ -16,14 +15,6 @@ local function get_formatter_filetypes(name)
|
||||
for filetype, formatters in pairs(conform.formatters_by_ft) do
|
||||
if type(formatters) == "function" then
|
||||
formatters = formatters(0)
|
||||
-- support the old structure where formatters could be a subkey
|
||||
elseif not islist(formatters) then
|
||||
vim.notify_once(
|
||||
"Using deprecated structure for formatters_by_ft. See :help conform-options for details.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
formatters = formatters.formatters
|
||||
end
|
||||
|
||||
for _, ft_name in ipairs(formatters) do
|
||||
@ -61,7 +52,7 @@ M.check = function()
|
||||
end
|
||||
end
|
||||
|
||||
---@param formatters conform.FormatterUnit[]
|
||||
---@param formatters conform.FiletypeFormatterInternal
|
||||
---@return string[]
|
||||
local function flatten_formatters(formatters)
|
||||
local flat = {}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local islist = vim.islist or vim.tbl_islist
|
||||
local M = {}
|
||||
|
||||
---@type table<string, conform.FiletypeFormatter>
|
||||
@ -9,20 +7,72 @@ M.formatters_by_ft = {}
|
||||
M.formatters = {}
|
||||
|
||||
M.notify_on_error = true
|
||||
M.notify_no_formatters = true
|
||||
|
||||
---@type conform.DefaultFormatOpts
|
||||
M.default_format_opts = {}
|
||||
|
||||
-- Defer notifications because nvim-notify can throw errors if called immediately
|
||||
-- in some contexts (e.g. inside statusline function)
|
||||
local notify = vim.schedule_wrap(function(...)
|
||||
vim.notify(...)
|
||||
end)
|
||||
local notify_once = vim.schedule_wrap(function(...)
|
||||
vim.notify_once(...)
|
||||
end)
|
||||
|
||||
local allowed_default_opts = { "timeout_ms", "lsp_format", "quiet", "stop_after_first" }
|
||||
local function merge_default_opts(a, b)
|
||||
for _, key in ipairs(allowed_default_opts) do
|
||||
if a[key] == nil then
|
||||
a[key] = b[key]
|
||||
end
|
||||
end
|
||||
return a
|
||||
end
|
||||
|
||||
---@param conf? conform.FiletypeFormatter
|
||||
local function check_for_default_opts(conf)
|
||||
if not conf or type(conf) ~= "table" then
|
||||
return
|
||||
end
|
||||
for k in pairs(conf) do
|
||||
if type(k) == "string" then
|
||||
notify(
|
||||
string.format(
|
||||
'conform.setup: the "_" and "*" keys in formatters_by_ft do not support configuring format options, such as "%s"',
|
||||
k
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts? conform.setupOpts
|
||||
M.setup = function(opts)
|
||||
if vim.fn.has("nvim-0.9") == 0 then
|
||||
notify("conform.nvim requires Neovim 0.9+", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
opts = opts or {}
|
||||
|
||||
M.formatters = vim.tbl_extend("force", M.formatters, opts.formatters or {})
|
||||
M.formatters_by_ft = vim.tbl_extend("force", M.formatters_by_ft, opts.formatters_by_ft or {})
|
||||
check_for_default_opts(M.formatters_by_ft["_"])
|
||||
check_for_default_opts(M.formatters_by_ft["*"])
|
||||
M.default_format_opts =
|
||||
vim.tbl_extend("force", M.default_format_opts, opts.default_format_opts or {})
|
||||
|
||||
if opts.log_level then
|
||||
require("conform.log").level = opts.log_level
|
||||
end
|
||||
local notify_on_error = opts.notify_on_error
|
||||
if notify_on_error ~= nil then
|
||||
M.notify_on_error = notify_on_error
|
||||
if opts.notify_on_error ~= nil then
|
||||
M.notify_on_error = opts.notify_on_error
|
||||
end
|
||||
if opts.notify_no_formatters ~= nil then
|
||||
M.notify_no_formatters = opts.notify_no_formatters
|
||||
end
|
||||
|
||||
local aug = vim.api.nvim_create_augroup("Conform", { clear = true })
|
||||
@ -44,7 +94,7 @@ M.setup = function(opts)
|
||||
end
|
||||
if format_args then
|
||||
if format_args.async then
|
||||
vim.notify_once(
|
||||
notify_once(
|
||||
"Conform format_on_save cannot use async=true. Use format_after_save instead.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
@ -97,7 +147,7 @@ M.setup = function(opts)
|
||||
exit_timeout = format_args.timeout_ms or exit_timeout
|
||||
num_running_format_jobs = num_running_format_jobs + 1
|
||||
if format_args.async == false then
|
||||
vim.notify_once(
|
||||
notify_once(
|
||||
"Conform format_after_save cannot use async=false. Use format_on_save instead.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
@ -174,7 +224,7 @@ end
|
||||
|
||||
---Get the configured formatter filetype for a buffer
|
||||
---@param bufnr? integer
|
||||
---@return nil|string filetype or nil if no formatter is configured
|
||||
---@return nil|string filetype or nil if no formatter is configured. Can be "_".
|
||||
local function get_matching_filetype(bufnr)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
@ -193,7 +243,7 @@ end
|
||||
|
||||
---@private
|
||||
---@param bufnr? integer
|
||||
---@return conform.FormatterUnit[]
|
||||
---@return string[]
|
||||
M.list_formatters_for_buffer = function(bufnr)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
@ -204,6 +254,10 @@ M.list_formatters_for_buffer = function(bufnr)
|
||||
local function dedupe_formatters(names, collect)
|
||||
for _, name in ipairs(names) do
|
||||
if type(name) == "table" then
|
||||
notify_once(
|
||||
"deprecated[conform]: The nested {} syntax to run the first formatter has been replaced by the stop_after_first option (see :help conform.format).\nSupport for the old syntax will be dropped on 2025-01-01.",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local alternation = {}
|
||||
dedupe_formatters(name, alternation)
|
||||
if not vim.tbl_isempty(alternation) then
|
||||
@ -228,16 +282,6 @@ M.list_formatters_for_buffer = function(bufnr)
|
||||
if type(ft_formatters) == "function" then
|
||||
dedupe_formatters(ft_formatters(bufnr), formatters)
|
||||
else
|
||||
-- support the old structure where formatters could be a subkey
|
||||
if not islist(ft_formatters) then
|
||||
vim.notify_once(
|
||||
"Using deprecated structure for formatters_by_ft. See :help conform-options for details.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
ft_formatters = ft_formatters.formatters
|
||||
end
|
||||
|
||||
dedupe_formatters(ft_formatters, formatters)
|
||||
end
|
||||
end
|
||||
@ -246,6 +290,25 @@ M.list_formatters_for_buffer = function(bufnr)
|
||||
return formatters
|
||||
end
|
||||
|
||||
---@param bufnr? integer
|
||||
---@return nil|conform.DefaultFormatOpts
|
||||
local function get_opts_from_filetype(bufnr)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
local matching_filetype = get_matching_filetype(bufnr)
|
||||
if not matching_filetype then
|
||||
return nil
|
||||
end
|
||||
|
||||
local ft_formatters = M.formatters_by_ft[matching_filetype]
|
||||
assert(ft_formatters ~= nil, "get_matching_filetype ensures formatters_by_ft has key")
|
||||
if type(ft_formatters) == "function" then
|
||||
ft_formatters = ft_formatters(bufnr)
|
||||
end
|
||||
return merge_default_opts({}, ft_formatters)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param mode "v"|"V"
|
||||
---@return table {start={row,col}, end={row,col}} using (1, 0) indexing
|
||||
@ -278,17 +341,18 @@ local function range_from_selection(bufnr, mode)
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param names conform.FormatterUnit[]
|
||||
---@param names conform.FiletypeFormatterInternal
|
||||
---@param bufnr integer
|
||||
---@param warn_on_missing boolean
|
||||
---@param stop_after_first boolean
|
||||
---@return conform.FormatterInfo[]
|
||||
M.resolve_formatters = function(names, bufnr, warn_on_missing)
|
||||
M.resolve_formatters = function(names, bufnr, warn_on_missing, stop_after_first)
|
||||
local all_info = {}
|
||||
local function add_info(info, warn)
|
||||
if info.available then
|
||||
table.insert(all_info, info)
|
||||
elseif warn then
|
||||
vim.notify(
|
||||
notify(
|
||||
string.format("Formatter '%s' unavailable: %s", info.name, info.available_msg),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
@ -301,6 +365,10 @@ M.resolve_formatters = function(names, bufnr, warn_on_missing)
|
||||
local info = M.get_formatter_info(name, bufnr)
|
||||
add_info(info, warn_on_missing)
|
||||
else
|
||||
notify_once(
|
||||
"deprecated[conform]: The nested {} syntax to run the first formatter has been replaced by the stop_after_first option (see :help conform.format).\nSupport for the old syntax will be dropped on 2025-01-01.",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
-- If this is an alternation, take the first one that's available
|
||||
for i, v in ipairs(name) do
|
||||
local info = M.get_formatter_info(v, bufnr)
|
||||
@ -309,6 +377,10 @@ M.resolve_formatters = function(names, bufnr, warn_on_missing)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if stop_after_first and #all_info > 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
return all_info
|
||||
end
|
||||
@ -328,33 +400,34 @@ local function has_lsp_formatter(opts)
|
||||
return not vim.tbl_isempty(lsp_format.get_format_clients(opts))
|
||||
end
|
||||
|
||||
---@class conform.FormatOpts
|
||||
---@field timeout_ms nil|integer Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true.
|
||||
---@field bufnr nil|integer Format this buffer (default 0)
|
||||
---@field 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.
|
||||
---@field dry_run nil|boolean If true don't apply formatting changes to the buffer
|
||||
---@field formatters nil|string[] List of formatters to run. Defaults to all formatters for the buffer filetype.
|
||||
---@field lsp_format? "never"|"fallback"|"prefer"|"first"|"last" "fallback" 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.
|
||||
---@field quiet nil|boolean Don't show any notifications for warnings or failures. Defaults to false.
|
||||
---@field 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
|
||||
---@field id nil|integer Passed to |vim.lsp.buf.format| when using LSP formatting
|
||||
---@field name nil|string Passed to |vim.lsp.buf.format| when using LSP formatting
|
||||
---@field filter nil|fun(client: table): boolean Passed to |vim.lsp.buf.format| when using LSP formatting
|
||||
local has_notified_ft_no_formatters = {}
|
||||
|
||||
---Format a buffer
|
||||
---@param opts? conform.FormatOpts
|
||||
---@param callback? fun(err: nil|string, did_edit: nil|boolean) Called once formatting has completed
|
||||
---@return boolean True if any formatters were attempted
|
||||
M.format = function(opts, callback)
|
||||
---@type {timeout_ms: integer, bufnr: integer, async: boolean, dry_run: boolean, lsp_format: "never"|"first"|"last"|"prefer"|"fallback", quiet: boolean, formatters?: string[], range?: conform.Range}
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
opts = opts or {}
|
||||
local has_explicit_formatters = opts.formatters ~= nil
|
||||
-- If formatters were not passed in directly, fetch any options from formatters_by_ft
|
||||
if not has_explicit_formatters then
|
||||
merge_default_opts(opts, get_opts_from_filetype(opts.bufnr) or {})
|
||||
end
|
||||
merge_default_opts(opts, M.default_format_opts)
|
||||
---@type {timeout_ms: integer, bufnr: integer, async: boolean, dry_run: boolean, lsp_format: "never"|"first"|"last"|"prefer"|"fallback", quiet: boolean, stop_after_first: boolean, formatters?: string[], range?: conform.Range, undojoin: boolean}
|
||||
opts = vim.tbl_extend("keep", opts, {
|
||||
timeout_ms = 1000,
|
||||
bufnr = 0,
|
||||
async = false,
|
||||
dry_run = false,
|
||||
lsp_format = "never",
|
||||
quiet = false,
|
||||
undojoin = false,
|
||||
stop_after_first = false,
|
||||
})
|
||||
if opts.bufnr == 0 then
|
||||
opts.bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
-- For backwards compatibility
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
@ -365,9 +438,6 @@ M.format = function(opts, callback)
|
||||
opts.lsp_format = "last"
|
||||
end
|
||||
|
||||
if opts.bufnr == 0 then
|
||||
opts.bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
local mode = vim.api.nvim_get_mode().mode
|
||||
if not opts.range and mode == "v" or mode == "V" then
|
||||
opts.range = range_from_selection(opts.bufnr, mode)
|
||||
@ -378,18 +448,23 @@ M.format = function(opts, callback)
|
||||
local lsp_format = require("conform.lsp_format")
|
||||
local runner = require("conform.runner")
|
||||
|
||||
local explicit_formatters = opts.formatters ~= nil
|
||||
local formatter_names = opts.formatters or M.list_formatters_for_buffer(opts.bufnr)
|
||||
local formatters =
|
||||
M.resolve_formatters(formatter_names, opts.bufnr, not opts.quiet and explicit_formatters)
|
||||
local formatters = M.resolve_formatters(
|
||||
formatter_names,
|
||||
opts.bufnr,
|
||||
not opts.quiet and has_explicit_formatters,
|
||||
opts.stop_after_first
|
||||
)
|
||||
local has_lsp = has_lsp_formatter(opts)
|
||||
|
||||
---Handle errors and maybe run LSP formatting after cli formatters complete
|
||||
---@param err? conform.Error
|
||||
---@param did_edit? boolean
|
||||
local function handle_result(err, did_edit)
|
||||
if err then
|
||||
local level = errors.level_for_code(err.code)
|
||||
log.log(level, err.message)
|
||||
---@type boolean?
|
||||
local should_notify = not opts.quiet and level >= vim.log.levels.WARN
|
||||
-- Execution errors have special handling. Maybe should reconsider this.
|
||||
local notify_msg = err.message
|
||||
@ -398,7 +473,7 @@ M.format = function(opts, callback)
|
||||
notify_msg = "Formatter failed. See :ConformInfo for details"
|
||||
end
|
||||
if should_notify then
|
||||
vim.notify(notify_msg, level)
|
||||
notify(notify_msg, level)
|
||||
end
|
||||
end
|
||||
local err_message = err and err.message
|
||||
@ -418,12 +493,15 @@ M.format = function(opts, callback)
|
||||
callback(nil, did_edit)
|
||||
end
|
||||
end
|
||||
|
||||
---Run the resolved formatters on the buffer
|
||||
local function run_cli_formatters(cb)
|
||||
local resolved_names = vim.tbl_map(function(f)
|
||||
return f.name
|
||||
end, formatters)
|
||||
log.debug("Running formatters on %s: %s", vim.api.nvim_buf_get_name(opts.bufnr), resolved_names)
|
||||
local run_opts = { exclusive = true, dry_run = opts.dry_run }
|
||||
---@type conform.RunOpts
|
||||
local run_opts = { exclusive = true, dry_run = opts.dry_run, undojoin = opts.undojoin }
|
||||
if opts.async then
|
||||
runner.format_async(opts.bufnr, formatters, opts.range, run_opts, cb)
|
||||
else
|
||||
@ -461,19 +539,25 @@ M.format = function(opts, callback)
|
||||
run_cli_formatters(handle_result)
|
||||
return true
|
||||
else
|
||||
local level = explicit_formatters and "warn" or "debug"
|
||||
log[level]("No formatters found for %s", vim.api.nvim_buf_get_name(opts.bufnr))
|
||||
callback("No formatters found for buffer")
|
||||
local level = has_explicit_formatters and "warn" or "debug"
|
||||
log[level]("Formatters unavailable for %s", vim.api.nvim_buf_get_name(opts.bufnr))
|
||||
|
||||
local ft = vim.bo[opts.bufnr].filetype
|
||||
if
|
||||
not vim.tbl_isempty(formatter_names)
|
||||
and not has_notified_ft_no_formatters[ft]
|
||||
and not opts.quiet
|
||||
and M.notify_no_formatters
|
||||
then
|
||||
notify(string.format("Formatters unavailable for %s file", ft), vim.log.levels.WARN)
|
||||
has_notified_ft_no_formatters[ft] = true
|
||||
end
|
||||
|
||||
callback("No formatters available for buffer")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
---@class conform.FormatLinesOpts
|
||||
---@field timeout_ms nil|integer Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true.
|
||||
---@field bufnr nil|integer use this as the working buffer (default 0)
|
||||
---@field 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.
|
||||
---@field quiet nil|boolean Don't show any notifications for warnings or failures. Defaults to false.
|
||||
|
||||
---Process lines with formatters
|
||||
---@private
|
||||
---@param formatter_names string[]
|
||||
@ -483,18 +567,20 @@ end
|
||||
---@return nil|conform.Error error Only present if async = false
|
||||
---@return nil|string[] new_lines Only present if async = false
|
||||
M.format_lines = function(formatter_names, lines, opts, callback)
|
||||
---@type {timeout_ms: integer, bufnr: integer, async: boolean, quiet: boolean}
|
||||
---@type {timeout_ms: integer, bufnr: integer, async: boolean, quiet: boolean, stop_after_first: boolean}
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
timeout_ms = 1000,
|
||||
bufnr = 0,
|
||||
async = false,
|
||||
quiet = false,
|
||||
stop_after_first = false,
|
||||
})
|
||||
callback = callback or function(_err, _lines) end
|
||||
local errors = require("conform.errors")
|
||||
local log = require("conform.log")
|
||||
local runner = require("conform.runner")
|
||||
local formatters = M.resolve_formatters(formatter_names, opts.bufnr, not opts.quiet)
|
||||
local formatters =
|
||||
M.resolve_formatters(formatter_names, opts.bufnr, not opts.quiet, opts.stop_after_first)
|
||||
if vim.tbl_isempty(formatters) then
|
||||
callback(nil, lines)
|
||||
return
|
||||
@ -510,7 +596,8 @@ M.format_lines = function(formatter_names, lines, opts, callback)
|
||||
callback(err, new_lines)
|
||||
end
|
||||
|
||||
local run_opts = { exclusive = false, dry_run = false }
|
||||
---@type conform.RunOpts
|
||||
local run_opts = { exclusive = false, dry_run = false, undojoin = false }
|
||||
if opts.async then
|
||||
runner.format_lines_async(opts.bufnr, formatters, nil, lines, run_opts, handle_err)
|
||||
else
|
||||
@ -529,7 +616,44 @@ M.list_formatters = function(bufnr)
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
local formatters = M.list_formatters_for_buffer(bufnr)
|
||||
return M.resolve_formatters(formatters, bufnr, false)
|
||||
return M.resolve_formatters(formatters, bufnr, false, false)
|
||||
end
|
||||
|
||||
---Get the exact formatters that will be run for a buffer.
|
||||
---@param bufnr? integer
|
||||
---@return conform.FormatterInfo[]
|
||||
---@return boolean lsp Will use LSP formatter
|
||||
---@note
|
||||
--- This accounts for stop_after_first, lsp fallback logic, etc.
|
||||
M.list_formatters_to_run = function(bufnr)
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
---@type {bufnr: integer, lsp_format: conform.LspFormatOpts, stop_after_first: boolean}
|
||||
local opts = vim.tbl_extend(
|
||||
"keep",
|
||||
get_opts_from_filetype(bufnr) or {},
|
||||
M.default_format_opts,
|
||||
{ stop_after_first = false, lsp_format = "never", bufnr = bufnr }
|
||||
)
|
||||
local formatter_names = M.list_formatters_for_buffer(bufnr)
|
||||
local formatters = M.resolve_formatters(formatter_names, bufnr, false, opts.stop_after_first)
|
||||
|
||||
local has_lsp = has_lsp_formatter(opts)
|
||||
local any_formatters = has_filetype_formatters(opts.bufnr) and not vim.tbl_isempty(formatters)
|
||||
|
||||
if
|
||||
has_lsp
|
||||
and (opts.lsp_format == "prefer" or (opts.lsp_format ~= "never" and not any_formatters))
|
||||
then
|
||||
return {}, true
|
||||
elseif has_lsp and opts.lsp_format == "first" then
|
||||
return formatters, true
|
||||
elseif not vim.tbl_isempty(formatters) then
|
||||
return formatters, opts.lsp_format == "last" and has_lsp
|
||||
else
|
||||
return {}, false
|
||||
end
|
||||
end
|
||||
|
||||
---List information about all filetype-configured formatters
|
||||
@ -540,18 +664,13 @@ M.list_all_formatters = function()
|
||||
if type(ft_formatters) == "function" then
|
||||
ft_formatters = ft_formatters(0)
|
||||
end
|
||||
-- support the old structure where formatters could be a subkey
|
||||
if not islist(ft_formatters) then
|
||||
vim.notify_once(
|
||||
"Using deprecated structure for formatters_by_ft. See :help conform-options for details.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
ft_formatters = ft_formatters.formatters
|
||||
end
|
||||
|
||||
for _, formatter in ipairs(ft_formatters) do
|
||||
if type(formatter) == "table" then
|
||||
notify_once(
|
||||
"deprecated[conform]: The nested {} syntax to run the first formatter has been replaced by the stop_after_first option (see :help conform.format).\nSupport for the old syntax will be dropped on 2025-01-01.",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
for _, v in ipairs(formatter) do
|
||||
formatters[v] = true
|
||||
end
|
||||
@ -590,7 +709,7 @@ M.get_formatter_config = function(formatter, bufnr)
|
||||
if override and override.command and override.format then
|
||||
local msg =
|
||||
string.format("Formatter '%s' cannot define both 'command' and 'format' function", formatter)
|
||||
vim.notify_once(msg, vim.log.levels.ERROR)
|
||||
notify_once(msg, vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
|
||||
@ -612,7 +731,7 @@ M.get_formatter_config = function(formatter, bufnr)
|
||||
"Formatter '%s' missing built-in definition\nSet `command` to get rid of this error.",
|
||||
formatter
|
||||
)
|
||||
vim.notify_once(msg, vim.log.levels.ERROR)
|
||||
notify_once(msg, vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
else
|
||||
@ -696,9 +815,14 @@ M.get_formatter_info = function(formatter, bufnr)
|
||||
end
|
||||
|
||||
---Check if the buffer will use LSP formatting when lsp_format = "fallback"
|
||||
---@deprecated
|
||||
---@param options? table Options passed to |vim.lsp.buf.format|
|
||||
---@return boolean
|
||||
M.will_fallback_lsp = function(options)
|
||||
notify_once(
|
||||
"deprecated[conform]: will_fallback_lsp is deprecated. Use list_formatters_to_run instead.\nThis method will be removed on 2025-01-01.",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
options = vim.tbl_deep_extend("keep", options or {}, {
|
||||
bufnr = vim.api.nvim_get_current_buf(),
|
||||
})
|
||||
|
||||
@ -4,7 +4,7 @@ local util = require("vim.lsp.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function apply_text_edits(text_edits, bufnr, offset_encoding, dry_run)
|
||||
local function apply_text_edits(text_edits, bufnr, offset_encoding, dry_run, undojoin)
|
||||
if
|
||||
#text_edits == 1
|
||||
and text_edits[1].range.start.line == 0
|
||||
@ -25,11 +25,15 @@ local function apply_text_edits(text_edits, bufnr, offset_encoding, dry_run)
|
||||
new_lines,
|
||||
nil,
|
||||
false,
|
||||
dry_run
|
||||
dry_run,
|
||||
undojoin
|
||||
)
|
||||
elseif dry_run then
|
||||
return #text_edits > 0
|
||||
else
|
||||
if undojoin then
|
||||
vim.cmd.undojoin()
|
||||
end
|
||||
vim.lsp.util.apply_text_edits(text_edits, bufnr, offset_encoding)
|
||||
return #text_edits > 0
|
||||
end
|
||||
@ -124,8 +128,13 @@ function M.format(options, callback)
|
||||
)
|
||||
)
|
||||
else
|
||||
local this_did_edit =
|
||||
apply_text_edits(result, ctx.bufnr, client.offset_encoding, options.dry_run)
|
||||
local this_did_edit = apply_text_edits(
|
||||
result,
|
||||
ctx.bufnr,
|
||||
client.offset_encoding,
|
||||
options.dry_run,
|
||||
options.undojoin
|
||||
)
|
||||
changedtick = vim.b[bufnr].changedtick
|
||||
|
||||
if options.dry_run and this_did_edit then
|
||||
@ -145,8 +154,13 @@ function M.format(options, callback)
|
||||
local params = set_range(client, util.make_formatting_params(options.formatting_options))
|
||||
local result, err = client.request_sync(method, params, timeout_ms, bufnr)
|
||||
if result and result.result then
|
||||
local this_did_edit =
|
||||
apply_text_edits(result.result, bufnr, client.offset_encoding, options.dry_run)
|
||||
local this_did_edit = apply_text_edits(
|
||||
result.result,
|
||||
bufnr,
|
||||
client.offset_encoding,
|
||||
options.dry_run,
|
||||
options.undojoin
|
||||
)
|
||||
did_edit = did_edit or this_did_edit
|
||||
|
||||
if options.dry_run and did_edit then
|
||||
|
||||
@ -9,6 +9,7 @@ local M = {}
|
||||
---@class (exact) conform.RunOpts
|
||||
---@field exclusive boolean If true, ensure only a single formatter is running per buffer
|
||||
---@field dry_run boolean If true, do not apply changes and stop after the first formatter attempts to do so
|
||||
---@field undojoin boolean Use undojoin to merge formatting changes with previous edit
|
||||
|
||||
---@param formatter_name string
|
||||
---@param ctx conform.Context
|
||||
@ -168,8 +169,18 @@ end
|
||||
---@param new_lines string[]
|
||||
---@param range? conform.Range
|
||||
---@param only_apply_range boolean
|
||||
---@param dry_run boolean
|
||||
---@param undojoin boolean
|
||||
---@return boolean any_changes
|
||||
M.apply_format = function(bufnr, original_lines, new_lines, range, only_apply_range, dry_run)
|
||||
M.apply_format = function(
|
||||
bufnr,
|
||||
original_lines,
|
||||
new_lines,
|
||||
range,
|
||||
only_apply_range,
|
||||
dry_run,
|
||||
undojoin
|
||||
)
|
||||
if bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
@ -251,6 +262,9 @@ M.apply_format = function(bufnr, original_lines, new_lines, range, only_apply_ra
|
||||
|
||||
if not dry_run then
|
||||
log.trace("Applying text edits: %s", text_edits)
|
||||
if undojoin then
|
||||
vim.cmd.undojoin()
|
||||
end
|
||||
vim.lsp.util.apply_text_edits(text_edits, bufnr, "utf-8")
|
||||
log.trace("Done formatting %s", bufname)
|
||||
end
|
||||
@ -258,6 +272,12 @@ M.apply_format = function(bufnr, original_lines, new_lines, range, only_apply_ra
|
||||
return not vim.tbl_isempty(text_edits)
|
||||
end
|
||||
|
||||
---@param output? string[]
|
||||
---@return boolean
|
||||
local function is_empty_output(output)
|
||||
return not output or vim.tbl_isempty(output) or (#output == 1 and output[1] == "")
|
||||
end
|
||||
|
||||
---Map of formatter name to if the last run of that formatter produced an error
|
||||
---@type table<string, boolean>
|
||||
local last_run_errored = {}
|
||||
@ -388,10 +408,12 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
|
||||
log.debug("%s stdout: %s", formatter.name, stdout)
|
||||
log.debug("%s stderr: %s", formatter.name, stderr)
|
||||
local err_str
|
||||
if stderr and not vim.tbl_isempty(stderr) then
|
||||
if not is_empty_output(stderr) then
|
||||
err_str = table.concat(stderr, "\n")
|
||||
elseif stdout and not vim.tbl_isempty(stdout) then
|
||||
elseif not is_empty_output(stdout) then
|
||||
err_str = table.concat(stdout, "\n")
|
||||
else
|
||||
err_str = "unknown error"
|
||||
end
|
||||
if
|
||||
vim.api.nvim_buf_is_valid(bufnr)
|
||||
@ -450,6 +472,11 @@ M.build_context = function(bufnr, config, range)
|
||||
end
|
||||
local filename = vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
local shiftwidth = vim.bo[bufnr].shiftwidth
|
||||
if shiftwidth == 0 then
|
||||
shiftwidth = vim.bo[bufnr].tabstop
|
||||
end
|
||||
|
||||
-- Hack around checkhealth. For buffers that are not files, we need to fabricate a filename
|
||||
if vim.bo[bufnr].buftype ~= "" then
|
||||
filename = ""
|
||||
@ -482,6 +509,7 @@ M.build_context = function(bufnr, config, range)
|
||||
filename = filename,
|
||||
dirname = dirname,
|
||||
range = range,
|
||||
shiftwidth = shiftwidth,
|
||||
}
|
||||
end
|
||||
|
||||
@ -529,7 +557,8 @@ M.format_async = function(bufnr, formatters, range, opts, callback)
|
||||
output_lines,
|
||||
range,
|
||||
not all_support_range_formatting,
|
||||
opts.dry_run
|
||||
opts.dry_run,
|
||||
opts.undojoin
|
||||
)
|
||||
end
|
||||
callback(err, did_edit)
|
||||
@ -603,7 +632,8 @@ M.format_sync = function(bufnr, formatters, timeout_ms, range, opts)
|
||||
final_result,
|
||||
range,
|
||||
not all_support_range_formatting,
|
||||
opts.dry_run
|
||||
opts.dry_run,
|
||||
opts.undojoin
|
||||
)
|
||||
return err, did_edit
|
||||
end
|
||||
|
||||
@ -49,6 +49,7 @@
|
||||
---@field filename string
|
||||
---@field dirname string
|
||||
---@field range? conform.Range
|
||||
---@field shiftwidth integer
|
||||
|
||||
---@class (exact) conform.RangeContext : conform.Context
|
||||
---@field range conform.Range
|
||||
@ -57,13 +58,53 @@
|
||||
---@field start integer[]
|
||||
---@field end integer[]
|
||||
|
||||
---@alias conform.FormatterUnit string|string[]
|
||||
---@alias conform.FiletypeFormatter conform.FormatterUnit[]|fun(bufnr: integer): string[]
|
||||
---@alias conform.FiletypeFormatter conform.FiletypeFormatterInternal|fun(bufnr: integer): conform.FiletypeFormatterInternal
|
||||
|
||||
---This list of formatters to run for a filetype, an any associated format options.
|
||||
---@class conform.FiletypeFormatterInternal : conform.DefaultFormatOpts
|
||||
---@field [integer] string
|
||||
|
||||
---@alias conform.LspFormatOpts
|
||||
---| '"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
|
||||
|
||||
---@class (exact) conform.FormatOpts
|
||||
---@field timeout_ms? integer Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true.
|
||||
---@field bufnr? integer Format this buffer (default 0)
|
||||
---@field async? 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.
|
||||
---@field dry_run? boolean If true don't apply formatting changes to the buffer
|
||||
---@field undojoin? boolean Use undojoin to merge formatting changes with previous edit (default false)
|
||||
---@field formatters? string[] List of formatters to run. Defaults to all formatters for the buffer filetype.
|
||||
---@field lsp_format? conform.LspFormatOpts Configure if and when LSP should be used for formatting. Defaults to "never".
|
||||
---@field stop_after_first? boolean Only run the first available formatter in the list. Defaults to false.
|
||||
---@field quiet? boolean Don't show any notifications for warnings or failures. Defaults to false.
|
||||
---@field range? 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
|
||||
---@field id? integer Passed to |vim.lsp.buf.format| when using LSP formatting
|
||||
---@field name? string Passed to |vim.lsp.buf.format| when using LSP formatting
|
||||
---@field filter? fun(client: table): boolean Passed to |vim.lsp.buf.format| when using LSP formatting
|
||||
|
||||
---@class (exact) conform.DefaultFormatOpts
|
||||
---@field timeout_ms? integer Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true.
|
||||
---@field lsp_format? conform.LspFormatOpts Configure if and when LSP should be used for formatting. Defaults to "never".
|
||||
---@field quiet? boolean Don't show any notifications for warnings or failures. Defaults to false.
|
||||
---@field stop_after_first? boolean Only run the first available formatter in the list. Defaults to false.
|
||||
|
||||
---@class conform.FormatLinesOpts
|
||||
---@field timeout_ms? integer Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true.
|
||||
---@field bufnr? integer use this as the working buffer (default 0)
|
||||
---@field async? 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.
|
||||
---@field quiet? boolean Don't show any notifications for warnings or failures. Defaults to false.
|
||||
---@field stop_after_first? boolean Only run the first available formatter in the list. Defaults to false.
|
||||
|
||||
---@class (exact) conform.setupOpts
|
||||
---@field formatters_by_ft? table<string, conform.FiletypeFormatter> Map of filetype to formatters
|
||||
---@field format_on_save? 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.
|
||||
---@field default_format_opts? conform.DefaultFormatOpts The default options to use when calling conform.format()
|
||||
---@field format_after_save? 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.
|
||||
---@field log_level? integer Set the log level (e.g. `vim.log.levels.DEBUG`). Use `:ConformInfo` to see the location of the log file.
|
||||
---@field notify_on_error? boolean Conform will notify you when a formatter errors (default true).
|
||||
---@field notify_no_formatters? boolean Conform will notify you when no formatters are available for the buffer (default true).
|
||||
---@field formatters? table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride> Custom formatters and overrides for built-in formatters.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
#!/nix/store/4bj2kxdm1462fzcc2i2s4dn33g2angcc-bash-5.2p32/bin/bash
|
||||
set -e
|
||||
|
||||
mkdir -p ".testenv/config/nvim"
|
||||
|
||||
@ -4,8 +4,8 @@ require("conform").setup({
|
||||
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
|
||||
@ -20,6 +20,11 @@ require("conform").setup({
|
||||
-- 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.
|
||||
@ -38,6 +43,8 @@ require("conform").setup({
|
||||
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 = {
|
||||
@ -74,7 +81,6 @@ require("conform").setup({
|
||||
-- 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.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
#!/nix/store/4bj2kxdm1462fzcc2i2s4dn33g2angcc-bash-5.2p32/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ describe("fuzzer", function()
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, buf_content)
|
||||
vim.bo[bufnr].modified = false
|
||||
runner.apply_format(0, buf_content, expected, nil, false)
|
||||
runner.apply_format(0, buf_content, expected, nil, false, false, false)
|
||||
assert.are.same(expected, vim.api.nvim_buf_get_lines(0, 0, -1, false))
|
||||
end
|
||||
|
||||
|
||||
@ -4,11 +4,6 @@ local injected = require("conform.formatters.injected")
|
||||
local runner = require("conform.runner")
|
||||
local test_util = require("tests.test_util")
|
||||
|
||||
-- injected formatter only supported on neovim 0.9+
|
||||
if vim.fn.has("nvim-0.9") == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
---@param dir string
|
||||
---@return string[]
|
||||
local function list_test_files(dir)
|
||||
|
||||
@ -59,11 +59,36 @@ describe("runner", function()
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
local filename = vim.api.nvim_buf_get_name(bufnr)
|
||||
assert.are.same({
|
||||
buf = bufnr,
|
||||
filename = filename,
|
||||
dirname = vim.fs.dirname(filename),
|
||||
}, ctx)
|
||||
assert.equal(bufnr, ctx.buf)
|
||||
assert.equal(filename, ctx.filename)
|
||||
assert.equal(vim.fs.dirname(filename), ctx.dirname)
|
||||
end)
|
||||
|
||||
it("sets the shiftwidth to shiftwidth", function()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
vim.bo[bufnr].shiftwidth = 7
|
||||
conform.formatters.test = {
|
||||
meta = { url = "", description = "" },
|
||||
command = "echo",
|
||||
}
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
assert.equal(7, ctx.shiftwidth)
|
||||
end)
|
||||
|
||||
it("sets the shiftwidth to tabstop as fallback", function()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
vim.bo[bufnr].shiftwidth = 0
|
||||
vim.bo[bufnr].tabstop = 3
|
||||
conform.formatters.test = {
|
||||
meta = { url = "", description = "" },
|
||||
command = "echo",
|
||||
}
|
||||
local config = assert(conform.get_formatter_config("test"))
|
||||
local ctx = runner.build_context(0, config)
|
||||
assert.equal(3, ctx.shiftwidth)
|
||||
end)
|
||||
|
||||
it("sets temp file when stdin = false", function()
|
||||
|
||||
Reference in New Issue
Block a user