Skip to content

Commit

Permalink
fix: range format method for async formatters and injected
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Nov 18, 2023
1 parent eeef888 commit a36c68d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lua/conform/formatters/injected.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,7 @@ return {
apply_format_results()
end
end,
-- TODO this is kind of a hack. It's here to ensure all_support_range_formatting is set properly.
-- Should figure out a better way to do this.
range_args = true,
}
10 changes: 8 additions & 2 deletions lua/conform/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ M.build_cmd = function(ctx, config)
end
end

---@param value any
---@return boolean
local function truthy(value)
return value ~= nil and value ~= false
end

---@param range conform.Range
---@param start_a integer
---@param end_a integer
Expand Down Expand Up @@ -506,9 +512,9 @@ M.format_lines_async = function(bufnr, formatters, range, input_lines, opts, cal
final_err = errors.coalesce(final_err, err)
end
input_lines = output or input_lines
all_support_range_formatting = all_support_range_formatting and truthy(config.range_args)
run_next_formatter()
end)
all_support_range_formatting = all_support_range_formatting and config.range_args ~= nil
end
run_next_formatter()
end
Expand Down Expand Up @@ -584,7 +590,7 @@ M.format_lines_sync = function(bufnr, formatters, timeout_ms, range, input_lines
result = output
end
)
all_support_range_formatting = all_support_range_formatting and config.range_args ~= nil
all_support_range_formatting = all_support_range_formatting and truthy(config.range_args)

local wait_result, wait_reason = vim.wait(remaining, function()
return done
Expand Down

0 comments on commit a36c68d

Please sign in to comment.