aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/semantic_tokens.lua
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2023-01-19 19:37:12 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-01-19 20:08:12 +0000
commitb3e662b4b5b41e19368318dfaf09c731fbaf9597 (patch)
treed6aae47922ffeec6e4d6d6ec65490a6c7d329bcb /runtime/lua/vim/lsp/semantic_tokens.lua
parentb8f56fec7f99a2ebda5331c907f87ba3b445d5ca (diff)
downloadrneovim-20220114-mix.tar.gz
rneovim-20220114-mix.tar.bz2
rneovim-20220114-mix.zip
fix(semantic_tokens.lua): Fix nil tokens/data in semantic_tokens.luafix_semantic_tokens20220114-mix
Some (poorly-implemented) LSPs can return an empty JSON object in LSP responses, which could cause tokens to be nil, which would eventually cause an error and a bad UI experience. This fix makes sure that the tokens variable is always set to a non-nil value.
Diffstat (limited to 'runtime/lua/vim/lsp/semantic_tokens.lua')
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua6
1 files changed, 3 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index b1bc48dac6..a9d3d0cbd6 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -330,7 +330,7 @@ function STHighlighter:process_response(response, client, version)
end
vim.list_extend(tokens, old_tokens, idx)
else
- tokens = response.data
+ tokens = response.data or {}
end
-- Update the state with the new results
@@ -378,7 +378,7 @@ function STHighlighter:on_win(topline, botline)
--
-- Instead, we have to use normal extmarks that can attach to locations
-- in the buffer and are persisted between redraws.
- local highlights = current_result.highlights
+ local highlights = current_result.highlights or {}
local idx = binary_search(highlights, topline)
for i = idx, #highlights do
@@ -612,7 +612,7 @@ function M.get_at_pos(bufnr, row, col)
local tokens = {}
for client_id, client in pairs(highlighter.client_state) do
- local highlights = client.current_result.highlights
+ local highlights = client.current_result.highlights or {}
if highlights then
local idx = binary_search(highlights, row)
for i = idx, #highlights do