Repository: neovim/neovim
File: test/functional/plugin/lsp/semantic_tokens_spec.lua (Lua)

Code before:
        end)
      )

      insert(text)

      screen:expect {
        grid = [[
        #include <iostream>                     |
                                                |
        int main()                              |
        {                                       |
            int x;                              |
        #ifdef __cplusplus                      |
            std::cout << x << "\n";             |
        #else                                   |
            printf("%d\n", x);                  |
        #endif                                  |
        }                                       |
        ^}                                       |
        {1:~                                       }|*3
                                                |
      ]],
      }
    end)

    it('reset active request after receiving error responses from the server', function()
      local error = { code = -32801, message = 'Content modified' }
      exec_lua(function()
        _G.server2 = _G._create_server({
          capabilities = {
            semanticTokensProvider = {
              full = { delta = false },
            },
          },
          handlers = {
            -- There is same logic for handling nil responses and error responses,
            -- so keep responses not nil.
            --
            -- if an error response was not be handled, this test will hang on here.
            --- @param callback function
            ['textDocument/semanticTokens/full'] = function(_, _, callback)
              callback(error, vim.fn.json_decode(response))
            end,
            --- @param callback function
            ['textDocument/semanticTokens/full/delta'] = function(_, _, callback)
              callback(error, vim.fn.json_decode(response))
            end,
          },
        })
        return vim.lsp.start({ name = 'dummy', cmd = _G.server2.cmd })
      end)

Review comment (suggestion):
```suggestion
    it('resets active request after receiving error response from the server', function()
```

Code after:
        end)
      )

      insert(text)

      screen:expect {
        grid = [[
        #include <iostream>                     |
                                                |
        int main()                              |
        {                                       |
            int x;                              |
        #ifdef __cplusplus                      |
            std::cout << x << "\n";             |
        #else                                   |
            printf("%d\n", x);                  |
        #endif                                  |
        }                                       |
        ^}                                       |
        {1:~                                       }|*3
                                                |
      ]],
      }
    end)

    it('resets active request after receiving error responses from the server', function()
      local error = { code = -32801, message = 'Content modified' }
      exec_lua(function()
        _G.server2 = _G._create_server({
          capabilities = {
            semanticTokensProvider = {
              full = { delta = false },
            },
          },
          handlers = {
            -- There is same logic for handling nil responses and error responses,
            -- so keep responses not nil.
            --
            -- if an error response was not be handled, this test will hang on here.
            --- @param callback function
            ['textDocument/semanticTokens/full'] = function(_, _, callback)
              callback(error, vim.fn.json_decode(response))
            end,
            --- @param callback function
            ['textDocument/semanticTokens/full/delta'] = function(_, _, callback)
              callback(error, vim.fn.json_decode(response))
            end,
          },
        })
        return vim.lsp.start({ name = 'dummy', cmd = _G.server2.cmd })
      end)