Skip to content

Commit 2caa05f

Browse files
authored
fix: Use offset encoding of first client (#1506)
1 parent d027f8b commit 2caa05f

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

lua/lspsaga/codeaction/init.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,18 @@ function act:send_request(main_buf, options, callback)
169169
end
170170
local params
171171
local mode = api.nvim_get_mode().mode
172+
local client = vim.lsp.get_clients({ bufnr = main_buf })[1]
173+
local offset_encoding = client and client.offset_encoding or 'utf-16'
172174
if options.range then
173175
assert(type(options.range) == 'table', 'code_action range must be a table')
174176
local start = assert(options.range.start, 'range must have a `start` property')
175177
local end_ = assert(options.range['end'], 'range must have a `end` property')
176-
params = lsp.util.make_given_range_params(start, end_)
178+
params = lsp.util.make_given_range_params(start, end_, offset_encoding)
177179
elseif mode == 'v' or mode == 'V' then
178180
local range = range_from_selection(0, mode)
179181
params = lsp.util.make_given_range_params(range.start, range['end'])
180182
else
181-
params = lsp.util.make_range_params()
183+
params = lsp.util.make_range_params(0, offset_encoding)
182184
end
183185

184186
params.context = context

lua/lspsaga/codeaction/lightbulb.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ end
106106

107107
local function render(bufnr)
108108
local row = api.nvim_win_get_cursor(0)[1] - 1
109-
local params = lsp.util.make_range_params()
109+
local client = vim.lsp.get_clients({ bufnr = bufnr })[1]
110+
local offset_encoding = client and client.offset_encoding or 'utf-16'
111+
local params = lsp.util.make_range_params(0, offset_encoding)
110112
params.context = {
111113
diagnostics = diagnostic_vim_to_lsp(vim.diagnostic.get(bufnr, { lnum = row })),
112114
}

0 commit comments

Comments
 (0)