From 1abbb82bb8e519e652d8b31b12a311872e9090d1 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Sun, 17 Sep 2023 10:02:10 -0700 Subject: feat: make lsp_fallback behavior more intuitive (#59) When lsp_fallback = true AND the only formatters for the buffer are from the "*" or "_" filetype, format with LSP instead of the "*"/"_" formatters. --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index eceb89d..fb2a923 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Lightweight yet powerful formatter plugin for Neovim - [list_formatters(bufnr)](#list_formattersbufnr) - [list_all_formatters()](#list_all_formatters) - [get_formatter_info(formatter, bufnr)](#get_formatter_infoformatter-bufnr) + - [will_fallback_lsp(options)](#will_fallback_lspoptions) - [Acknowledgements](#acknowledgements) @@ -241,12 +242,9 @@ require("conform").setup({ -- Use a sub-list to run only the first available formatter javascript = { { "prettierd", "prettier" } }, -- Use the "*" filetype to run formatters on all filetypes. - -- Note that if you use this, you may want to set lsp_fallback = "always" - -- (see :help conform.format) ["*"] = { "codespell" }, - -- Use the "_" filetype to run formatters on all filetypes - -- that don't have other formatters configured. Again, you may want to - -- set lsp_fallback = "always" when using this value. + -- Use the "_" filetype to run formatters on filetypes that don't + -- have other formatters configured. ["_"] = { "trim_whitespace" }, }, -- If this is set, Conform will run the formatter on save. @@ -384,6 +382,15 @@ 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_fallback = true + +| Param | Type | Desc | +| ------- | ------------ | ------------------------------------ | +| options | `nil\|table` | Options passed to vim.lsp.buf.format | ## Acknowledgements -- cgit v1.2.3-70-g09d2