fix(lsp): ignore null responses for semanticTokens request (#21364)

The spec indicates that the response may be `null`, but it doesn't
really say what a `null` response means. Since neovim raises an error if
the response is `null`, I figured that ignoring it would be the safest
bet.

Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
This commit is contained in:
fsouza
2022-12-10 06:16:33 -05:00
committed by GitHub
parent f96fb23de6
commit 6d37d8cb17
3 changed files with 75 additions and 3 deletions

View File

@@ -304,6 +304,11 @@ function STHighlighter:process_response(response, client, version)
-- reset active request
state.active_request = {}
-- skip nil responses
if response == nil then
return
end
-- if we have a response to a delta request, update the state of our tokens
-- appropriately. if it's a full response, just use that
local tokens

View File

@@ -36,9 +36,7 @@ M.create_server_definition = [[
local handler = handlers[method]
if handler then
local response, err = handler(method, params)
if response then
callback(err, response)
end
callback(err, response)
elseif method == 'initialize' then
callback(nil, {
capabilities = opts.capabilities or {}

View File

@@ -415,6 +415,75 @@ describe('semantic token highlighting', function()
]], unchanged = true }
end)
it('ignores null responses from the server', function()
exec_lua([[
local legend, response, edit_response = ...
server2 = _create_server({
capabilities = {
semanticTokensProvider = {
full = { delta = false },
},
},
handlers = {
['textDocument/semanticTokens/full'] = function()
return nil
end,
['textDocument/semanticTokens/full/delta'] = function()
return nil
end,
}
})
bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_buf(0, bufnr)
client_id = vim.lsp.start({ name = 'dummy', cmd = server2.cmd })
]])
eq(true, exec_lua("return vim.lsp.buf_is_attached(bufnr, client_id)"))
insert(text)
screen:expect { grid = [[
#include <iostream> |
|
int main() |
{ |
int x; |
#ifdef __cplusplus |
std::cout << x << "\n"; |
#else |
printf("%d\n", x); |
#endif |
} |
^} |
{1:~ }|
{1:~ }|
{1:~ }|
|
]] }
exec_lua([[
vim.lsp.semantic_tokens.start(bufnr, client_id)
]])
screen:expect { grid = [[
#include <iostream> |
|
int main() |
{ |
int x; |
#ifdef __cplusplus |
std::cout << x << "\n"; |
#else |
printf("%d\n", x); |
#endif |
} |
^} |
{1:~ }|
{1:~ }|
{1:~ }|
|
]], unchanged = true }
end)
it('does not send delta requests if not supported by server', function()
exec_lua([[
local legend, response, edit_response = ...