Refresh generated neovim config
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
set -e
|
||||
make fastlint
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
set -e
|
||||
IFS=' '
|
||||
while read local_ref _local_sha _remote_ref _remote_sha; do
|
||||
|
||||
@ -30,7 +30,7 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: stevearc/nvim-typecheck-action@v1
|
||||
- uses: stevearc/nvim-typecheck-action@v2
|
||||
with:
|
||||
path: lua
|
||||
|
||||
|
||||
@ -1,5 +1,39 @@
|
||||
# Changelog
|
||||
|
||||
## [5.9.0](https://github.com/stevearc/conform.nvim/compare/v5.8.0...v5.9.0) (2024-06-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add support for d2 ([#445](https://github.com/stevearc/conform.nvim/issues/445)) ([5e7a000](https://github.com/stevearc/conform.nvim/commit/5e7a000e4f239b56077e5a38680c5e9a0bf60e6a))
|
||||
* add support for efmt ([#428](https://github.com/stevearc/conform.nvim/issues/428)) ([a1d3c0a](https://github.com/stevearc/conform.nvim/commit/a1d3c0aff306b974bc07b4cdf52f1766dd89fc90))
|
||||
* add support for for vsg ([#451](https://github.com/stevearc/conform.nvim/issues/451)) ([cf562dd](https://github.com/stevearc/conform.nvim/commit/cf562dd160c27a7fc5342dfce7e1227746dd3aaa))
|
||||
* add support for fprettify ([#429](https://github.com/stevearc/conform.nvim/issues/429)) ([7999faf](https://github.com/stevearc/conform.nvim/commit/7999faf7bbec7461f62dabd57cccb784c8d804b5))
|
||||
* add support for hindent ([#430](https://github.com/stevearc/conform.nvim/issues/430)) ([9f46982](https://github.com/stevearc/conform.nvim/commit/9f46982b8dc2bf1e267d386ccd096f896369e323))
|
||||
* add support for kcl fmt ([#431](https://github.com/stevearc/conform.nvim/issues/431)) ([03a07d5](https://github.com/stevearc/conform.nvim/commit/03a07d58be09a681ab162f3a069dc9e86589bacb))
|
||||
* add support for npm-groovy-lint ([#433](https://github.com/stevearc/conform.nvim/issues/433)) ([8fd894c](https://github.com/stevearc/conform.nvim/commit/8fd894cdc248cad64dbfeac6b89e03db9f737a35))
|
||||
* add treesitter query formatter ([#425](https://github.com/stevearc/conform.nvim/issues/425)) ([63e0a32](https://github.com/stevearc/conform.nvim/commit/63e0a32c85a39484813957dc480f171907aa90b9))
|
||||
* **erlang:** support erlfmt ([#436](https://github.com/stevearc/conform.nvim/issues/436)) ([948c83b](https://github.com/stevearc/conform.nvim/commit/948c83b00eb81bf16b54c6a092ddd88be46793cd))
|
||||
* formatter override can use ([#453](https://github.com/stevearc/conform.nvim/issues/453)) ([a28a425](https://github.com/stevearc/conform.nvim/commit/a28a4255e5c5631ee9c58537592fca05447f0503))
|
||||
* **fortran:** support findent ([#426](https://github.com/stevearc/conform.nvim/issues/426)) ([969cdf5](https://github.com/stevearc/conform.nvim/commit/969cdf50b011bec08b4fb8bd3ea3031df183501b))
|
||||
* **haskell:** support stylish-haskell ([#435](https://github.com/stevearc/conform.nvim/issues/435)) ([dc612fb](https://github.com/stevearc/conform.nvim/commit/dc612fbf6194fcb3ef401871db1cae74134e9423))
|
||||
* **latex:** support llf ([#446](https://github.com/stevearc/conform.nvim/issues/446)) ([1743ee6](https://github.com/stevearc/conform.nvim/commit/1743ee6f9fc52825bdee9493e246876bed591bc1))
|
||||
* **lua:** support lua-format ([#432](https://github.com/stevearc/conform.nvim/issues/432)) ([b421e95](https://github.com/stevearc/conform.nvim/commit/b421e95a31e6c3b064a964292255e3b9c762fddd))
|
||||
* **python:** support pyink ([#427](https://github.com/stevearc/conform.nvim/issues/427)) ([8b147ca](https://github.com/stevearc/conform.nvim/commit/8b147ca7abccbb19dd952dbb7aeebcdd56b02aee))
|
||||
* **rst:** support rstfmt ([#434](https://github.com/stevearc/conform.nvim/issues/434)) ([294bd1d](https://github.com/stevearc/conform.nvim/commit/294bd1d4d32d4c4b797bfc997ea0e4c1a7019ce5))
|
||||
* support docstrfmt ([#441](https://github.com/stevearc/conform.nvim/issues/441)) ([c841697](https://github.com/stevearc/conform.nvim/commit/c84169717ee74698f9df20c6437fa06df03bf1fe))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* always add cwd to debug logs ([44879ff](https://github.com/stevearc/conform.nvim/commit/44879ffd0268ba931532537b1ee44ed77cd90a5d))
|
||||
* **dprint:** add support for binary in node_modules ([#422](https://github.com/stevearc/conform.nvim/issues/422)) ([b1285c7](https://github.com/stevearc/conform.nvim/commit/b1285c7c24559688a9e02d3828d9b72f553b3549))
|
||||
* **format-queries:** update query formatter for breaking changes in nvim-treesitter ([7159a23](https://github.com/stevearc/conform.nvim/commit/7159a23d19fb982269dae2e8147ebbe34965095b))
|
||||
* improve error message when formatter config is missing ([3f61023](https://github.com/stevearc/conform.nvim/commit/3f610236caf3db6576a0dd7760e5b0731659db68))
|
||||
* **rustfmt:** add a default cwd when config file is detected ([#419](https://github.com/stevearc/conform.nvim/issues/419)) ([355049b](https://github.com/stevearc/conform.nvim/commit/355049bc318c3c968b2b434cea9a5bcdf6bf8ea7))
|
||||
* set correct file extension for unsaved buffer temp files ([#440](https://github.com/stevearc/conform.nvim/issues/440)) ([88b699b](https://github.com/stevearc/conform.nvim/commit/88b699b595703f1ae9d9061c050e52b1fe7c33f1))
|
||||
* use vim.fs.root in neovim 0.10 ([584adfe](https://github.com/stevearc/conform.nvim/commit/584adfe7c665827601f4245c0c40273e8bc9e7cb))
|
||||
|
||||
## [5.8.0](https://github.com/stevearc/conform.nvim/compare/v5.7.0...v5.8.0) (2024-05-22)
|
||||
|
||||
|
||||
|
||||
@ -153,7 +153,7 @@ require("conform").setup({
|
||||
format_on_save = {
|
||||
-- These options will be passed to conform.format()
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
})
|
||||
```
|
||||
@ -207,22 +207,29 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [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.
|
||||
- [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.
|
||||
- [docstrfmt](https://github.com/LilSpazJoekp/docstrfmt) - reStructuredText formatter.
|
||||
- [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.
|
||||
- [elm_format](https://github.com/avh4/elm-format) - elm-format formats Elm source code according to a standard set of rules based on the official [Elm Style Guide](https://elm-lang.org/docs/style-guide).
|
||||
- [erb_format](https://github.com/nebulab/erb-formatter) - Format ERB files with speed and precision.
|
||||
- [erlfmt](https://github.com/WhatsApp/erlfmt) - An automated code formatter for Erlang.
|
||||
- [eslint_d](https://github.com/mantoni/eslint_d.js/) - Like ESLint, but faster.
|
||||
- [fantomas](https://github.com/fsprojects/fantomas) - F# source code formatter.
|
||||
- [findent](https://github.com/wvermin/findent) - Indent, relabel and convert Fortran sources.
|
||||
- [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html) - Indent or otherwise prettify a piece of fish code.
|
||||
- [fixjson](https://github.com/rhysd/fixjson) - JSON Fixer for Humans using (relaxed) JSON5.
|
||||
- [fnlfmt](https://git.sr.ht/~technomancy/fnlfmt) - A formatter for Fennel code.
|
||||
- [forge_fmt](https://github.com/foundry-rs/foundry) - Forge is a command-line tool that ships with Foundry. Forge tests, builds, and deploys your smart contracts.
|
||||
- [format-queries](https://github.com/nvim-treesitter/nvim-treesitter/blob/main/CONTRIBUTING.md#formatting) - Tree-sitter query formatter.
|
||||
- [fourmolu](https://hackage.haskell.org/package/fourmolu) - A fork of ormolu that uses four space indentation and allows arbitrary configuration.
|
||||
- [fprettify](https://github.com/fortran-lang/fprettify) - Auto-formatter for modern fortran source code.
|
||||
- [gci](https://github.com/daixiang0/gci) - GCI, a tool that controls Go package import order and makes it always deterministic.
|
||||
- [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.
|
||||
@ -235,6 +242,7 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [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.
|
||||
- [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.
|
||||
- [indent](https://www.gnu.org/software/indent/) - GNU Indent.
|
||||
- [injected](doc/advanced_topics.md#injected-language-formatting-code-blocks) - Format treesitter injected languages.
|
||||
@ -244,11 +252,14 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [jq](https://github.com/stedolan/jq) - Command-line JSON processor.
|
||||
- [jsonnetfmt](https://github.com/google/go-jsonnet/tree/master/cmd/jsonnetfmt) - jsonnetfmt is a command line tool to format jsonnet files.
|
||||
- [just](https://github.com/casey/just) - Format Justfile.
|
||||
- [kcl](https://www.kcl-lang.io/docs/tools/cli/kcl/fmt) - The KCL Format tool modifies the files according to the KCL code style.
|
||||
- [ktfmt](https://github.com/facebook/ktfmt) - Reformats Kotlin source code to comply with the common community standard conventions.
|
||||
- [ktlint](https://ktlint.github.io/) - An anti-bikeshedding Kotlin linter with built-in formatter.
|
||||
- [latexindent](https://github.com/cmhughes/latexindent.pl) - A perl script for formatting LaTeX files that is generally included in major TeX distributions.
|
||||
- [leptosfmt](https://github.com/bram209/leptosfmt) - A formatter for the Leptos view! macro.
|
||||
- [liquidsoap-prettier](https://github.com/savonet/liquidsoap-prettier) - A binary to format Liquidsoap scripts
|
||||
- [llf](https://repo.or.cz/llf.git) - A LaTeX reformatter / beautifier.
|
||||
- [lua-format](https://github.com/Koihik/LuaFormatter) - Code formatter for Lua.
|
||||
- [markdown-toc](https://github.com/jonschlinkert/markdown-toc) - API and CLI for generating a markdown TOC (table of contents) for a README or any markdown files.
|
||||
- [markdownlint](https://github.com/DavidAnson/markdownlint) - A Node.js style checker and lint tool for Markdown/CommonMark files.
|
||||
- [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) - A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the markdownlint library.
|
||||
@ -259,6 +270,7 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [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.
|
||||
- [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) - Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files using command line.
|
||||
- [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) - Auto-formatter for OCaml code.
|
||||
- [ocp-indent](https://github.com/OCamlPro/ocp-indent) - Automatic indentation of OCaml source files.
|
||||
- [opa_fmt](https://www.openpolicyagent.org/docs/latest/cli/#opa-fmt) - Format Rego files using `opa fmt` command.
|
||||
@ -277,9 +289,11 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [pretty-php](https://github.com/lkrms/pretty-php) - The opinionated PHP code formatter.
|
||||
- [puppet-lint](https://github.com/puppetlabs/puppet-lint) - Check that your Puppet manifests conform to the style guide.
|
||||
- [purs-tidy](https://github.com/natefaubion/purescript-tidy) - A syntax tidy-upper for PureScript.
|
||||
- [pyink](https://github.com/google/pyink) - A Python formatter, forked from Black with a few different formatting behaviors.
|
||||
- [reorder-python-imports](https://github.com/asottile/reorder-python-imports) - Rewrites source to reorder python imports
|
||||
- [rescript-format](https://rescript-lang.org/) - The built-in ReScript formatter.
|
||||
- [roc](https://github.com/roc-lang/roc) - A fast, friendly, functional language.
|
||||
- [rstfmt](https://github.com/dzhu/rstfmt) - A formatter for reStructuredText.
|
||||
- [rubocop](https://github.com/rubocop/rubocop) - Ruby static code analyzer and formatter, based on the community Ruby style guide.
|
||||
- [rubyfmt](https://github.com/fables-tales/rubyfmt) - Ruby Autoformatter! (Written in Rust)
|
||||
- [ruff_fix](https://docs.astral.sh/ruff/) - An extremely fast Python linter, written in Rust. Fix lint errors.
|
||||
@ -302,6 +316,7 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [standardrb](https://github.com/standardrb/standard) - Ruby's bikeshed-proof linter and formatter.
|
||||
- [stylelint](https://github.com/stylelint/stylelint) - A mighty CSS linter that helps you avoid errors and enforce conventions.
|
||||
- [styler](https://github.com/devOpifex/r.nvim) - R formatter and linter.
|
||||
- [stylish-haskell](https://github.com/haskell/stylish-haskell) - Haskell code prettifier.
|
||||
- [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.
|
||||
@ -315,11 +330,11 @@ You can view this list in vim with `:help conform-formatters`
|
||||
- [trim_whitespace](https://www.gnu.org/software/gawk/manual/gawk.html) - Trim whitespaces with awk.
|
||||
- [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
|
||||
- [typstfmt](https://github.com/astrale-sharp/typstfmt) - Basic formatter for the Typst language with a future!
|
||||
- [typstyle](https://github.com/Enter-tainer/typstyle) - Beautiful and reliable typst code formatter.
|
||||
- [uncrustify](https://github.com/uncrustify/uncrustify) - A source code beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and Vala.
|
||||
- [usort](https://github.com/facebook/usort) - Safe, minimal import sorting for Python projects.
|
||||
- [verible](https://github.com/chipsalliance/verible/blob/master/verilog/tools/formatter/README.md) - The SystemVerilog formatter.
|
||||
- [vsg](https://github.com/jeremiah-c-leary/vhdl-style-guide) - Style guide enforcement for VHDL.
|
||||
- [xmlformat](https://github.com/pamoller/xmlformatter) - xmlformatter is an Open Source Python package, which provides formatting of XML documents.
|
||||
- [xmllint](http://xmlsoft.org/xmllint.html) - Despite the name, xmllint can be used to format XML files as well as lint them.
|
||||
- [yamlfix](https://github.com/lyz-code/yamlfix) - A configurable YAML formatter that keeps comments.
|
||||
@ -451,14 +466,14 @@ require("conform").setup({
|
||||
-- This can also be a function that returns the table.
|
||||
format_on_save = {
|
||||
-- I recommend these options. See :help conform.format for details.
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
timeout_ms = 500,
|
||||
},
|
||||
-- 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.
|
||||
format_after_save = {
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
-- Set the log level. Use `:ConformInfo` to see the location of the log file.
|
||||
log_level = vim.log.levels.ERROR,
|
||||
@ -499,9 +514,13 @@ 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.
|
||||
-- This can also be a function, like args
|
||||
append_args = { "--trailing-comma" },
|
||||
},
|
||||
-- These can also be a function that returns the formatter
|
||||
other_formatter = function(bufnr)
|
||||
@ -544,8 +563,8 @@ 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): 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): 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. |
|
||||
| | 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` | 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). |
|
||||
| | formatters | `nil\|table<string, conform.FormatterConfigOverride\|fun(bufnr: integer): nil\|conform.FormatterConfigOverride>` | Custom formatters and overrides for built-in formatters. |
|
||||
@ -555,21 +574,21 @@ 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_fallback | `nil\|boolean\|"always"` | Attempt LSP formatting if no formatters are available. Defaults to false. If "always", will attempt LSP formatting even if formatters are available. |
|
||||
| | 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 lsp_fallback = true |
|
||||
| | name | `nil\|string` | Passed to vim.lsp.buf.format when lsp_fallback = true |
|
||||
| | filter | `nil\|fun(client: table): boolean` | Passed to vim.lsp.buf.format when lsp_fallback = true |
|
||||
| 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 |
|
||||
| | 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 | |
|
||||
|
||||
Returns:
|
||||
|
||||
@ -605,7 +624,7 @@ Get information about a formatter (including availability)
|
||||
### will_fallback_lsp(options)
|
||||
|
||||
`will_fallback_lsp(options): boolean` \
|
||||
Check if the buffer will use LSP formatting when lsp_fallback = true
|
||||
Check if the buffer will use LSP formatting when lsp_format = "fallback"
|
||||
|
||||
| Param | Type | Desc |
|
||||
| ------- | ------------ | ------------------------------------ |
|
||||
|
||||
@ -38,14 +38,14 @@ OPTIONS *conform-option
|
||||
-- This can also be a function that returns the table.
|
||||
format_on_save = {
|
||||
-- I recommend these options. See :help conform.format for details.
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
timeout_ms = 500,
|
||||
},
|
||||
-- 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.
|
||||
format_after_save = {
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
-- Set the log level. Use `:ConformInfo` to see the location of the log file.
|
||||
log_level = vim.log.levels.ERROR,
|
||||
@ -86,9 +86,13 @@ 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.
|
||||
-- This can also be a function, like args
|
||||
append_args = { "--trailing-comma" },
|
||||
},
|
||||
-- These can also be a function that returns the formatter
|
||||
other_formatter = function(bufnr)
|
||||
@ -115,11 +119,11 @@ 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): conform.FormatOpts` I
|
||||
{format_on_save} `nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts` I
|
||||
f 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): conform.FormatOpts` I
|
||||
{format_after_save} `nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts` I
|
||||
f 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
|
||||
@ -138,32 +142,32 @@ 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_fallback} `nil|boolean|"always"` Attempt LSP formatting if no
|
||||
formatters are available. Defaults to false. If
|
||||
"always", will attempt LSP formatting even if
|
||||
formatters are available.
|
||||
{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
|
||||
lsp_fallback = true
|
||||
{name} `nil|string` Passed to |vim.lsp.buf.format| when
|
||||
lsp_fallback = true
|
||||
{filter} `nil|fun(client: table): boolean` Passed to
|
||||
|vim.lsp.buf.format| when lsp_fallback = true
|
||||
{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
|
||||
{callback} `nil|fun(err: nil|string, did_edit: nil|boolean)` Called once
|
||||
formatting has completed
|
||||
Returns:
|
||||
@ -187,7 +191,7 @@ get_formatter_info({formatter}, {bufnr}): conform.FormatterInfo *conform.get_for
|
||||
{bufnr} `nil|integer`
|
||||
|
||||
will_fallback_lsp({options}): boolean *conform.will_fallback_lsp*
|
||||
Check if the buffer will use LSP formatting when lsp_fallback = true
|
||||
Check if the buffer will use LSP formatting when lsp_format = "fallback"
|
||||
|
||||
Parameters:
|
||||
{options} `nil|table` Options passed to |vim.lsp.buf.format|
|
||||
@ -238,6 +242,7 @@ FORMATTERS *conform-formatter
|
||||
`crystal` - Format Crystal code.
|
||||
`csharpier` - The opinionated C# code formatter.
|
||||
`cue_fmt` - Format CUE files using `cue fmt` command.
|
||||
`d2` - D2 is a modern diagram scripting language that turns text to diagrams.
|
||||
`darker` - Run black only on changed lines.
|
||||
`dart_format` - Replace the whitespace in your program with formatting that
|
||||
follows Dart guidelines.
|
||||
@ -246,22 +251,28 @@ FORMATTERS *conform-formatter
|
||||
`dfmt` - Formatter for D source code.
|
||||
`djlint` - ✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks -
|
||||
Handlebars - GoLang.
|
||||
`docstrfmt` - reStructuredText formatter.
|
||||
`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.
|
||||
`efmt` - Erlang code formatter.
|
||||
`elm_format` - elm-format formats Elm source code according to a standard set of
|
||||
rules based on the official [Elm Style Guide](https://elm-
|
||||
lang.org/docs/style-guide).
|
||||
`erb_format` - Format ERB files with speed and precision.
|
||||
`erlfmt` - An automated code formatter for Erlang.
|
||||
`eslint_d` - Like ESLint, but faster.
|
||||
`fantomas` - F# source code formatter.
|
||||
`findent` - Indent, relabel and convert Fortran sources.
|
||||
`fish_indent` - Indent or otherwise prettify a piece of fish code.
|
||||
`fixjson` - JSON Fixer for Humans using (relaxed) JSON5.
|
||||
`fnlfmt` - A formatter for Fennel code.
|
||||
`forge_fmt` - Forge is a command-line tool that ships with Foundry. Forge tests,
|
||||
builds, and deploys your smart contracts.
|
||||
`format-queries` - Tree-sitter query formatter.
|
||||
`fourmolu` - A fork of ormolu that uses four space indentation and allows
|
||||
arbitrary configuration.
|
||||
`fprettify` - Auto-formatter for modern fortran source code.
|
||||
`gci` - GCI, a tool that controls Go package import order and makes it always
|
||||
deterministic.
|
||||
`gdformat` - A formatter for Godot's gdscript.
|
||||
@ -280,6 +291,7 @@ FORMATTERS *conform-formatter
|
||||
`google-java-format` - Reformats Java source code according to Google Java
|
||||
Style.
|
||||
`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.
|
||||
`indent` - GNU Indent.
|
||||
@ -291,6 +303,7 @@ FORMATTERS *conform-formatter
|
||||
`jq` - Command-line JSON processor.
|
||||
`jsonnetfmt` - jsonnetfmt is a command line tool to format jsonnet files.
|
||||
`just` - Format Justfile.
|
||||
`kcl` - The KCL Format tool modifies the files according to the KCL code style.
|
||||
`ktfmt` - Reformats Kotlin source code to comply with the common community
|
||||
standard conventions.
|
||||
`ktlint` - An anti-bikeshedding Kotlin linter with built-in formatter.
|
||||
@ -298,6 +311,8 @@ FORMATTERS *conform-formatter
|
||||
included in major TeX distributions.
|
||||
`leptosfmt` - A formatter for the Leptos view! macro.
|
||||
`liquidsoap-prettier` - A binary to format Liquidsoap scripts
|
||||
`llf` - A LaTeX reformatter / beautifier.
|
||||
`lua-format` - Code formatter for Lua.
|
||||
`markdown-toc` - API and CLI for generating a markdown TOC (table of contents)
|
||||
for a README or any markdown files.
|
||||
`markdownlint` - A Node.js style checker and lint tool for Markdown/CommonMark
|
||||
@ -315,6 +330,8 @@ FORMATTERS *conform-formatter
|
||||
`nixfmt` - nixfmt is a formatter for Nix code, intended to apply a uniform
|
||||
style.
|
||||
`nixpkgs_fmt` - nixpkgs-fmt is a Nix code formatter for nixpkgs.
|
||||
`npm-groovy-lint` - Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle
|
||||
files using command line.
|
||||
`ocamlformat` - Auto-formatter for OCaml code.
|
||||
`ocp-indent` - Automatic indentation of OCaml source files.
|
||||
`opa_fmt` - Format Rego files using `opa fmt` command.
|
||||
@ -339,9 +356,12 @@ FORMATTERS *conform-formatter
|
||||
`pretty-php` - The opinionated PHP code formatter.
|
||||
`puppet-lint` - Check that your Puppet manifests conform to the style guide.
|
||||
`purs-tidy` - A syntax tidy-upper for PureScript.
|
||||
`pyink` - A Python formatter, forked from Black with a few different formatting
|
||||
behaviors.
|
||||
`reorder-python-imports` - Rewrites source to reorder python imports
|
||||
`rescript-format` - The built-in ReScript formatter.
|
||||
`roc` - A fast, friendly, functional language.
|
||||
`rstfmt` - A formatter for reStructuredText.
|
||||
`rubocop` - Ruby static code analyzer and formatter, based on the community Ruby
|
||||
style guide.
|
||||
`rubyfmt` - Ruby Autoformatter! (Written in Rust)
|
||||
@ -372,6 +392,7 @@ FORMATTERS *conform-formatter
|
||||
`stylelint` - A mighty CSS linter that helps you avoid errors and enforce
|
||||
conventions.
|
||||
`styler` - R formatter and linter.
|
||||
`stylish-haskell` - Haskell code prettifier.
|
||||
`stylua` - An opinionated code formatter for Lua.
|
||||
`swift_format` - Swift formatter from apple. Requires building from source with
|
||||
`swift build`.
|
||||
@ -390,12 +411,12 @@ FORMATTERS *conform-formatter
|
||||
`trim_whitespace` - Trim whitespaces with awk.
|
||||
`twig-cs-fixer` - Automatically fix Twig Coding Standards issues
|
||||
`typos` - Source code spell checker
|
||||
`typstfmt` - Basic formatter for the Typst language with a future!
|
||||
`typstyle` - Beautiful and reliable typst code formatter.
|
||||
`uncrustify` - A source code beautifier for C, C++, C#, ObjectiveC, D, Java,
|
||||
Pawn and Vala.
|
||||
`usort` - Safe, minimal import sorting for Python projects.
|
||||
`verible` - The SystemVerilog formatter.
|
||||
`vsg` - Style guide enforcement for VHDL.
|
||||
`xmlformat` - xmlformatter is an Open Source Python package, which provides
|
||||
formatting of XML documents.
|
||||
`xmllint` - Despite the name, xmllint can be used to format XML files as well as
|
||||
|
||||
@ -24,7 +24,7 @@ vim.api.nvim_create_user_command("Format", function(args)
|
||||
["end"] = { args.line2, end_line:len() },
|
||||
}
|
||||
end
|
||||
require("conform").format({ async = true, lsp_fallback = true, range = range })
|
||||
require("conform").format({ async = true, lsp_format = "fallback", range = range })
|
||||
end, { range = true })
|
||||
```
|
||||
|
||||
@ -53,7 +53,7 @@ require("conform").setup({
|
||||
return
|
||||
end
|
||||
-- ...additional logic...
|
||||
return { timeout_ms = 500, lsp_fallback = true }
|
||||
return { timeout_ms = 500, lsp_format = "fallback" }
|
||||
end,
|
||||
})
|
||||
|
||||
@ -65,7 +65,7 @@ require("conform").setup({
|
||||
return
|
||||
end
|
||||
-- ...additional logic...
|
||||
return { lsp_fallback = true }
|
||||
return { lsp_format = "fallback" }
|
||||
end,
|
||||
})
|
||||
```
|
||||
@ -83,7 +83,7 @@ require("conform").setup({
|
||||
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||
return
|
||||
end
|
||||
return { timeout_ms = 500, lsp_fallback = true }
|
||||
return { timeout_ms = 500, lsp_format = "fallback" }
|
||||
end,
|
||||
})
|
||||
|
||||
@ -123,14 +123,14 @@ require("conform").setup({
|
||||
end
|
||||
end
|
||||
|
||||
return { timeout_ms = 200, lsp_fallback = true }, on_format
|
||||
return { timeout_ms = 200, lsp_format = "fallback" }, on_format
|
||||
end,
|
||||
|
||||
format_after_save = function(bufnr)
|
||||
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
|
||||
return
|
||||
end
|
||||
return { lsp_fallback = true }
|
||||
return { lsp_format = "fallback" }
|
||||
end,
|
||||
})
|
||||
```
|
||||
@ -149,7 +149,7 @@ return {
|
||||
-- Customize or remove this keymap to your liking
|
||||
"<leader>f",
|
||||
function()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
require("conform").format({ async = true, lsp_format = "fallback" })
|
||||
end,
|
||||
mode = "",
|
||||
desc = "Format buffer",
|
||||
@ -164,7 +164,7 @@ return {
|
||||
javascript = { { "prettierd", "prettier" } },
|
||||
},
|
||||
-- Set up format-on-save
|
||||
format_on_save = { timeout_ms = 500, lsp_fallback = true },
|
||||
format_on_save = { timeout_ms = 500, lsp_format = "fallback" },
|
||||
-- Customize formatters
|
||||
formatters = {
|
||||
shfmt = {
|
||||
|
||||
@ -5,7 +5,7 @@ return {
|
||||
url = "https://github.com/dprint/dprint",
|
||||
description = "Pluggable and configurable code formatting platform written in Rust.",
|
||||
},
|
||||
command = "dprint",
|
||||
command = util.from_node_modules("dprint"),
|
||||
args = { "fmt", "--stdin", "$FILENAME" },
|
||||
cwd = util.root_file({
|
||||
"dprint.json",
|
||||
|
||||
@ -18,4 +18,8 @@ return {
|
||||
|
||||
return args
|
||||
end,
|
||||
cwd = util.root_file({
|
||||
"rustfmt.toml",
|
||||
".rustfmt.toml",
|
||||
}),
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ return {
|
||||
meta = {
|
||||
url = "https://github.com/astrale-sharp/typstfmt",
|
||||
description = "Basic formatter for the Typst language with a future!",
|
||||
deprecated = true,
|
||||
},
|
||||
command = "typstfmt",
|
||||
stdin = true,
|
||||
|
||||
@ -18,4 +18,8 @@ return {
|
||||
|
||||
return args
|
||||
end,
|
||||
cwd = util.root_file({
|
||||
"rustfmt.toml",
|
||||
".rustfmt.toml",
|
||||
}),
|
||||
}
|
||||
|
||||
@ -166,6 +166,12 @@ M.setup = function(opts)
|
||||
end, { desc = "Show information about Conform formatters" })
|
||||
end
|
||||
|
||||
---@param obj any
|
||||
---@return boolean
|
||||
local function is_empty_table(obj)
|
||||
return type(obj) == "table" and vim.tbl_isempty(obj)
|
||||
end
|
||||
|
||||
---Get the configured formatter filetype for a buffer
|
||||
---@param bufnr? integer
|
||||
---@return nil|string filetype or nil if no formatter is configured
|
||||
@ -177,7 +183,9 @@ local function get_matching_filetype(bufnr)
|
||||
table.insert(filetypes, "_")
|
||||
for _, filetype in ipairs(filetypes) do
|
||||
local ft_formatters = M.formatters_by_ft[filetype]
|
||||
if ft_formatters then
|
||||
-- Sometimes people put an empty table here, and that should not count as configuring formatters
|
||||
-- for a filetype.
|
||||
if ft_formatters and not is_empty_table(ft_formatters) then
|
||||
return filetype
|
||||
end
|
||||
end
|
||||
@ -305,33 +313,58 @@ M.resolve_formatters = function(names, bufnr, warn_on_missing)
|
||||
return all_info
|
||||
end
|
||||
|
||||
---Check if there are any formatters configured specifically for the buffer's filetype
|
||||
---@param bufnr integer
|
||||
---@return boolean
|
||||
local function has_filetype_formatters(bufnr)
|
||||
local matching_filetype = get_matching_filetype(bufnr)
|
||||
return matching_filetype ~= nil and matching_filetype ~= "_"
|
||||
end
|
||||
|
||||
---@param opts table
|
||||
---@return boolean
|
||||
local function has_lsp_formatter(opts)
|
||||
local lsp_format = require("conform.lsp_format")
|
||||
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_fallback nil|boolean|"always" Attempt LSP formatting if no formatters are available. Defaults to false. If "always", will attempt LSP formatting even if formatters are available.
|
||||
---@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 lsp_fallback = true
|
||||
---@field name nil|string Passed to |vim.lsp.buf.format| when lsp_fallback = true
|
||||
---@field filter nil|fun(client: table): boolean Passed to |vim.lsp.buf.format| when lsp_fallback = true
|
||||
---@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
|
||||
|
||||
---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_fallback: boolean|"always", quiet: boolean, formatters?: string[], range?: conform.Range}
|
||||
---@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 {}, {
|
||||
timeout_ms = 1000,
|
||||
bufnr = 0,
|
||||
async = false,
|
||||
dry_run = false,
|
||||
lsp_fallback = false,
|
||||
lsp_format = "never",
|
||||
quiet = false,
|
||||
})
|
||||
|
||||
-- For backwards compatibility
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
if opts.lsp_fallback == true then
|
||||
opts.lsp_format = "fallback"
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
elseif opts.lsp_fallback == "always" then
|
||||
opts.lsp_format = "last"
|
||||
end
|
||||
|
||||
if opts.bufnr == 0 then
|
||||
opts.bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
@ -349,71 +382,86 @@ M.format = function(opts, callback)
|
||||
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 has_lsp = has_lsp_formatter(opts)
|
||||
|
||||
local any_formatters = not vim.tbl_isempty(formatters)
|
||||
if not explicit_formatters and opts.lsp_fallback == true and M.will_fallback_lsp(opts) then
|
||||
-- use the LSP formatter when the configured formatters are from the fallback "_" filetype
|
||||
any_formatters = false
|
||||
else
|
||||
---@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)
|
||||
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
|
||||
if errors.is_execution_error(err.code) then
|
||||
should_notify = should_notify and M.notify_on_error and not err.debounce_message
|
||||
notify_msg = "Formatter failed. See :ConformInfo for details"
|
||||
end
|
||||
if should_notify then
|
||||
vim.notify(notify_msg, level)
|
||||
end
|
||||
end
|
||||
local err_message = err and err.message
|
||||
if not err_message and not vim.api.nvim_buf_is_valid(opts.bufnr) then
|
||||
err_message = "buffer was deleted"
|
||||
end
|
||||
if err_message then
|
||||
return callback(err_message)
|
||||
end
|
||||
|
||||
if opts.dry_run and did_edit then
|
||||
callback(nil, true)
|
||||
elseif opts.lsp_format == "last" and has_lsp then
|
||||
log.debug("Running LSP formatter on %s", vim.api.nvim_buf_get_name(opts.bufnr))
|
||||
lsp_format.format(opts, callback)
|
||||
else
|
||||
callback(nil, did_edit)
|
||||
end
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
if any_formatters then
|
||||
---@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)
|
||||
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
|
||||
if errors.is_execution_error(err.code) then
|
||||
should_notify = should_notify and M.notify_on_error and not err.debounce_message
|
||||
notify_msg = "Formatter failed. See :ConformInfo for details"
|
||||
end
|
||||
if should_notify then
|
||||
vim.notify(notify_msg, level)
|
||||
end
|
||||
end
|
||||
local err_message = err and err.message
|
||||
if not err_message and not vim.api.nvim_buf_is_valid(opts.bufnr) then
|
||||
err_message = "buffer was deleted"
|
||||
end
|
||||
if err_message then
|
||||
return callback(err_message)
|
||||
end
|
||||
|
||||
if opts.dry_run and did_edit then
|
||||
callback(nil, true)
|
||||
elseif
|
||||
opts.lsp_fallback == "always" and not vim.tbl_isempty(lsp_format.get_format_clients(opts))
|
||||
then
|
||||
log.debug("Running LSP formatter on %s", vim.api.nvim_buf_get_name(opts.bufnr))
|
||||
lsp_format.format(opts, callback)
|
||||
else
|
||||
callback(nil, did_edit)
|
||||
end
|
||||
end
|
||||
|
||||
local run_opts = { exclusive = true, dry_run = opts.dry_run }
|
||||
if opts.async then
|
||||
runner.format_async(opts.bufnr, formatters, opts.range, run_opts, handle_result)
|
||||
runner.format_async(opts.bufnr, formatters, opts.range, run_opts, cb)
|
||||
else
|
||||
local err, did_edit =
|
||||
runner.format_sync(opts.bufnr, formatters, opts.timeout_ms, opts.range, run_opts)
|
||||
handle_result(err, did_edit)
|
||||
cb(err, did_edit)
|
||||
end
|
||||
return true
|
||||
elseif opts.lsp_fallback and not vim.tbl_isempty(lsp_format.get_format_clients(opts)) then
|
||||
end
|
||||
|
||||
-- check if formatters were configured for this buffer's filetype specifically (i.e. not the "_"
|
||||
-- or "*" formatters) AND that at least one of the configured formatters is available
|
||||
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
|
||||
-- LSP formatting only
|
||||
log.debug("Running LSP formatter on %s", vim.api.nvim_buf_get_name(opts.bufnr))
|
||||
lsp_format.format(opts, callback)
|
||||
return true
|
||||
elseif has_lsp and opts.lsp_format == "first" then
|
||||
-- LSP formatting, then other formatters
|
||||
log.debug("Running LSP formatter on %s", vim.api.nvim_buf_get_name(opts.bufnr))
|
||||
lsp_format.format(opts, function(err, did_edit)
|
||||
if err or (did_edit and opts.dry_run) then
|
||||
return callback(err, did_edit)
|
||||
end
|
||||
run_cli_formatters(function(err2, did_edit2)
|
||||
handle_result(err2, did_edit or did_edit2)
|
||||
end)
|
||||
end)
|
||||
return true
|
||||
elseif not vim.tbl_isempty(formatters) then
|
||||
run_cli_formatters(handle_result)
|
||||
return true
|
||||
else
|
||||
local level = vim.tbl_isempty(formatter_names) and "debug" or "warn"
|
||||
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")
|
||||
return false
|
||||
@ -592,7 +640,7 @@ M.get_formatter_info = function(formatter, bufnr)
|
||||
name = formatter,
|
||||
command = formatter,
|
||||
available = false,
|
||||
available_msg = "No config found",
|
||||
available_msg = "Formatter config missing or incomplete",
|
||||
}
|
||||
end
|
||||
|
||||
@ -647,7 +695,7 @@ M.get_formatter_info = function(formatter, bufnr)
|
||||
}
|
||||
end
|
||||
|
||||
---Check if the buffer will use LSP formatting when lsp_fallback = true
|
||||
---Check if the buffer will use LSP formatting when lsp_format = "fallback"
|
||||
---@param options? table Options passed to |vim.lsp.buf.format|
|
||||
---@return boolean
|
||||
M.will_fallback_lsp = function(options)
|
||||
@ -657,18 +705,15 @@ M.will_fallback_lsp = function(options)
|
||||
if options.bufnr == 0 then
|
||||
options.bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
local matching_filetype = get_matching_filetype(options.bufnr)
|
||||
local has_primary_formatters = matching_filetype and matching_filetype ~= "_"
|
||||
local lsp_clients = require("conform.lsp_format").get_format_clients(options)
|
||||
return not has_primary_formatters and not vim.tbl_isempty(lsp_clients)
|
||||
return not has_filetype_formatters(options.bufnr) and has_lsp_formatter(options)
|
||||
end
|
||||
|
||||
M.formatexpr = function(opts)
|
||||
local lsp_format = require("conform.lsp_format")
|
||||
-- Change the defaults slightly from conform.format
|
||||
opts = vim.tbl_deep_extend("keep", opts or {}, {
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
bufnr = vim.api.nvim_get_current_buf(),
|
||||
})
|
||||
-- Force async = false
|
||||
opts.async = false
|
||||
@ -697,15 +742,8 @@ M.formatexpr = function(opts)
|
||||
}
|
||||
end
|
||||
|
||||
if M.format(opts) then
|
||||
return 0
|
||||
elseif opts.lsp_fallback and not vim.tbl_isempty(lsp_format.get_format_clients(opts)) then
|
||||
-- No formatters were available; fall back to lsp formatter
|
||||
return vim.lsp.formatexpr({ timeout_ms = opts.timeout_ms })
|
||||
else
|
||||
-- Do not fallback to built-in formatter.
|
||||
return 0
|
||||
end
|
||||
M.format(opts)
|
||||
return 0
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
local errors = require("conform.errors")
|
||||
local fs = require("conform.fs")
|
||||
local ft_to_ext = require("conform.ft_to_ext")
|
||||
local log = require("conform.log")
|
||||
local util = require("conform.util")
|
||||
local uv = vim.uv or vim.loop
|
||||
@ -196,6 +197,7 @@ M.apply_format = function(bufnr, original_lines, new_lines, range, only_apply_ra
|
||||
end
|
||||
|
||||
log.trace("Comparing lines %s and %s", original_lines, new_lines)
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
local indices = vim.diff(original_text, new_text, {
|
||||
result_type = "indices",
|
||||
algorithm = "histogram",
|
||||
@ -328,6 +330,8 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
|
||||
log.debug("Run command: %s", cmd)
|
||||
if cwd then
|
||||
log.debug("Run CWD: %s", cwd)
|
||||
else
|
||||
log.debug("Run default CWD: %s", vim.fn.getcwd())
|
||||
end
|
||||
if env then
|
||||
log.debug("Run ENV: %s", env)
|
||||
@ -456,7 +460,7 @@ M.build_context = function(bufnr, config, range)
|
||||
filename = fs.join(dirname, "unnamed_temp")
|
||||
local ft = vim.bo[bufnr].filetype
|
||||
if ft and ft ~= "" then
|
||||
filename = filename .. "." .. ft
|
||||
filename = filename .. "." .. (ft_to_ext[ft] or ft)
|
||||
end
|
||||
else
|
||||
dirname = vim.fs.dirname(filename)
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
---@field inherit? boolean
|
||||
---@field command? string|fun(self: conform.FormatterConfig, ctx: conform.Context): string
|
||||
---@field prepend_args? string|string[]|fun(self: conform.FormatterConfig, ctx: conform.Context): string|string[]
|
||||
---@field append_args? string|string[]|fun(self: conform.FormatterConfig, ctx: conform.Context): string|string[]
|
||||
---@field format? fun(self: conform.LuaFormatterConfig, ctx: conform.Context, lines: string[], callback: fun(err: nil|string, new_lines: nil|string[])) Mutually exclusive with command
|
||||
---@field options? table
|
||||
|
||||
@ -61,8 +62,8 @@
|
||||
|
||||
---@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): 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 format_after_save? conform.FormatOpts|fun(bufnr: integer): 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 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 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 formatters? table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride> Custom formatters and overrides for built-in formatters.
|
||||
|
||||
@ -49,6 +49,9 @@ end
|
||||
---@return fun(self: conform.FormatterConfig, ctx: conform.Context): nil|string
|
||||
M.root_file = function(files)
|
||||
return function(self, ctx)
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
return vim.fs.root(ctx.dirname, files)
|
||||
end
|
||||
local found = vim.fs.find(files, { upward = true, path = ctx.dirname })[1]
|
||||
if found then
|
||||
return vim.fs.dirname(found)
|
||||
@ -167,6 +170,8 @@ M.merge_formatter_configs = function(config, override)
|
||||
local ret = vim.tbl_deep_extend("force", config, override)
|
||||
if override.prepend_args then
|
||||
M.add_formatter_args(ret, override.prepend_args, { append = false })
|
||||
elseif override.append_args then
|
||||
M.add_formatter_args(ret, override.append_args, { append = true })
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
set -e
|
||||
|
||||
mkdir -p ".testenv/config/nvim"
|
||||
|
||||
@ -16,7 +16,7 @@ require("conform").setup({
|
||||
return
|
||||
end
|
||||
-- ...additional logic...
|
||||
return { timeout_ms = 500, lsp_fallback = true }
|
||||
return { timeout_ms = 500, lsp_format = "fallback" }
|
||||
end,
|
||||
})
|
||||
|
||||
@ -28,6 +28,6 @@ require("conform").setup({
|
||||
return
|
||||
end
|
||||
-- ...additional logic...
|
||||
return { lsp_fallback = true }
|
||||
return { lsp_format = "fallback" }
|
||||
end,
|
||||
})
|
||||
|
||||
@ -25,14 +25,14 @@ require("conform").setup({
|
||||
-- This can also be a function that returns the table.
|
||||
format_on_save = {
|
||||
-- I recommend these options. See :help conform.format for details.
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
timeout_ms = 500,
|
||||
},
|
||||
-- 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.
|
||||
format_after_save = {
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
-- Set the log level. Use `:ConformInfo` to see the location of the log file.
|
||||
log_level = vim.log.levels.ERROR,
|
||||
@ -73,9 +73,13 @@ 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.
|
||||
-- This can also be a function, like args
|
||||
append_args = { "--trailing-comma" },
|
||||
},
|
||||
-- These can also be a function that returns the formatter
|
||||
other_formatter = function(bufnr)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
|
||||
#!/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
Reference in New Issue
Block a user