mirror of
https://github.com/neovim/neovim.git
synced 2026-04-25 08:44:06 +00:00
feat(lua): conversion between vim and lsp position/range
This commit is contained in:
@@ -5,6 +5,7 @@ local eq = t.eq
|
||||
|
||||
local clear = n.clear
|
||||
local exec_lua = n.exec_lua
|
||||
local insert = n.insert
|
||||
|
||||
describe('vim.pos', function()
|
||||
before_each(clear)
|
||||
@@ -67,4 +68,24 @@ describe('vim.pos', function()
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('supports conversion between vim.Pos and lsp.Position', function()
|
||||
local buf = exec_lua(function()
|
||||
return vim.api.nvim_get_current_buf()
|
||||
end)
|
||||
insert('Neovim 是 Vim 的分支,专注于扩展性和可用性。')
|
||||
local lsp_pos = exec_lua(function()
|
||||
local pos = vim.pos(0, 36, { buf = buf })
|
||||
return pos:to_lsp('utf-16')
|
||||
end)
|
||||
eq({ line = 0, character = 20 }, lsp_pos)
|
||||
local pos = exec_lua(function()
|
||||
return vim.pos.lsp(buf, lsp_pos, 'utf-16')
|
||||
end)
|
||||
eq({
|
||||
buf = buf,
|
||||
row = 0,
|
||||
col = 36,
|
||||
}, pos)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user