aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/semantic_tokens.lua
diff options
context:
space:
mode:
authorTristan Knight <admin@snappeh.com>2024-09-08 11:44:46 +0100
committerGitHub <noreply@github.com>2024-09-08 03:44:46 -0700
commit003b8a251dc1184e36c222f675bf79a50a40ab3a (patch)
treee30192fa5362163eafc657c6ba5f4d512ee4cb53 /runtime/lua/vim/lsp/semantic_tokens.lua
parent0cfbc6eafff731d2d2ecce1f6ceb40be340473f3 (diff)
downloadrneovim-003b8a251dc1184e36c222f675bf79a50a40ab3a.tar.gz
rneovim-003b8a251dc1184e36c222f675bf79a50a40ab3a.tar.bz2
rneovim-003b8a251dc1184e36c222f675bf79a50a40ab3a.zip
fix(lsp): handle out-of-bounds character positions #30288
Problem: str_byteindex_enc could return an error if the index was longer than the lline length. This was handled in each of the calls to it individually Solution: * Fix the call at the source level so that if the index is higher than the line length, line length is returned as per LSP specification * Remove pcalls on str_byteindex_enc calls. No longer needed now that str_byteindex_enc has a bounds check.
Diffstat (limited to 'runtime/lua/vim/lsp/semantic_tokens.lua')
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua7
1 files changed, 1 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index 2ae86851d1..8182457dd0 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -140,12 +140,7 @@ local function tokens_to_ranges(data, bufnr, client, request)
local function _get_byte_pos(col)
if col > 0 then
local buf_line = lines[line + 1] or ''
- local ok, result
- ok, result = pcall(util._str_byteindex_enc, buf_line, col, client.offset_encoding)
- if ok then
- return result
- end
- return math.min(#buf_line, col)
+ return util._str_byteindex_enc(buf_line, col, client.offset_encoding)
end
return col
end