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

Code before:
        'squidward',
        exec_lua(function()
          vim.lsp.diagnostic.on_diagnostic(nil, {
            kind = 'unchanged',
            resultId = 'squidward',
          }, {
            method = vim.lsp.protocol.Methods.textDocument_diagnostic,
            params = {
              textDocument = { uri = fake_uri },
            },
            client_id = client_id,
            bufnr = diagnostic_bufnr,
          })
          vim.api.nvim_exec_autocmds('LspNotify', {
            buffer = diagnostic_bufnr,
            data = {
              method = vim.lsp.protocol.Methods.textDocument_didChange,
              client_id = client_id,
            },
          })
          return _G.params.previousResultId
        end)
      )
    end)

    it('handles related document diagnostics', function()
      local fake_uri_2 = 'file:///fake/uri2'
      ---@type vim.Diagnostic[], vim.Diagnostic[], string?
      local diagnostics, related_diagnostics, relatedPreviousResultId = exec_lua(function()
        local second_buf = vim.uri_to_bufnr(fake_uri_2)
        vim.fn.bufload(second_buf)

        -- Attach the client to both buffers.
        vim.api.nvim_win_set_buf(0, second_buf)
        vim.lsp.start({ name = 'dummy', cmd = _G.server.cmd })

        vim.lsp.diagnostic.on_diagnostic(nil, {
          kind = 'full',
          relatedDocuments = {
            [fake_uri_2] = {
              kind = 'full',
              resultId = 'spongebob',
              items = {
                {
                  range = _G.make_range(4, 4, 4, 4),
                  message = 'related bad!',
                },
              },
            },
          },
          items = {},

Review comment (suggestion):
helpful for searching if we use the literal protocol name
```suggestion
    it('handles relatedDocuments diagnostics', function()
```

Code after:
        'squidward',
        exec_lua(function()
          vim.lsp.diagnostic.on_diagnostic(nil, {
            kind = 'unchanged',
            resultId = 'squidward',
          }, {
            method = vim.lsp.protocol.Methods.textDocument_diagnostic,
            params = {
              textDocument = { uri = fake_uri },
            },
            client_id = client_id,
            bufnr = diagnostic_bufnr,
          })
          vim.api.nvim_exec_autocmds('LspNotify', {
            buffer = diagnostic_bufnr,
            data = {
              method = vim.lsp.protocol.Methods.textDocument_didChange,
              client_id = client_id,
            },
          })
          return _G.params.previousResultId
        end)
      )
    end)

    it('handles relatedDocuments diagnostics', function()
      local fake_uri_2 = 'file:///fake/uri2'
      ---@type vim.Diagnostic[], vim.Diagnostic[], string?
      local diagnostics, related_diagnostics, relatedPreviousResultId = exec_lua(function()
        local second_buf = vim.uri_to_bufnr(fake_uri_2)
        vim.fn.bufload(second_buf)

        -- Attach the client to both buffers.
        vim.api.nvim_win_set_buf(0, second_buf)
        vim.lsp.start({ name = 'dummy', cmd = _G.server.cmd })

        vim.lsp.diagnostic.on_diagnostic(nil, {
          kind = 'full',
          relatedDocuments = {
            [fake_uri_2] = {
              kind = 'full',
              resultId = 'spongebob',
              items = {
                {
                  range = _G.make_range(4, 4, 4, 4),
                  message = 'related bad!',
                },
              },
            },
          },
          items = {},