Skip to content

Commit

Permalink
fix: Use offset encoding of first client (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutkat authored Dec 9, 2024
1 parent d027f8b commit 2caa05f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lua/lspsaga/codeaction/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,18 @@ function act:send_request(main_buf, options, callback)
end
local params
local mode = api.nvim_get_mode().mode
local client = vim.lsp.get_clients({ bufnr = main_buf })[1]
local offset_encoding = client and client.offset_encoding or 'utf-16'
if options.range then
assert(type(options.range) == 'table', 'code_action range must be a table')
local start = assert(options.range.start, 'range must have a `start` property')
local end_ = assert(options.range['end'], 'range must have a `end` property')
params = lsp.util.make_given_range_params(start, end_)
params = lsp.util.make_given_range_params(start, end_, offset_encoding)
elseif mode == 'v' or mode == 'V' then
local range = range_from_selection(0, mode)
params = lsp.util.make_given_range_params(range.start, range['end'])
else
params = lsp.util.make_range_params()
params = lsp.util.make_range_params(0, offset_encoding)
end

params.context = context
Expand Down
4 changes: 3 additions & 1 deletion lua/lspsaga/codeaction/lightbulb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ end

local function render(bufnr)
local row = api.nvim_win_get_cursor(0)[1] - 1
local params = lsp.util.make_range_params()
local client = vim.lsp.get_clients({ bufnr = bufnr })[1]
local offset_encoding = client and client.offset_encoding or 'utf-16'
local params = lsp.util.make_range_params(0, offset_encoding)
params.context = {
diagnostics = diagnostic_vim_to_lsp(vim.diagnostic.get(bufnr, { lnum = row })),
}
Expand Down

0 comments on commit 2caa05f

Please sign in to comment.