Skip to content

Auto-Formatting Breaks GDScript Lambda Function Indentation

Auto-Formatting Breaks GDScript Lambda Function Indentation

Environment

  • Godot Version: 4.4
  • OS: macOS

Issue Description

When using Command + Option + L to auto-format GDScript in Rider, the formatting breaks valid GDScript lambda function indentation inside .connect() calls.

Steps to Reproduce

  1. Write the following valid GDScript code in Rider:

    func _show_attack_options(abilities: Array[Ability]) -> void:
        attacks_vbox.show()
        clear_vbox(attacks_vbox)
    
        # Show attack menu if there are abilities
        if abilities.size() > 0:
            attacks_vbox.get_parent().show()
            for ability in abilities:
                var ability_button = Button.new()
                ability_button.text = ability.display_name + " (TP: " + str(ability.tp_cost) + ")"
                # Connect the button to show ability range and description
                ability_button.pressed.connect(func(): 
                    _on_ability_button_pressed(ability)
                    show_ability_info(ability)
                )
                attacks_vbox.add_child(ability_button)
  2. Press Command + Option + L to auto-format.

  3. The formatted result becomes invalid:

    func _show_attack_options(abilities: Array[Ability]) -> void:
        attacks_vbox.show()
        clear_vbox(attacks_vbox)
    
        # Show attack menu if there are abilities
        if abilities.size() > 0:
            attacks_vbox.get_parent().show()
            for ability in abilities:
                var ability_button = Button.new()
                ability_button.text = ability.display_name + " (TP: " + str(ability.tp_cost) + ")"
                # Connect the button to show ability range and description
                ability_button.pressed.connect(func():
                _on_ability_button_pressed(ability)
                show_ability_info(ability)
    )
    attacks_vbox.add_child(ability_button)

Expected Behavior

  • The formatter should preserve the correct indentation inside .connect(func(): ... ), ensuring the lambda function body remains properly indented.

Actual Behavior

  • The formatter incorrectly shifts indentation, breaking valid GDScript syntax.

Additional Information

  • This issue makes auto-formatting unusable for code using lambda functions inside .connect() calls.
  • The expected behavior aligns with Godot's official GDScript indentation rules.

Would appreciate any guidance or fixes for this issue. Let me know if more details are needed!