Scony / godot-gdscript-toolkit

Independent set of GDScript tools - parser, linter, formatter, and more
MIT License
944 stars 65 forks source link

A comment about formatting, gdscript #310

Closed wyattbiker closed 2 months ago

wyattbiker commented 2 months ago

I use lots of lambdas. I understand they are not easy to parse yet for the formatting.

My need actually is less about formatting and is more about space between operands and operators. The Godot editor makes the whole indentation and even continuation easier because of the language itself, but the spacing is extra work.

Is there some simple way I can run this or another formatter that does just that. So for example be able to just add spaces around operators and assignments to code like this, but not change my code indents in any way:


    var dummy:=Container.new()
    dummy.name="Dummy"
    return dummy

    this.mouse_exited.connect(func():
        t2_close=Timer.new()
        this.add_child(t2_close)
        t2_close.name="Some Name"
        t2_close.one_shot=true
        t2_close.timeout.connect(func():
            if !tooltip_entered:
                ctrl.hide()
                ctrl.queue_free()
            ,CONNECT_ONE_SHOT)
        t2_close.start(t2_close_delay)
        ,CONNECT_ONE_SHOT)

func calculate_position():
    ctrl.position+=get_local_mouse_position()
    if ctrl.position.x+ctrl.size.x>get_tree().get_current_scene().size.x:
        ctrl.position.x+=get_local_mouse_position().x-ctrl.size.x
    if ctrl.position.y+ ctrl.size.yget_tree().get_current_scene().size.y:
        ctrl.position.y+=get_local_mouse_position().y-ctrl.size.y
    return
Scony commented 2 months ago

That would require some other formatter. Gdformat parses gdscript to parse tree and then reconstructs your entire code from scratch. With that, there are no guarantees your style will be preserved.