From cddd536e087a9fd3d2c9ea5b0a44e46c7b4b54c2 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Mon, 28 Aug 2023 18:28:07 -0700 Subject: feat: range formatting Should work the same as vim.lsp.buf.format(). Additionally, range formatting is supported for *any* formatter. If the formatter doesn't have native support for ranges, conform will do its best to only apply the diffs that affect that range. --- lua/conform/formatters/prettier.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lua/conform/formatters/prettier.lua') diff --git a/lua/conform/formatters/prettier.lua b/lua/conform/formatters/prettier.lua index 6f4bbfb..ea45ffb 100644 --- a/lua/conform/formatters/prettier.lua +++ b/lua/conform/formatters/prettier.lua @@ -1,5 +1,5 @@ local util = require("conform.util") ----@type conform.FormatterConfig +---@type conform.FileFormatterConfig return { meta = { url = "https://github.com/prettier/prettier", @@ -7,6 +7,10 @@ return { }, command = util.from_node_modules("prettier"), args = { "--stdin-filepath", "$FILENAME" }, + range_args = function(ctx) + local start_offset, end_offset = util.get_offsets_from_range(ctx.buf, ctx.range) + return { "$FILENAME", "--range-start=" .. start_offset, "--range-end=" .. end_offset } + end, cwd = util.root_file({ -- https://prettier.io/docs/en/configuration.html ".prettierrc", -- cgit v1.2.3-70-g09d2