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

Code before:
        },
      },
      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)
    client_push_namespaces[client_id] = ns
  end
  return ns
end


Review comment (suggestion):
let's give ourselves a reminder to update the type decl later. 

note: using version=0.14 avoids bothering people until after 0.12 is released.

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

Code after:
        },
      },
      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

  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)