diff options
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 |