aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters/stylua.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-08-28 18:28:07 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-08-28 18:28:07 -0700
commitcddd536e087a9fd3d2c9ea5b0a44e46c7b4b54c2 (patch)
tree70f6868440596ae90b7f451379c3abfa5678849c /lua/conform/formatters/stylua.lua
parent69c4495ab5ad3c07c3a4f3c2bcac2f070718b4cb (diff)
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.
Diffstat (limited to 'lua/conform/formatters/stylua.lua')
-rw-r--r--lua/conform/formatters/stylua.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/lua/conform/formatters/stylua.lua b/lua/conform/formatters/stylua.lua
index ac482bd..d971932 100644
--- a/lua/conform/formatters/stylua.lua
+++ b/lua/conform/formatters/stylua.lua
@@ -1,5 +1,5 @@
local util = require("conform.util")
----@type conform.FormatterConfig
+---@type conform.FileFormatterConfig
return {
meta = {
url = "https://github.com/JohnnyMorganz/StyLua",
@@ -7,6 +7,19 @@ return {
},
command = "stylua",
args = { "--search-parent-directories", "--stdin-filepath", "$FILENAME", "-" },
+ range_args = function(ctx)
+ local start_offset, end_offset = util.get_offsets_from_range(ctx.buf, ctx.range)
+ return {
+ "--search-parent-directories",
+ "--stdin-filepath",
+ "$FILENAME",
+ "--range-start",
+ tostring(start_offset),
+ "--range-end",
+ tostring(end_offset),
+ "-",
+ }
+ end,
cwd = util.root_file({
".stylua.toml",
"stylua.toml",