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

Code before:
      end)
    end)

    it('adds diagnostics to vim.diagnostics', function()
      local diags = exec_lua(function()
        vim.lsp.diagnostic.on_diagnostic(nil, {
          kind = 'full',
          items = {
            _G.make_error('Pull Diagnostic', 4, 4, 4, 4),
          },
        }, {
          params = {
            textDocument = { uri = fake_uri },
          },
          uri = fake_uri,
          client_id = client_id,
          bufnr = diagnostic_bufnr,
        }, {})

        return vim.diagnostic.get(diagnostic_bufnr)
      end)
      eq(1, #diags)
      eq('Pull Diagnostic', diags[1].message)
    end)

    it('does not clear push diagnostics when pull diagnostics are empty', function()
      local push_ns_count, pull_ns_count, all_diags_count, push_ns, pull_ns = exec_lua(function()
        vim.lsp.diagnostic.on_publish_diagnostics(nil, {
          uri = fake_uri,
          diagnostics = {
            _G.make_error('Push Diagnostic', 0, 0, 0, 0),
          },
        }, { client_id = client_id })

        vim.lsp.diagnostic.on_diagnostic(nil, {
          kind = 'full',
          items = {},
        }, {
          params = {
            textDocument = { uri = fake_uri },
          },
          uri = fake_uri,
          client_id = client_id,
          bufnr = diagnostic_bufnr,
        }, {})

        local push_ns = vim.lsp.diagnostic.get_namespace(client_id, false)
        local pull_ns = vim.lsp.diagnostic.get_namespace(client_id, true)

        return #vim.diagnostic.get(diagnostic_bufnr, { namespace = push_ns }),
          #vim.diagnostic.get(diagnostic_bufnr, { namespace = pull_ns }),

Review comment (suggestion):
```suggestion
    it('preserves push diagnostics when pull diagnostics are empty', function()
```

Code after:
      end)
    end)

    it('adds diagnostics to vim.diagnostics', function()
      local diags = exec_lua(function()
        vim.lsp.diagnostic.on_diagnostic(nil, {
          kind = 'full',
          items = {
            _G.make_error('Pull Diagnostic', 4, 4, 4, 4),
          },
        }, {
          params = {
            textDocument = { uri = fake_uri },
          },
          uri = fake_uri,
          client_id = client_id,
          bufnr = diagnostic_bufnr,
        }, {})

        return vim.diagnostic.get(diagnostic_bufnr)
      end)
      eq(1, #diags)
      eq('Pull Diagnostic', diags[1].message)
    end)

    it('preserves push diagnostics when pull diagnostics are empty', function()
      local push_ns_count, pull_ns_count, all_diags_count, push_ns, pull_ns = exec_lua(function()
        vim.lsp.diagnostic.on_publish_diagnostics(nil, {
          uri = fake_uri,
          diagnostics = {
            _G.make_error('Push Diagnostic', 0, 0, 0, 0),
          },
        }, { client_id = client_id })

        vim.lsp.diagnostic.on_diagnostic(nil, {
          kind = 'full',
          items = {},
        }, {
          params = {
            textDocument = { uri = fake_uri },
          },
          uri = fake_uri,
          client_id = client_id,
          bufnr = diagnostic_bufnr,
        }, {})

        local push_ns = vim.lsp.diagnostic.get_namespace(client_id, false)
        local pull_ns = vim.lsp.diagnostic.get_namespace(client_id, true)

        return #vim.diagnostic.get(diagnostic_bufnr, { namespace = push_ns }),
          #vim.diagnostic.get(diagnostic_bufnr, { namespace = pull_ns }),