feat(pos): create a cursor position by using the current of a window

Problem:
`vim.pos.cursor(vim.api.nvim_get_current_buf(win), vim.api.nvim_win_get_cursor(win))`
is too verbose to create a cursor position of a window,
but it is a common use case.

Solution:
Overload `vim.pos.cursor()`, so that it accepts `win` as an argument when `pos` is omitted.
This commit is contained in:
Yi Ming
2026-06-02 20:06:08 +08:00
parent 3f37b230af
commit 2bd13177b8
6 changed files with 47 additions and 12 deletions

View File

@@ -1810,10 +1810,9 @@ end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
function M.make_position_params(win, position_encoding)
win = win or 0
local buf = api.nvim_win_get_buf(win)
return {
textDocument = M.make_text_document_params(buf),
position = vim.pos.cursor(buf, api.nvim_win_get_cursor(win)):to_lsp(position_encoding),
textDocument = M.make_text_document_params(api.nvim_win_get_buf(win)),
position = vim.pos.cursor(win):to_lsp(position_encoding),
}
end