Repository: neovim/neovim
File: runtime/lua/vim/lsp/diagnostic.lua (Lua)

Code before:
          character = diagnostic.col,
        },
        ['end'] = {
          line = diagnostic.end_lnum,
          character = diagnostic.end_col,
        },
      },
      severity = severity_vim_to_lsp(diagnostic.severity),
      message = diagnostic.message,
      source = diagnostic.source,
      code = diagnostic.code,
      tags = tags_vim_to_lsp(diagnostic),
    }
  end, diagnostics)
end

---@type table<integer, integer>
local client_push_namespaces = {}

---@type table<string, integer>
local client_pull_namespaces = {}

--- Get the diagnostic namespace associated with an LSP client |vim.diagnostic| for diagnostics
---
---@param client_id integer The id of the LSP client
---@param pull_id (boolean|string)? Pull diagnostics provider identifier
function M.get_namespace(client_id, pull_id)
  vim.validate('client_id', client_id, 'number')
  vim.validate('pull_id', pull_id, { 'boolean', 'string' }, true)

  local client = lsp.get_client_by_id(client_id)
  if pull_id then
    local provider_id = type(pull_id) == 'string' and pull_id or 'nil'
    local key = ('%d:%s'):format(client_id, provider_id)
    local name = ('nvim.lsp.%s.%d.%s'):format(
      client and client.name or 'unknown',
      client_id,
      provider_id
    )
    local ns = client_pull_namespaces[key]
    if not ns then
      ns = api.nvim_create_namespace(name)
      client_pull_namespaces[key] = ns
    end
    return ns
  end

  local ns = client_push_namespaces[client_id]
  if not ns then
    local name = ('nvim.lsp.%s.%d'):format(client and client.name or 'unknown', client_id)
    ns = api.nvim_create_namespace(name)

Review comment (suggestion):
```suggestion
---@param pull_id (boolean|string)? (default: nil) Pull diagnostics provider id
---               (indicates "pull" client), or `nil` for a "push" client.
```

Code after:
          character = diagnostic.col,
        },
        ['end'] = {
          line = diagnostic.end_lnum,
          character = diagnostic.end_col,
        },
      },
      severity = severity_vim_to_lsp(diagnostic.severity),
      message = diagnostic.message,
      source = diagnostic.source,
      code = diagnostic.code,
      tags = tags_vim_to_lsp(diagnostic),
    }
  end, diagnostics)
end

---@type table<integer, integer>
local client_push_namespaces = {}

---@type table<string, integer>
local client_pull_namespaces = {}

--- Get the diagnostic namespace associated with an LSP client |vim.diagnostic| for diagnostics
---
---@param client_id integer The id of the LSP client
---@param pull_id (boolean|string)? (default: nil) Pull diagnostics provider id
---               (indicates "pull" client), or `nil` for a "push" client.
function M.get_namespace(client_id, pull_id)
  vim.validate('client_id', client_id, 'number')
  vim.validate('pull_id', pull_id, { 'boolean', 'string' }, true)

  if type(pull_id) == 'boolean' then
    vim.deprecate('get_namespace(pull_id:boolean)', 'get_namespace(pull_id:string)', '0.14')
  end

  local client = lsp.get_client_by_id(client_id)
  if pull_id then
    local provider_id = type(pull_id) == 'string' and pull_id or 'nil'
    local key = ('%d:%s'):format(client_id, provider_id)
    local name = ('nvim.lsp.%s.%d.%s'):format(
      client and client.name or 'unknown',
      client_id,
      provider_id
    )
    local ns = client_pull_namespaces[key]
    if not ns then
      ns = api.nvim_create_namespace(name)
      client_pull_namespaces[key] = ns
    end
    return ns
  end