Repository: neovim/neovim
File: src/gen/gen_lsp.lua (Lua)

Code before:
  end

  do -- registrationMethods
    local found = {} --- @type table<string, boolean>
    vim.list_extend(output, {
      '',
      '-- Generated by gen_lsp.lua, keep at end of file.',
      '--- LSP registration methods',
      '---@alias vim.lsp.protocol.Method.Registration',
    })
    for _, item in ipairs(all) do
      if item.registrationMethod and not found[item.registrationMethod] then
        vim.list_extend(output, {
          ("--- | '%s'"):format(item.registrationMethod or item.method),
        })
        found[item.registrationMethod or item.method] = true
      end
    end
  end

  do -- capabilities
    vim.list_extend(output, {
      '',
      '-- stylua: ignore start',
      '-- Generated by gen_lsp.lua, keep at end of file.',
      '--- Maps method names to the required client capability',
      'protocol._provider_to_client_registration = {',
    })

    local found = {} --- @type table<string, boolean>
    for _, item in ipairs(all) do
      local base_provider = item.serverCapability and item.serverCapability:match('^[^%.]+')
      if item.registrationOptions and not found[base_provider] and item.clientCapability then
        if item.clientCapability == item.serverCapability then
          base_provider = nil
        end
        output[#output + 1] = ("  ['%s'] = { %s },"):format(
          base_provider or item.method,
          "'" .. item.clientCapability:gsub('%.', "', '") .. "'"
        )
        found[base_provider or item.method] = true
      end
    end

    output[#output + 1] = '}'
    output[#output + 1] = '-- stylua: ignore end'

    vim.list_extend(output, {
      '',
      '-- stylua: ignore start',
      '-- Generated by gen_lsp.lua, keep at end of file.',

Review comment (suggestion):
```suggestion
      '--- Maps method names to the required client capability',
      '--- TODO: also has workspace/* items because spec lacks a top-level "workspaceProvider"
```

Code after:
  end

  do -- registrationMethods
    local found = {} --- @type table<string, boolean>
    vim.list_extend(output, {
      '',
      '-- Generated by gen_lsp.lua, keep at end of file.',
      '--- LSP registration methods',
      '---@alias vim.lsp.protocol.Method.Registration',
    })
    for _, item in ipairs(all) do
      if item.registrationMethod and not found[item.registrationMethod] then
        vim.list_extend(output, {
          ("--- | '%s'"):format(item.registrationMethod or item.method),
        })
        found[item.registrationMethod or item.method] = true
      end
    end
  end

  do -- capabilities
    vim.list_extend(output, {
      '',
      '-- stylua: ignore start',
      '-- Generated by gen_lsp.lua, keep at end of file.',
      '--- Maps method names to the required client capability',
      '---TODO: also has workspace/* items because spec lacks a top-level "workspaceProvider"',
      'protocol._provider_to_client_registration = {',
    })

    local providers = {} --- @type table<string, string>
    for _, item in ipairs(all) do
      local base_provider = item.serverCapability and item.serverCapability:match('^[^%.]+')
      if item.registrationOptions and not providers[base_provider] and item.clientCapability then
        if item.clientCapability == item.serverCapability then
          base_provider = nil
        end
        local key = base_provider or item.method
        providers[key] = item.clientCapability
      end
    end

    ---@type { provider: string, path : string }[]
    local found_entries = {}
    for key, value in pairs(providers) do
      found_entries[#found_entries + 1] = { provider = key, path = value }
    end
    table.sort(found_entries, function(a, b)
      return a.provider < b.provider
    end)
    for _, entry in ipairs(found_entries) do