Skip to content

Commit 3f19052

Browse files
committed
Fix case where export_category would merge with next annotated variable
1 parent 530cff8 commit 3f19052

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This file documents the changes made to the formatter with each release.
44

5+
## Unreleased
6+
7+
### Fixed
8+
9+
- Fix `@export_category` annotations sometimes wrapping with variables on a single line (#358)
10+
511
## Release 0.26.2 (2026-09-20)
612

713
### Fixed

‎src/formatter.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::parser::{ParseInput, RegionWithDisabledFormatting};
1616
use crate::renderer::{GroupParentFit, RangeRenderElement, RangeSourceBytes, RenderElement};
1717
use crate::reorder;
1818
use crate::reorder::DeclarationKind;
19+
use crate::shared_utils::should_annotation_be_inline;
1920

2021
fn begin_indent(render_elements: &mut Vec<RenderElement>, level: u16) -> usize {
2122
let index = render_elements.len();
@@ -209,9 +210,7 @@ fn is_annotation_that_should_stay_inline(source: &str, annotation: tree_sitter::
209210
&& GDScriptNodeKind::get_kind_from_ast_node(child) == GDScriptNodeKind::Identifier
210211
{
211212
let annotation_name = &source[child.start_byte()..child.end_byte()];
212-
return (annotation_name.starts_with("export")
213-
&& !["export_group", "export_subgroup"].contains(&annotation_name))
214-
|| annotation_name == "onready";
213+
return should_annotation_be_inline(annotation_name);
215214
}
216215
child_index += 1;
217216
}

‎src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod node_kind;
2121
pub mod parser;
2222
pub mod renderer;
2323
pub mod reorder;
24+
pub mod shared_utils;
2425
pub mod verify_structure;
2526

2627
pub use renderer::{PrinterConfiguration, RenderElement};

‎src/reorder.rs‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! bundled with it so they move together when reordered.
88
99
use crate::node_kind::GDScriptNodeKind;
10+
use crate::shared_utils::should_annotation_be_inline;
1011
use tree_sitter::Node;
1112

1213
#[derive(Debug, Clone)]
@@ -187,10 +188,10 @@ pub fn build_reorder_plan<'a>(parent: Node<'a>, content: &'a str) -> ReorderPlan
187188
} else {
188189
is_child_attached_to_declaration[child_index] = true;
189190
if let Some(annotation_identifier) = get_annotation_identifier(child, content) {
190-
if is_inline_export_annotation(annotation_identifier) {
191-
visited_annotations.has_export_annotation = true;
192-
} else if annotation_identifier == "onready" {
191+
if annotation_identifier == "onready" {
193192
visited_annotations.has_onready_annotation = true;
193+
} else if should_annotation_be_inline(annotation_identifier) {
194+
visited_annotations.has_export_annotation = true;
194195
}
195196
}
196197
}
@@ -528,10 +529,10 @@ fn classify_variable<'a>(
528529
let Some(annotation_name) = get_annotation_identifier(annotation, content) else {
529530
continue;
530531
};
531-
if is_inline_export_annotation(annotation_name) {
532-
has_export_annotation = true;
533-
} else if annotation_name == "onready" {
532+
if annotation_name == "onready" {
534533
has_onready_annotation = true;
534+
} else if should_annotation_be_inline(annotation_name) {
535+
has_export_annotation = true;
535536
}
536537
}
537538
}
@@ -563,16 +564,6 @@ fn get_annotation_identifier<'a>(annotation: Node<'a>, content: &'a str) -> Opti
563564
None
564565
}
565566

566-
/// Returns true when an annotation exports the variable it annotates. The
567-
/// `@export_group` and `@export_subgroup` annotations only mark groups of
568-
/// following properties and must not make an unannotated variable look
569-
/// exported.
570-
fn is_inline_export_annotation(annotation_name: &str) -> bool {
571-
annotation_name.starts_with("export")
572-
&& annotation_name != "export_group"
573-
&& annotation_name != "export_subgroup"
574-
}
575-
576567
/// Extract the "name" field child from a declaration node.
577568
fn extract_name<'a>(node: Node<'a>, content: &'a str) -> Option<&'a str> {
578569
let count = node.child_count();

‎src/shared_utils.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Returns `true` if the annotation should be inline, `false` otherwise. All
2+
/// export annotations except those that create inspector groups or categories
3+
/// and the onready annotation should be written inline.
4+
pub fn should_annotation_be_inline(annotation_name: &str) -> bool {
5+
(annotation_name.starts_with("export")
6+
&& !["export_group", "export_subgroup", "export_category"].contains(&annotation_name))
7+
|| annotation_name == "onready"
8+
}

0 commit comments

Comments
 (0)