class Rufo::Formatter

def visit_call_at_paren(node, args)

def visit_call_at_paren(node, args)
  consume_token :on_lparen
  # If there's a trailing comma then comes [:arg_paren, args],
  # which is a bit unexpected, so we fix it
  if args[1].is_a?(Array) && args[1][0].is_a?(Array)
    args_node = [:args_add_block, args[1], false]
  else
    args_node = args[1]
  end
  if args_node
    skip_space
    needs_trailing_newline = newline? || comment?
    if needs_trailing_newline && (call_info = @line_to_call_info[@line])
      call_info << true
    end
    want_trailing_comma = true
    # Check if there's a block arg and if the call ends with hash key/values
    if args_node[0] == :args_add_block
      _, args, block_arg = args_node
      want_trailing_comma = !block_arg
      if args.is_a?(Array) && (last_arg = args.last) && last_arg.is_a?(Array) &&
         last_arg[0].is_a?(Symbol) && last_arg[0] != :bare_assoc_hash
        want_trailing_comma = false
      end
    end
    push_call(node) do
      visit args_node
      skip_space
    end
    found_comma = comma?
    heredoc_needs_newline = true
    if found_comma
      if needs_trailing_newline
        write "," if trailing_commas && !block_arg
        next_token
        heredoc_needs_newline = !newline?
        indent(next_indent) do
          consume_end_of_line
        end
        write_indent
      else
        next_token
        skip_space
      end
    end
    if newline? || comment?
      if needs_trailing_newline && !@last_was_heredoc
        write "," if trailing_commas && want_trailing_comma
        indent(next_indent) do
          consume_end_of_line
        end
        write_indent
      else
        skip_space_or_newline
      end
    else
      if needs_trailing_newline && !found_comma
        write "," if trailing_commas && want_trailing_comma && !@last_was_heredoc
        consume_end_of_line
        write_indent
      end
    end
  else
    skip_space_or_newline
  end
  # If the closing parentheses matches the indent of the first parameter,
  # keep it like that. Otherwise dedent.
  if call_info && call_info[1] != current_token_column
    call_info << @line
  end
  if @last_was_heredoc && heredoc_needs_newline
    write_line
    write_indent
  end
  consume_token :on_rparen
end