mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	feat(lsp.util): improve offset_encoding type annotations
This commit is contained in:
		@@ -1912,7 +1912,7 @@ apply_text_document_edit({text_document_edit}, {index}, {offset_encoding})
 | 
				
			|||||||
      • {text_document_edit}  (`lsp.TextDocumentEdit`)
 | 
					      • {text_document_edit}  (`lsp.TextDocumentEdit`)
 | 
				
			||||||
      • {index}               (`integer?`) Optional index of the edit, if from
 | 
					      • {index}               (`integer?`) Optional index of the edit, if from
 | 
				
			||||||
                              a list of edits (or nil, if not from a list)
 | 
					                              a list of edits (or nil, if not from a list)
 | 
				
			||||||
      • {offset_encoding}     (`string?`)
 | 
					      • {offset_encoding}     (`'utf-8'|'utf-16'|'utf-32'?`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    See also: ~
 | 
					    See also: ~
 | 
				
			||||||
      • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
 | 
					      • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
 | 
				
			||||||
@@ -1924,7 +1924,7 @@ apply_text_edits({text_edits}, {bufnr}, {offset_encoding})
 | 
				
			|||||||
    Parameters: ~
 | 
					    Parameters: ~
 | 
				
			||||||
      • {text_edits}       (`lsp.TextEdit[]`)
 | 
					      • {text_edits}       (`lsp.TextEdit[]`)
 | 
				
			||||||
      • {bufnr}            (`integer`) Buffer id
 | 
					      • {bufnr}            (`integer`) Buffer id
 | 
				
			||||||
      • {offset_encoding}  (`string`) utf-8|utf-16|utf-32
 | 
					      • {offset_encoding}  (`'utf-8'|'utf-16'|'utf-32'`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    See also: ~
 | 
					    See also: ~
 | 
				
			||||||
      • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
 | 
					      • https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
 | 
				
			||||||
@@ -1953,7 +1953,7 @@ buf_highlight_references({bufnr}, {references}, {offset_encoding})
 | 
				
			|||||||
    Parameters: ~
 | 
					    Parameters: ~
 | 
				
			||||||
      • {bufnr}            (`integer`) Buffer id
 | 
					      • {bufnr}            (`integer`) Buffer id
 | 
				
			||||||
      • {references}       (`lsp.DocumentHighlight[]`) objects to highlight
 | 
					      • {references}       (`lsp.DocumentHighlight[]`) objects to highlight
 | 
				
			||||||
      • {offset_encoding}  (`string`) One of "utf-8", "utf-16", "utf-32".
 | 
					      • {offset_encoding}  (`'utf-8'|'utf-16'|'utf-32'`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    See also: ~
 | 
					    See also: ~
 | 
				
			||||||
      • https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
 | 
					      • https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
 | 
				
			||||||
@@ -1966,7 +1966,7 @@ character_offset({buf}, {row}, {col}, {offset_encoding})
 | 
				
			|||||||
      • {buf}              (`integer`) buffer number (0 for current)
 | 
					      • {buf}              (`integer`) buffer number (0 for current)
 | 
				
			||||||
      • {row}              (`integer`) 0-indexed line
 | 
					      • {row}              (`integer`) 0-indexed line
 | 
				
			||||||
      • {col}              (`integer`) 0-indexed byte offset in line
 | 
					      • {col}              (`integer`) 0-indexed byte offset in line
 | 
				
			||||||
      • {offset_encoding}  (`string`) utf-8|utf-16|utf-32 defaults to
 | 
					      • {offset_encoding}  (`'utf-8'|'utf-16'|'utf-32'?`) defaults to
 | 
				
			||||||
                           `offset_encoding` of first client of `buf`
 | 
					                           `offset_encoding` of first client of `buf`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Return: ~
 | 
					    Return: ~
 | 
				
			||||||
@@ -2033,7 +2033,7 @@ jump_to_location({location}, {offset_encoding}, {reuse_win})
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Parameters: ~
 | 
					    Parameters: ~
 | 
				
			||||||
      • {location}         (`lsp.Location|lsp.LocationLink`)
 | 
					      • {location}         (`lsp.Location|lsp.LocationLink`)
 | 
				
			||||||
      • {offset_encoding}  (`string?`) utf-8|utf-16|utf-32
 | 
					      • {offset_encoding}  (`'utf-8'|'utf-16'|'utf-32'?`)
 | 
				
			||||||
      • {reuse_win}        (`boolean?`) Jump to existing window if buffer is
 | 
					      • {reuse_win}        (`boolean?`) Jump to existing window if buffer is
 | 
				
			||||||
                           already open.
 | 
					                           already open.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2053,9 +2053,8 @@ locations_to_items({locations}, {offset_encoding})
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Parameters: ~
 | 
					    Parameters: ~
 | 
				
			||||||
      • {locations}        (`lsp.Location[]|lsp.LocationLink[]`)
 | 
					      • {locations}        (`lsp.Location[]|lsp.LocationLink[]`)
 | 
				
			||||||
      • {offset_encoding}  (`string`) offset_encoding for locations
 | 
					      • {offset_encoding}  (`'utf-8'|'utf-16'|'utf-32'?`) default to first
 | 
				
			||||||
                           utf-8|utf-16|utf-32 default to first client of
 | 
					                           client of buffer
 | 
				
			||||||
                           buffer
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Return: ~
 | 
					    Return: ~
 | 
				
			||||||
        (`vim.quickfix.entry[]`) See |setqflist()| for the format
 | 
					        (`vim.quickfix.entry[]`) See |setqflist()| for the format
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -362,7 +362,7 @@ end
 | 
				
			|||||||
--- Applies a list of text edits to a buffer.
 | 
					--- Applies a list of text edits to a buffer.
 | 
				
			||||||
---@param text_edits lsp.TextEdit[]
 | 
					---@param text_edits lsp.TextEdit[]
 | 
				
			||||||
---@param bufnr integer Buffer id
 | 
					---@param bufnr integer Buffer id
 | 
				
			||||||
---@param offset_encoding string utf-8|utf-16|utf-32
 | 
					---@param offset_encoding 'utf-8'|'utf-16'|'utf-32'
 | 
				
			||||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
 | 
					---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
 | 
				
			||||||
function M.apply_text_edits(text_edits, bufnr, offset_encoding)
 | 
					function M.apply_text_edits(text_edits, bufnr, offset_encoding)
 | 
				
			||||||
  validate('text_edits', text_edits, 'table', false)
 | 
					  validate('text_edits', text_edits, 'table', false)
 | 
				
			||||||
@@ -497,7 +497,7 @@ end
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
---@param text_document_edit lsp.TextDocumentEdit
 | 
					---@param text_document_edit lsp.TextDocumentEdit
 | 
				
			||||||
---@param index? integer: Optional index of the edit, if from a list of edits (or nil, if not from a list)
 | 
					---@param index? integer: Optional index of the edit, if from a list of edits (or nil, if not from a list)
 | 
				
			||||||
---@param offset_encoding? string
 | 
					---@param offset_encoding? 'utf-8'|'utf-16'|'utf-32'
 | 
				
			||||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
 | 
					---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
 | 
				
			||||||
function M.apply_text_document_edit(text_document_edit, index, offset_encoding)
 | 
					function M.apply_text_document_edit(text_document_edit, index, offset_encoding)
 | 
				
			||||||
  local text_document = text_document_edit.textDocument
 | 
					  local text_document = text_document_edit.textDocument
 | 
				
			||||||
@@ -1025,7 +1025,7 @@ end
 | 
				
			|||||||
--- Jumps to a location.
 | 
					--- Jumps to a location.
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
---@param location lsp.Location|lsp.LocationLink
 | 
					---@param location lsp.Location|lsp.LocationLink
 | 
				
			||||||
---@param offset_encoding string? utf-8|utf-16|utf-32
 | 
					---@param offset_encoding 'utf-8'|'utf-16'|'utf-32'?
 | 
				
			||||||
---@param reuse_win boolean? Jump to existing window if buffer is already open.
 | 
					---@param reuse_win boolean? Jump to existing window if buffer is already open.
 | 
				
			||||||
---@return boolean `true` if the jump succeeded
 | 
					---@return boolean `true` if the jump succeeded
 | 
				
			||||||
function M.jump_to_location(location, offset_encoding, reuse_win)
 | 
					function M.jump_to_location(location, offset_encoding, reuse_win)
 | 
				
			||||||
@@ -1694,7 +1694,7 @@ do --[[ References ]]
 | 
				
			|||||||
  ---
 | 
					  ---
 | 
				
			||||||
  ---@param bufnr integer Buffer id
 | 
					  ---@param bufnr integer Buffer id
 | 
				
			||||||
  ---@param references lsp.DocumentHighlight[] objects to highlight
 | 
					  ---@param references lsp.DocumentHighlight[] objects to highlight
 | 
				
			||||||
  ---@param offset_encoding string One of "utf-8", "utf-16", "utf-32".
 | 
					  ---@param offset_encoding 'utf-8'|'utf-16'|'utf-32'
 | 
				
			||||||
  ---@see https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
 | 
					  ---@see https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
 | 
				
			||||||
  function M.buf_highlight_references(bufnr, references, offset_encoding)
 | 
					  function M.buf_highlight_references(bufnr, references, offset_encoding)
 | 
				
			||||||
    validate('bufnr', bufnr, 'number', true)
 | 
					    validate('bufnr', bufnr, 'number', true)
 | 
				
			||||||
@@ -1748,7 +1748,7 @@ end)
 | 
				
			|||||||
--- |setloclist()|.
 | 
					--- |setloclist()|.
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
---@param locations lsp.Location[]|lsp.LocationLink[]
 | 
					---@param locations lsp.Location[]|lsp.LocationLink[]
 | 
				
			||||||
---@param offset_encoding string offset_encoding for locations utf-8|utf-16|utf-32
 | 
					---@param offset_encoding? 'utf-8'|'utf-16'|'utf-32'
 | 
				
			||||||
---                         default to first client of buffer
 | 
					---                         default to first client of buffer
 | 
				
			||||||
---@return vim.quickfix.entry[] # See |setqflist()| for the format
 | 
					---@return vim.quickfix.entry[] # See |setqflist()| for the format
 | 
				
			||||||
function M.locations_to_items(locations, offset_encoding)
 | 
					function M.locations_to_items(locations, offset_encoding)
 | 
				
			||||||
@@ -2088,7 +2088,8 @@ end
 | 
				
			|||||||
---@param buf integer buffer number (0 for current)
 | 
					---@param buf integer buffer number (0 for current)
 | 
				
			||||||
---@param row integer 0-indexed line
 | 
					---@param row integer 0-indexed line
 | 
				
			||||||
---@param col integer 0-indexed byte offset in line
 | 
					---@param col integer 0-indexed byte offset in line
 | 
				
			||||||
---@param offset_encoding string utf-8|utf-16|utf-32 defaults to `offset_encoding` of first client of `buf`
 | 
					---@param offset_encoding? 'utf-8'|'utf-16'|'utf-32'
 | 
				
			||||||
 | 
					---                        defaults to `offset_encoding` of first client of `buf`
 | 
				
			||||||
---@return integer `offset_encoding` index of the character in line {row} column {col} in buffer {buf}
 | 
					---@return integer `offset_encoding` index of the character in line {row} column {col} in buffer {buf}
 | 
				
			||||||
function M.character_offset(buf, row, col, offset_encoding)
 | 
					function M.character_offset(buf, row, col, offset_encoding)
 | 
				
			||||||
  local line = get_line(buf, row)
 | 
					  local line = get_line(buf, row)
 | 
				
			||||||
@@ -2126,7 +2127,7 @@ end
 | 
				
			|||||||
---@param bufnr integer
 | 
					---@param bufnr integer
 | 
				
			||||||
---@param start_line integer
 | 
					---@param start_line integer
 | 
				
			||||||
---@param end_line integer
 | 
					---@param end_line integer
 | 
				
			||||||
---@param offset_encoding lsp.PositionEncodingKind
 | 
					---@param offset_encoding 'utf-8'|'utf-16'|'utf-32'
 | 
				
			||||||
---@return lsp.Range
 | 
					---@return lsp.Range
 | 
				
			||||||
local function make_line_range_params(bufnr, start_line, end_line, offset_encoding)
 | 
					local function make_line_range_params(bufnr, start_line, end_line, offset_encoding)
 | 
				
			||||||
  local last_line = api.nvim_buf_line_count(bufnr) - 1
 | 
					  local last_line = api.nvim_buf_line_count(bufnr) - 1
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user