How to use the gdtoolkit.formatter.expression_utils.is_expression_forcing_multiple_lines function in gdtoolkit

To help you get started, we’ve selected a few gdtoolkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
def _format_foldable(
    expression: Node, expression_context: ExpressionContext, context: Context
) -> Outcome:
    if is_expression_forcing_multiple_lines(expression):
        return _format_foldable_to_multiple_lines(
            expression, expression_context, context
        )
    single_line_expression = expression_to_str(expression)
    single_line_length = (
        context.indent
        + len(expression_context.prefix_string)
        + len(single_line_expression)
        + len(expression_context.suffix_string)
    )
    if single_line_length <= context.max_line_length:
        single_line = "{}{}{}{}".format(
            context.indent_string,
            expression_context.prefix_string,
            expression_to_str(expression),
            expression_context.suffix_string,
github Scony / godot-gdscript-toolkit / gdtoolkit / formatter / expression.py View on Github external
def format_comma_separated_list(
    a_list: List[Node], expression_context: ExpressionContext, context: Context
) -> FormattedLines:
    elements = [node for node in a_list if not is_any_comma(node)]
    child_context = context.create_child_context(expression_context.prefix_line)
    fake_expression = Tree("fake", a_list)
    multiline_mode_forced = is_expression_forcing_multiple_lines(fake_expression)
    if not multiline_mode_forced:
        strings_to_join = list(map(standalone_expression_to_str, elements))
        single_line_expression = "{}{}{}".format(
            expression_context.prefix_string,
            ", ".join(strings_to_join),
            expression_context.suffix_string,
        )
        single_line_length = len(single_line_expression) + context.indent
        if single_line_length <= context.max_line_length:
            return [
                (
                    expression_context.prefix_line,
                    "{}{}".format(context.indent_string, single_line_expression),
                )
            ]
        indented_single_line_expression = ", ".join(strings_to_join)