mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
feat(lua): conversion between extmark positions
This commit is contained in:
@@ -3986,20 +3986,23 @@ comparisons and conversions between various types of positions.
|
|||||||
as format conversions.
|
as format conversions.
|
||||||
|
|
||||||
Fields: ~
|
Fields: ~
|
||||||
• {row} (`integer`) 0-based byte index.
|
• {row} (`integer`) 0-based byte index.
|
||||||
• {col} (`integer`) 0-based byte index.
|
• {col} (`integer`) 0-based byte index.
|
||||||
• {buf}? (`integer`) Optional buffer handle.
|
• {buf}? (`integer`) Optional buffer handle.
|
||||||
|
|
||||||
When specified, it indicates that this position belongs
|
When specified, it indicates that this position belongs
|
||||||
to a specific buffer. This field is required when
|
to a specific buffer. This field is required when
|
||||||
performing position conversions.
|
performing position conversions.
|
||||||
• {to_lsp} (`fun(pos: vim.Pos, position_encoding: lsp.PositionEncodingKind)`)
|
• {to_lsp} (`fun(pos: vim.Pos, position_encoding: lsp.PositionEncodingKind)`)
|
||||||
See |Pos:to_lsp()|.
|
See |Pos:to_lsp()|.
|
||||||
• {lsp} (`fun(buf: integer, pos: lsp.Position, position_encoding: lsp.PositionEncodingKind)`)
|
• {lsp} (`fun(buf: integer, pos: lsp.Position, position_encoding: lsp.PositionEncodingKind)`)
|
||||||
See |Pos:lsp()|.
|
See |Pos:lsp()|.
|
||||||
• {to_cursor} (`fun(pos: vim.Pos): [integer, integer]`) See
|
• {to_cursor} (`fun(pos: vim.Pos): [integer, integer]`) See
|
||||||
|Pos:to_cursor()|.
|
|Pos:to_cursor()|.
|
||||||
• {cursor} (`fun(pos: [integer, integer])`) See |Pos:cursor()|.
|
• {cursor} (`fun(pos: [integer, integer])`) See |Pos:cursor()|.
|
||||||
|
• {to_extmark} (`fun(pos: vim.Pos): [integer, integer]`) See
|
||||||
|
|Pos:to_extmark()|.
|
||||||
|
• {extmark} (`fun(pos: [integer, integer])`) See |Pos:extmark()|.
|
||||||
|
|
||||||
|
|
||||||
Pos:cursor({pos}) *Pos:cursor()*
|
Pos:cursor({pos}) *Pos:cursor()*
|
||||||
@@ -4008,6 +4011,12 @@ Pos:cursor({pos}) *Pos:cursor()*
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {pos} (`[integer, integer]`)
|
• {pos} (`[integer, integer]`)
|
||||||
|
|
||||||
|
Pos:extmark({pos}) *Pos:extmark()*
|
||||||
|
Creates a new |vim.Pos| from extmark position.
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {pos} (`[integer, integer]`)
|
||||||
|
|
||||||
Pos:lsp({buf}, {pos}, {position_encoding}) *Pos:lsp()*
|
Pos:lsp({buf}, {pos}, {position_encoding}) *Pos:lsp()*
|
||||||
Creates a new |vim.Pos| from `lsp.Position`.
|
Creates a new |vim.Pos| from `lsp.Position`.
|
||||||
|
|
||||||
@@ -4036,6 +4045,15 @@ Pos:to_cursor({pos}) *Pos:to_cursor()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
(`[integer, integer]`)
|
(`[integer, integer]`)
|
||||||
|
|
||||||
|
Pos:to_extmark({pos}) *Pos:to_extmark()*
|
||||||
|
Converts |vim.Pos| to extmark position.
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {pos} (`vim.Pos`) See |vim.Pos|.
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
(`[integer, integer]`)
|
||||||
|
|
||||||
Pos:to_lsp({pos}, {position_encoding}) *Pos:to_lsp()*
|
Pos:to_lsp({pos}, {position_encoding}) *Pos:to_lsp()*
|
||||||
Converts |vim.Pos| to `lsp.Position`.
|
Converts |vim.Pos| to `lsp.Position`.
|
||||||
|
|
||||||
|
@@ -191,6 +191,20 @@ function Pos.cursor(pos)
|
|||||||
return Pos.new(pos[1] - 1, pos[2])
|
return Pos.new(pos[1] - 1, pos[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Converts |vim.Pos| to extmark position.
|
||||||
|
---@param pos vim.Pos
|
||||||
|
---@return [integer, integer]
|
||||||
|
function Pos.to_extmark(pos)
|
||||||
|
return { pos.row, pos.col }
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Creates a new |vim.Pos| from extmark position.
|
||||||
|
---@param pos [integer, integer]
|
||||||
|
function Pos.extmark(pos)
|
||||||
|
local row, col = unpack(pos)
|
||||||
|
return Pos.new(row, col)
|
||||||
|
end
|
||||||
|
|
||||||
-- Overload `Range.new` to allow calling this module as a function.
|
-- Overload `Range.new` to allow calling this module as a function.
|
||||||
setmetatable(Pos, {
|
setmetatable(Pos, {
|
||||||
__call = function(_, ...)
|
__call = function(_, ...)
|
||||||
|
Reference in New Issue
Block a user