Skip to content

GDScript, auto formatting breaks indentation of commented lines #362

@0x01011970

Description

@0x01011970

We very often temporarily comment lines of code, and then uncomment them.

Unfortunately, when auto formatting the code, and then uncommenting the lines, the lines are not valid anymore and we need to manually restore indentations.

See this scenario :

Original code

func _ready() -> void:
	align_stuff()
	pass

Commented code (using hotkey ctrl + /)

func _ready() -> void:
#	align_stuff()
	pass

Auto format applied :

func _ready() -> void:
	#	align_stuff()
	pass

Now uncomment :

func _ready() -> void:
		align_stuff()
	pass

The originally correct indentation is lost. The code needs to be corrected instead of just having to uncomment.

On a one liner this can seem like not a problem, but on multiple lines of commented code it is more problematic.

During ideation and prototyping commenting & uncommenting code is quite important.

Is there anyway to completely disable auto-formatting commented code ?

Or maybe a workaround for this specific use case ?

One noteworthy behavior is that commenting adds a # at the beginning of the line and not at the beginning of the text.

This behavior is different than in PyCharm or the Godot editor, where the # character is added at the beginning of the text.

Using
// @Formatter:off
// @Formatter:on
would not be convenient for this use case

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions