diff options
author | tiagovla <30515389+tiagovla@users.noreply.github.com> | 2022-12-19 05:24:27 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-19 09:24:27 +0100 |
commit | f4d8e992bfcd6e9d0097b9d7a022060bd32f2069 (patch) | |
tree | 4147ac1d360ce9e54359f0ee3780ff361e886b61 | |
parent | a7332ba9b429f9676723eb88cffb2068f5a95c9b (diff) | |
download | rneovim-f4d8e992bfcd6e9d0097b9d7a022060bd32f2069.tar.gz rneovim-f4d8e992bfcd6e9d0097b9d7a022060bd32f2069.tar.bz2 rneovim-f4d8e992bfcd6e9d0097b9d7a022060bd32f2069.zip |
fix(lsp): token_edit.data might be null on deletion (#21462)
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 4 | ||||
-rw-r--r-- | test/functional/plugin/lsp/semantic_tokens_spec.lua | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index e14d3e51cd..48190b03e1 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -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) diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index e62a6f7086..547e34d12a 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -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) |