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

Code before:
  config = config and vim.deepcopy(config) or {}
  config.focus_id = method

  lsp.buf_request_all(0, method, client_positional_params(), function(results, ctx)
    if api.nvim_get_current_buf() ~= ctx.bufnr then
      -- Ignore result since buffer changed. This happens for slow language servers.
      return
    end

    local signatures, active_signature = process_signature_help_results(results)

    if not next(signatures) then
      if config.silent ~= true then
        print('No signature help available')
      end
      return
    end

    local ft = vim.bo[ctx.bufnr].filetype
    local total = #signatures
    local can_cycle = total > 1 and config.focusable ~= false
    local idx = active_signature - 1

    local existing_cycle_sig_mapping = nil
    for _, map in ipairs(vim.api.nvim_get_keymap('n')) do
      if map.rhs == '<Plug>(nvim.lsp.ctrl-s)' then
        existing_cycle_sig_mapping = map.lhs
      end
    end

    --- @param update_win? integer
    local function show_signature(update_win)
      idx = (idx % total) + 1
      local client, result = signatures[idx][1], signatures[idx][2]
      --- @type string[]?
      local triggers =
        vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters')
      local lines, hl =
        util.convert_signature_help_to_markdown_lines({ signatures = { result } }, ft, triggers)
      if not lines then
        return
      end

      local sfx = total > 1
          and string.format(
            ' (%d/%d)%s',
            idx,
            total,
            can_cycle and string.format(' (%s to cycle)', existing_cycle_sig_mapping or '<C-s>')
              or ''
          )

Review comment (suggestion):
should not need to iterate through all normal-mode mappings. see if `vim.fn.maparg()` provides a way to get what you want

Code after:
  config = config and vim.deepcopy(config) or {}
  config.focus_id = method

  lsp.buf_request_all(0, method, client_positional_params(), function(results, ctx)
    if api.nvim_get_current_buf() ~= ctx.bufnr then
      -- Ignore result since buffer changed. This happens for slow language servers.
      return
    end

    local signatures, active_signature = process_signature_help_results(results)

    if not next(signatures) then
      if config.silent ~= true then
        print('No signature help available')
      end
      return
    end

    local ft = vim.bo[ctx.bufnr].filetype
    local total = #signatures
    local can_cycle = total > 1 and config.focusable ~= false
    local idx = active_signature - 1

    --- @param update_win? integer
    local function show_signature(update_win)
      idx = (idx % total) + 1
      local client, result = signatures[idx][1], signatures[idx][2]
      --- @type string[]?
      local triggers =
        vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters')
      local lines, hl =
        util.convert_signature_help_to_markdown_lines({ signatures = { result } }, ft, triggers)
      if not lines then
        return
      end

      local sfx = total > 1
          and string.format(' (%d/%d)%s', idx, total, can_cycle and ' (<C-s> to cycle)' or '')
        or ''
      local title = string.format('Signature Help: %s%s', client.name, sfx)
      if config.border then
        config.title = title
      else
        table.insert(lines, 1, '# ' .. title)
        if hl then
          hl[1] = hl[1] + 1
          hl[3] = hl[3] + 1
        end
      end

      config._update_win = update_win