class SyntaxTree::CallNode

def format(q)

def format(q)
  if receiver
    # If we're at the top of a call chain, then we're going to do some
    # specialized printing in case we can print it nicely. We _only_ do this
    # at the top of the chain to avoid weird recursion issues.
    if CallChainFormatter.chained?(receiver) &&
         !CallChainFormatter.chained?(q.parent)
      q.group do
        q
          .if_break { CallChainFormatter.new(self).format(q) }
          .if_flat { format_contents(q) }
      end
    else
      format_contents(q)
    end
  else
    q.format(message)
    # Note that this explicitly leaves parentheses in place even if they are
    # empty. There are two reasons we would need to do this. The first is if
    # we're calling something that looks like a constant, as in:
    #
    #     Foo()
    #
    # In this case if we remove the parentheses then this becomes a constant
    # reference and not a method call. The second is if we're calling a
    # method that is the same name as a local variable that is in scope, as
    # in:
    #
    #     foo = foo()
    #
    # In this case we have to keep the parentheses or else it treats this
    # like assigning nil to the local variable. Note that we could attempt
    # to be smarter about this by tracking the local variables that are in
    # scope, but for now it's simpler and more efficient to just leave the
    # parentheses in place.
    q.format(arguments) if arguments
  end
end