refactor(lsp): drop str_byteindex/str_utfindex wrappers #30915

* deprecate old signatures
* move to new str_byteindex/str_utfindex signature
* use single-underscore name (double-underscore is reserved for Lua itself)
This commit is contained in:
Tristan Knight
2024-10-26 15:38:25 +01:00
committed by GitHub
parent b922b7d6d7
commit 25b53b593e
12 changed files with 54 additions and 176 deletions

View File

@@ -70,20 +70,12 @@ function M.on_inlayhint(err, result, ctx, _)
end
local lines = api.nvim_buf_get_lines(bufnr, 0, -1, false)
---@param position lsp.Position
---@return integer
local function pos_to_byte(position)
local col = position.character
if col > 0 then
local line = lines[position.line + 1] or ''
return util._str_byteindex_enc(line, col, client.offset_encoding)
end
return col
end
for _, hint in ipairs(result) do
local lnum = hint.position.line
hint.position.character = pos_to_byte(hint.position)
local line = lines and lines[lnum + 1] or ''
hint.position.character =
vim.str_byteindex(line, client.offset_encoding, hint.position.character, false)
table.insert(new_lnum_hints[lnum], hint)
end