aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/diagnostic.lua
diff options
context:
space:
mode:
authorTristan Knight <admin@snappeh.com>2024-10-26 15:38:25 +0100
committerGitHub <noreply@github.com>2024-10-26 07:38:25 -0700
commit25b53b593ef6f229fbec5b3dc205a7539579d13a (patch)
tree8c13b6b78e22437b8fd22ac8b639ecc65417fff3 /runtime/lua/vim/lsp/diagnostic.lua
parentb922b7d6d7889cce863540df7b0da7d512f8a2a1 (diff)
downloadrneovim-25b53b593ef6f229fbec5b3dc205a7539579d13a.tar.gz
rneovim-25b53b593ef6f229fbec5b3dc205a7539579d13a.tar.bz2
rneovim-25b53b593ef6f229fbec5b3dc205a7539579d13a.zip
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)
Diffstat (limited to 'runtime/lua/vim/lsp/diagnostic.lua')
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua24
1 files changed, 3 insertions, 21 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index bf72222536..c59e2db901 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -33,25 +33,6 @@ local function severity_vim_to_lsp(severity)
return severity
end
----@param lines string[]?
----@param lnum integer
----@param col integer
----@param offset_encoding string
----@return integer
-local function line_byte_from_position(lines, lnum, col, offset_encoding)
- if not lines or offset_encoding == 'utf-8' then
- return col
- end
-
- local line = lines[lnum + 1]
- local ok, result = pcall(vim.str_byteindex, line, col, offset_encoding == 'utf-16')
- if ok then
- return result --- @type integer
- end
-
- return col
-end
-
---@param bufnr integer
---@return string[]?
local function get_buf_lines(bufnr)
@@ -118,12 +99,13 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
)
message = diagnostic.message.value
end
+ local line = buf_lines and buf_lines[start.line + 1] or ''
--- @type vim.Diagnostic
return {
lnum = start.line,
- col = line_byte_from_position(buf_lines, start.line, start.character, offset_encoding),
+ col = vim.str_byteindex(line, offset_encoding, start.character, false),
end_lnum = _end.line,
- end_col = line_byte_from_position(buf_lines, _end.line, _end.character, offset_encoding),
+ end_col = vim.str_byteindex(line, offset_encoding, _end.character, false),
severity = severity_lsp_to_vim(diagnostic.severity),
message = message,
source = diagnostic.source,