Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ impl Formatter {
}

self.tree = self.parser.parse(&self.content, Some(&self.tree)).unwrap();

// The reorder query uses (_) which silently skips ERROR nodes, so any
// top-level declaration wrapped in an ERROR node will be lost from the
// output. Bail out instead of producing a file with missing functions.
if self.tree.root_node().has_error() {
eprintln!(
"Warning: Parse errors detected, skipping code reordering to avoid data loss."
);
return Ok(self);
}
match crate::reorder::reorder_gdscript_elements(&self.tree, &self.content) {
Ok(reordered) => {
self.content = reordered;
Expand Down
16 changes: 16 additions & 0 deletions tests/reorder_code/expected/issue_233.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func jump(force: float) -> void:
self.velocity.y = force
is_shooting = false
func shoot() -> void:
var pos: Vector2 = muzzle_right.global_position
var direction: Vector2 = Vector2.RIGHT
if is_facing_left:
pos = muzzle_left.global_position
direction = Vector2.LEFT

var lazer: Projectile = Instancer.instance_scene_to_level(Instancer.laster_scene, pos) as Projectile
if lazer != null:
lazer.launch(direction, lazer_speed)

is_shooting = false
var yozora: bool.
18 changes: 18 additions & 0 deletions tests/reorder_code/input/issue_233.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
func jump(force: float) -> void:
self.velocity.y = force
is_shooting = false


func shoot() -> void:
var pos: Vector2 = muzzle_right.global_position
var direction: Vector2 = Vector2.RIGHT
if is_facing_left:
pos = muzzle_left.global_position
direction = Vector2.LEFT

var lazer: Projectile = Instancer.instance_scene_to_level(Instancer.laster_scene, pos) as Projectile
if lazer != null:
lazer.launch(direction, lazer_speed)

is_shooting = false
var yozora: bool.