diff options
author | fsouza <108725+fsouza@users.noreply.github.com> | 2022-12-10 06:16:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-10 12:16:33 +0100 |
commit | 6d37d8cb17390419360c1459607beac2d93183b6 (patch) | |
tree | 52c6019660731c79917529a82950579fca9b628c | |
parent | f96fb23de62f9539bf254cc1a4e99d1da8b71994 (diff) | |
download | rneovim-6d37d8cb17390419360c1459607beac2d93183b6.tar.gz rneovim-6d37d8cb17390419360c1459607beac2d93183b6.tar.bz2 rneovim-6d37d8cb17390419360c1459607beac2d93183b6.zip |
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>
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 5 | ||||
-rw-r--r-- | test/functional/plugin/lsp/helpers.lua | 4 | ||||
-rw-r--r-- | test/functional/plugin/lsp/semantic_tokens_spec.lua | 69 |
3 files changed, 75 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 66e656abb6..83b414bf87 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -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 diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 1363ab894d..028ccb9e2c 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -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 {} diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 3aeb4b264b..7a5494e9a5 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -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 = ... |