Skip to content

Commit

Permalink
fix(lsp): token_edit.data might be null on deletion (neovim#21462)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagovla authored and yesean committed Mar 25, 2023
1 parent c098ae9 commit 8bcd433
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion runtime/lua/vim/lsp/semantic_tokens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ function STHighlighter:process_response(response, client, version)
local idx = 1
for _, token_edit in ipairs(token_edits) do
vim.list_extend(tokens, old_tokens, idx, token_edit.start)
vim.list_extend(tokens, token_edit.data)
if token_edit.data then
vim.list_extend(tokens, token_edit.data)
end
idx = token_edit.start + token_edit.deleteCount + 1
end
vim.list_extend(tokens, old_tokens, idx)
Expand Down
31 changes: 30 additions & 1 deletion test/functional/plugin/lsp/semantic_tokens_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,36 @@ int main()
extmark_added = true,
}
},
}
},
{
it = 'optional token_edit.data on deletion',
legend = [[{
"tokenTypes": [
"comment", "keyword", "operator", "string", "number", "regexp", "type", "class", "interface", "enum", "enumMember", "typeParameter", "function", "method", "property", "variable", "parameter", "module", "intrinsic", "selfParameter", "clsParameter", "magicFunction", "builtinConstant", "parenthesis", "curlybrace", "bracket", "colon", "semicolon", "arrow"
],
"tokenModifiers": [
"declaration", "static", "abstract", "async", "documentation", "typeHint", "typeHintComment", "readonly", "decorator", "builtin"
]
}]],
text1 = [[string = "test"]],
text2 = [[]],
response1 = [[{"data": [0, 0, 6, 15, 1], "resultId": "1"}]],
response2 = [[{"edits": [{ "start": 0, "deleteCount": 5 }], "resultId": "2"}]],
expected1 = {
{
line = 0,
modifiers = {
'declaration',
},
start_col = 0,
end_col = 6,
type = 'variable',
extmark_added = true,
}
},
expected2 = {
},
},
}) do
it(test.it, function()
exec_lua(create_server_definition)
Expand Down

0 comments on commit 8bcd433

Please sign in to comment.