From db2c697fe8302f0328b50b480204be1b577a1e2f Mon Sep 17 00:00:00 2001 From: Wojciech Kulik <3128467+wojciech-kulik@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:58:41 +0100 Subject: [PATCH] fix(swiftformat): range formatting support and add cwd (#326) --- lua/conform/formatters/swiftformat.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/conform/formatters/swiftformat.lua b/lua/conform/formatters/swiftformat.lua index ed142ad6..adde245e 100644 --- a/lua/conform/formatters/swiftformat.lua +++ b/lua/conform/formatters/swiftformat.lua @@ -5,5 +5,16 @@ return { description = "SwiftFormat is a code library and command-line tool for reformatting `swift` code on macOS or Linux.", }, command = "swiftformat", + stdin = true, args = { "--stdinpath", "$FILENAME" }, + range_args = function(self, ctx) + local startOffset = tonumber(ctx.range.start[1]) - 1 + local endOffset = tonumber(ctx.range["end"][1]) - 1 + + return { + "--linerange", + startOffset .. "," .. endOffset, + } + end, + cwd = require("conform.util").root_file({ ".swiftformat", "Package.swift", "buildServer.json" }), }