public function addMultilineCall()

in src/HackBuilder.hack [46:86]


  public function addMultilineCall(
    string $func_call_line,
    Traversable<string> $params,
    bool $include_close_statement = true,
  ): this {
    // Mark that the call is inside a function
    $this->setIsInsideFunction();
    // Get the max_length. Substracting 4 as Multiline call happens inside a
    // method.
    $max_length = $this->getMaxCodeLength() - 4;

    // Let's put everything in a single line
    $args = '('.Str\join($params, ', ').')';
    $composite_line = $func_call_line.$args;
    // Ignore suggested line breaks within individual args; otherwise we could
    // split in the middle of arguments rather than after each parameter.
    $composite_line_no_breaks =
      $func_call_line.\str_replace(self::DELIMITER, ' ', $args);
    if ($include_close_statement) {
      $composite_line = $composite_line.";\n";
      $composite_line_no_breaks = $composite_line_no_breaks.";\n";
    }
    $clone_builder = $this->getClone();
    $clone_builder->addWithSuggestedLineBreaks($composite_line_no_breaks);

    if (!self::checkIfLineIsTooLong($clone_builder->getCode(), $max_length)) {
      return $this->addWithSuggestedLineBreaks($composite_line);
    }

    $this
      ->addWithSuggestedLineBreaks($func_call_line.'(')
      ->newLine()
      ->indent()
      ->addLinesWithSuggestedLineBreaks(Vec\map($params, $line ==> $line.','))
      ->unindent()
      ->add(')');
    if ($include_close_statement) {
      $this->closeStatement();
    }
    return $this;
  }