Skip to content

Commit 94fcd06

Browse files
committed
Fix annotations with parameters always wrapping in variables
1 parent c6dff41 commit 94fcd06

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/formatter.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,14 @@ fn emit_inter_child_separator(
22972297
return;
22982298
}
22992299

2300+
// Variable annotations stay inline even when they have arguments. Keeping
2301+
// them inline also ensures that sibling and nested annotation AST shapes
2302+
// produce the same output.
2303+
if previous_kind == GDScriptNodeKind::Annotations && parent_kind == GDScriptNodeKind::Variable {
2304+
render_elements.push(RenderElement::Space);
2305+
return;
2306+
}
2307+
23002308
// If the previous child is an annotations node and any of the annotations
23012309
// has arguments (e.g. @rpc("any_peer")), keep the annotation on its own line.
23022310
if previous_kind == GDScriptNodeKind::Annotations {

src/reorder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum DeclarationKind {
5959
OnReadyVariable, // 10
6060
Method, // 11: functions (sub-sorted by MethodType)
6161
InnerClass, // 12
62-
Unknown, // 255
62+
Unknown = 255, // 255
6363
}
6464

6565
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]

tests/expected/variable_annotations.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
@export var max_health := 5
33
@onready var health := max_health
44
@onready var health := max_health
5+
@export_range(10.0, 200.0) var jump_height := 50.0
6+
@export_range(0.1, 1.5) var jump_time_to_peak := 0.37
57

68
@export_group("my group")
79
@export var v = 1

tests/input/variable_annotations.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
@onready var health:=max_health
44
@onready
55
var health:=max_health
6+
@export_range(10.0, 200.0) var jump_height:=50.0
7+
@export_range(0.1, 1.5)
8+
var jump_time_to_peak:=0.37
69

710
@export_group("my group")
811
@export var v = 1

0 commit comments

Comments
 (0)