Repository navigation
Formatter on/off comments within a code block can prevent the entire code block from wrapping #350
Description
Activity
This might be an issue that was solved in the latest release. line length of 80 chars:
➜ GDScript-formatter on main [$?] 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 on main [$?] 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?
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|onblock 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 !)
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.
- 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 - added a commit that references this issue
on Sep 21, 2026
Sample code
With line_width = 80
With line_width = 120
Given the warning
max-line-length:warning: Line is too long. Found 166 characters, maximum allowed is 120