diff options
author | Steven Arcangeli <stevearc@stevearc.com> | 2023-08-28 18:28:07 -0700 |
---|---|---|
committer | Steven Arcangeli <stevearc@stevearc.com> | 2023-08-28 18:28:07 -0700 |
commit | cddd536e087a9fd3d2c9ea5b0a44e46c7b4b54c2 (patch) | |
tree | 70f6868440596ae90b7f451379c3abfa5678849c /lua/conform/util.lua | |
parent | 69c4495ab5ad3c07c3a4f3c2bcac2f070718b4cb (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/util.lua')
-rw-r--r-- | lua/conform/util.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lua/conform/util.lua b/lua/conform/util.lua index 353c447..d2ca1b9 100644 --- a/lua/conform/util.lua +++ b/lua/conform/util.lua @@ -58,6 +58,20 @@ M.save_win_positions = function(bufnr) end end +---@param bufnr integer +---@param range conform.Range +---@return integer start_offset +---@return integer end_offset +M.get_offsets_from_range = function(bufnr, range) + local row = range.start[1] - 1 + local end_row = range["end"][1] - 1 + local col = range.start[2] + local end_col = range["end"][2] + local start_offset = vim.api.nvim_buf_get_offset(bufnr, row) + col + local end_offset = vim.api.nvim_buf_get_offset(bufnr, end_row) + end_col + return start_offset, end_offset +end + ---@generic T : any ---@param tbl T[] ---@param start_idx? number |