mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
feat(lsp): more annotations
This commit is contained in:
committed by
Lewis Russell
parent
320e9c1c21
commit
97bea3163a
@@ -58,7 +58,7 @@ local function byte_to_utf(line, byte, offset_encoding)
|
||||
-- convert to 0 based indexing for str_utfindex
|
||||
byte = byte - 1
|
||||
|
||||
local utf_idx
|
||||
local utf_idx --- @type integer
|
||||
local _
|
||||
-- Convert the byte range to utf-{8,16,32} and convert 1-based (lua) indexing to 0-based
|
||||
if offset_encoding == 'utf-16' then
|
||||
@@ -73,8 +73,11 @@ local function byte_to_utf(line, byte, offset_encoding)
|
||||
return utf_idx + 1
|
||||
end
|
||||
|
||||
---@param line string
|
||||
---@param offset_encoding string
|
||||
---@return integer
|
||||
local function compute_line_length(line, offset_encoding)
|
||||
local length
|
||||
local length --- @type integer
|
||||
local _
|
||||
if offset_encoding == 'utf-16' then
|
||||
_, length = str_utfindex(line)
|
||||
@@ -94,7 +97,7 @@ end
|
||||
---@return integer byte_idx of first change position
|
||||
---@return integer char_idx of first change position
|
||||
local function align_end_position(line, byte, offset_encoding)
|
||||
local char
|
||||
local char --- @type integer
|
||||
-- If on the first byte, or an empty string: the trivial case
|
||||
if byte == 1 or #line == 0 then
|
||||
char = byte
|
||||
@@ -120,8 +123,8 @@ local function align_end_position(line, byte, offset_encoding)
|
||||
end
|
||||
|
||||
--- 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 table list of lines from previous buffer
|
||||
---@param curr_lines table list of lines from current buffer
|
||||
---@param prev_lines string[] list of lines from previous buffer
|
||||
---@param curr_lines string[] list of lines from current buffer
|
||||
---@param firstline integer firstline from on_lines, adjusted to 1-index
|
||||
---@param lastline integer lastline from on_lines, adjusted to 1-index
|
||||
---@param new_lastline integer new_lastline from on_lines, adjusted to 1-index
|
||||
@@ -135,14 +138,14 @@ local function compute_start_range(
|
||||
new_lastline,
|
||||
offset_encoding
|
||||
)
|
||||
local char_idx
|
||||
local byte_idx
|
||||
local char_idx --- @type integer?
|
||||
local byte_idx --- @type integer?
|
||||
-- If firstline == lastline, no existing text is changed. All edit operations
|
||||
-- occur on a new line pointed to by lastline. This occurs during insertion of
|
||||
-- new lines(O), the new newline is inserted at the line indicated by
|
||||
-- new_lastline.
|
||||
if firstline == lastline then
|
||||
local line_idx
|
||||
local line_idx --- @type integer
|
||||
local line = prev_lines[firstline - 1]
|
||||
if line then
|
||||
line_idx = firstline - 1
|
||||
@@ -343,6 +346,12 @@ end
|
||||
-- codeunits for utf-32
|
||||
-- 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 offset_encoding string
|
||||
---@param line_ending string
|
||||
---@return integer
|
||||
local function compute_range_length(lines, start_range, end_range, offset_encoding, line_ending)
|
||||
local line_ending_length = #line_ending
|
||||
-- Single line case
|
||||
@@ -351,7 +360,7 @@ local function compute_range_length(lines, start_range, end_range, offset_encodi
|
||||
end
|
||||
|
||||
local start_line = lines[start_range.line_idx]
|
||||
local range_length
|
||||
local range_length --- @type integer
|
||||
if start_line and #start_line > 0 then
|
||||
range_length = compute_line_length(start_line, offset_encoding)
|
||||
- start_range.char_idx
|
||||
@@ -387,6 +396,7 @@ end
|
||||
---@param lastline integer line to begin search in old_lines for last difference
|
||||
---@param new_lastline integer line to begin search in new_lines for last difference
|
||||
---@param offset_encoding string encoding requested by language server
|
||||
---@param line_ending string
|
||||
---@return table TextDocumentContentChangeEvent see https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
|
||||
function M.compute_diff(
|
||||
prev_lines,
|
||||
|
||||
Reference in New Issue
Block a user