Skip to content

Formatter on/off comments within a code block can prevent the entire code block from wrapping #350

Description

@blabdouze

Sample code

func add_river_quad(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y: float, v: float, reversed: bool) -> void:
	add_river_quad_two_heights(v1, v2, v3, v4, y, y, v, reversed)


func add_river_quad_two_heights(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y1: float, y2: float, v: float, reversed: bool) -> void:
       pass

With line_width = 80

# Ok
func add_river_quad(
	v1: Vector3,
	v2: Vector3,
	v3: Vector3,
	v4: Vector3,
	y: float,
	v: float,
	reversed: bool,
) -> void:
	add_river_quad_two_heights(v1, v2, v3, v4, y, y, v, reversed)

# Not ok
func add_river_quad_two_heights(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y1: float, y2: float, v: float, reversed: bool) -> void:
	pass

With line_width = 120

# Is OK
func add_river_quad(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y: float, v: float, reversed: bool) -> void:
	add_river_quad_two_heights(v1, v2, v3, v4, y, y, v, reversed)

# Still not split into multiple lines
func add_river_quad_two_heights(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y1: float, y2: float, v: float, reversed: bool) -> void:

Given the warning max-line-length:warning: Line is too long. Found 166 characters, maximum allowed is 120

Activity

  1. added theissue type on Sep 14, 2026
  2. NathanLovato commented on Sep 15, 2026

    @NathanLovato
    Contributor

    This might be an issue that was solved in the latest release. line length of 80 chars:

    ➜ GDScript-formatter onmain [$?]  cargo run -- --max-line-length 80 --stdout tmp.gd
        Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
         Running `target/debug/gdscript-formatter --max-line-length 80 --stdout tmp.gd`
    func add_river_quad(
    	v1: Vector3,
    	v2: Vector3,
    	v3: Vector3,
    	v4: Vector3,
    	y: float,
    	v: float,
    	reversed: bool,
    ) -> void:
    	add_river_quad_two_heights(v1, v2, v3, v4, y, y, v, reversed)
    
    
    func add_river_quad_two_heights(
    	v1: Vector3,
    	v2: Vector3,
    	v3: Vector3,
    	v4: Vector3,
    	y1: float,
    	y2: float,
    	v: float,
    	reversed: bool,
    ) -> void:
    	pass

    Max line length at 120:

    ➜ GDScript-formatter onmain [$?]  cargo run -- --max-line-length 120 --stdout tmp.gd
        Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
         Running `target/debug/gdscript-formatter --max-line-length 120 --stdout tmp.gd`
    func add_river_quad(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y: float, v: float, reversed: bool) -> void:
    	add_river_quad_two_heights(v1, v2, v3, v4, y, y, v, reversed)
    
    
    func add_river_quad_two_heights(
    	v1: Vector3,
    	v2: Vector3,
    	v3: Vector3,
    	v4: Vector3,
    	y1: float,
    	y2: float,
    	v: float,
    	reversed: bool,
    ) -> void:
    	pass

    I also tried with the max line length at 140, 139, 116, and 115. to verify wrapping happened right at the expected line lengths for each function definition.

    Could you please give it a try with version 0.26 if you haven't already?

  3. blabdouze commented on Sep 15, 2026

    @blabdouze
    Author

    My bad, the issue was not there something has gone wrong with my sample.

    It doesn't get reformated if the function has # fmt : off|on block inside it :

    func add_river_quad_two_heights(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y1: float, y2: float, v: float, reversed: bool) -> void:
    	pass
    
    func add_river_quad_two_heights_2(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y1: float, y2: float, v: float, reversed: bool) -> void:
    	v1.y = 50
    	# fmt : off 
    	pass
    	# fmt : on
    
    

    Will result in :

    func add_river_quad_two_heights(
    	v1: Vector3,
    	v2: Vector3,
    	v3: Vector3,
    	v4: Vector3,
    	y1: float,
    	y2: float,
    	v: float,
    	reversed: bool,
    ) -> void:
    	pass
    
    
    func add_river_quad_two_heights_2(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3, y1: float, y2: float, v: float, reversed: bool) -> void:
    	v1.y = 50
    	# fmt : off 
    	pass
    	# fmt : on

    Sorry my sample was wrong, maybe I tested it against an older version ahah. But this is happening in 0.26.1 (thanks for the fix & reactivity !)

  4. NathanLovato commented on Sep 16, 2026

    @NathanLovato
    Contributor

    Ah the thing to disable and enable formatting is a more complicated one. It's happening because the checks for this are still not where they need to be.

    To avoid bugs/edge cases, the formatter needs to be aware of where a region for turning off formatting is and not format the code inside the region, but still format all the code around it with the awareness of what the unformatted region contains.

    And so, right now, in some cases, if in a given context there's a formatter off region on just one line or a small amount of code, for safety, the formatter kinda bails for that code element. Notably, the complexity stems from the fact that these formatter on/off could be placed anywhere, like across different code constructs (e.g. from the middle of a function call's arguments to beyond the end of the function call, in the middle of a dictionary, etc.). But in the parsed structure of the code, which is a tree, this means it's spanning across nested tree branches that are handled in different parts of the codebase that don't communicate with each other.

    Anyway, long story short, I think it's time to refactor the formatter and keep the context of disabled regions around while walking the code. I thought about having some context structure from the start, but could pretty much get the entire formatting working without that. But not with this feature.

  5. changed the title [-]Very long functions args are not splited correctly[/-] [+]Formatter on/off comments within a code block can prevent the entire code block from wrapping[/+] on Sep 16, 2026
  6. self-assigned this
    on Sep 16, 2026
  7. added a commit that references this issue on Sep 21, 2026
    7f7474e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions