aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua6
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua14
2 files changed, 17 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
diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua
index 9c1ba86fe1..50b91edeb3 100644
--- a/test/functional/plugin/lsp/semantic_tokens_spec.lua
+++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua
@@ -852,6 +852,20 @@ b = "as"]],
},
},
},
+ {
+ it = 'nil_data',
+ text = [[some text]],
+ response = [[{}]], -- Data is nil
+ legend = [[{
+ "tokenTypes": [
+ "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "keyword", "modifier", "comment", "string", "number", "regexp", "operator"
+ ],
+ "tokenModifiers": [
+ "declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary"
+ ]
+ }]],
+ expected = {},
+ },
}) do
it(test.it, function()
exec_lua(create_server_definition)