diff options
author | Maria José Solano <majosolano99@gmail.com> | 2024-02-10 14:04:44 -0800 |
---|---|---|
committer | Maria José Solano <majosolano99@gmail.com> | 2024-02-10 20:05:47 -0800 |
commit | eac7e3fc6c738d7023c104f09341dbb10bf3c4bc (patch) | |
tree | 4af01783a23515bd0a63585e293c94a55068f0e5 | |
parent | 5a6868c888a9ef5bd22e004e7cb116e4578ccf32 (diff) | |
download | rneovim-eac7e3fc6c738d7023c104f09341dbb10bf3c4bc.tar.gz rneovim-eac7e3fc6c738d7023c104f09341dbb10bf3c4bc.tar.bz2 rneovim-eac7e3fc6c738d7023c104f09341dbb10bf3c4bc.zip |
refactor(lsp): add vim.lsp.sync.Range type
-rw-r--r-- | runtime/lua/vim/lsp/sync.lua | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua index 7eed542667..62fa0b33f4 100644 --- a/runtime/lua/vim/lsp/sync.lua +++ b/runtime/lua/vim/lsp/sync.lua @@ -120,6 +120,11 @@ local function align_end_position(line, byte, offset_encoding) return byte, char end +---@class vim.lsp.sync.Range +---@field line_idx integer +---@field byte_idx integer +---@field char_idx integer + --- Finds the first line, byte, and char index of the difference between the previous and current lines buffer normalized to the previous codepoint. ---@param prev_lines string[] list of lines from previous buffer ---@param curr_lines string[] list of lines from current buffer @@ -127,7 +132,7 @@ end ---@param lastline integer lastline from on_lines, adjusted to 1-index ---@param new_lastline integer new_lastline from on_lines, adjusted to 1-index ---@param offset_encoding string utf-8|utf-16|utf-32|nil (fallback to utf-8) ----@return table result table include line_idx, byte_idx, and char_idx of first change position +---@return vim.lsp.sync.Range result table include line_idx, byte_idx, and char_idx of first change position local function compute_start_range( prev_lines, curr_lines, @@ -200,15 +205,14 @@ end --- prev_end_range is the text range sent to the server representing the changed region. --- curr_end_range is the text that should be collected and sent to the server. -- ----@param start_range table ---@param prev_lines string[] list of lines ---@param curr_lines string[] list of lines +---@param start_range vim.lsp.sync.Range ---@param firstline integer ---@param lastline integer ---@param new_lastline integer ---@param offset_encoding string ----@return integer|table end_line_idx and end_col_idx of range ----@return table|nil end_col_idx of range +---@return vim.lsp.sync.Range, vim.lsp.sync.Range local function compute_end_range( prev_lines, curr_lines, @@ -285,7 +289,7 @@ local function compute_end_range( local prev_end_range = { line_idx = prev_line_idx, byte_idx = prev_byte_idx, char_idx = prev_char_idx } - local curr_end_range + local curr_end_range ---@type vim.lsp.sync.Range -- Deletion event, new_range cannot be before start if curr_line_idx < start_line_idx then curr_end_range = { line_idx = start_line_idx, byte_idx = 1, char_idx = 1 } @@ -346,8 +350,8 @@ end -- Line endings count here as 2 chars for \r\n (dos), 1 char for \n (unix), and 1 char for \r (mac) -- These correspond to Windows, Linux/macOS (OSX and newer), and macOS (version 9 and prior) ---@param lines string[] ----@param start_range table ----@param end_range table +---@param start_range vim.lsp.sync.Range +---@param end_range vim.lsp.sync.Range ---@param offset_encoding string ---@param line_ending string ---@return integer |