@@ -230,6 +230,17 @@ fn extract_tokens_to_reorder(
230230 // Notably a comment after the extends declaration might be a var or method docstring.
231231 // We need to check if the comments are contiguous with the declaration they are
232232 // attached to.
233+
234+ // Find the byte position of the first class_name or extends statement
235+ // Any annotations before this position are class-level annotations
236+ let first_class_declaration_byte = all_nodes
237+ . iter ( )
238+ . find ( |( node, _) | {
239+ node. kind ( ) == "class_name_statement" || node. kind ( ) == "extends_statement"
240+ } )
241+ . map ( |( node, _) | node. start_byte ( ) )
242+ . unwrap_or ( usize:: MAX ) ;
243+
233244 let mut class_docstring_comments = Vec :: new ( ) ;
234245 let mut class_docstring_comments_rows = Vec :: new ( ) ;
235246 for ( node, text) in & all_nodes {
@@ -274,7 +285,9 @@ fn extract_tokens_to_reorder(
274285 // annotations until we hit a declaration, at which point we attach the
275286 // collected comments/annotations to that declaration.
276287 for ( node, text) in & all_nodes {
277- let reorderable_element = classify_element ( * node, text, content) ?;
288+ let is_before_class_declaration = node. start_byte ( ) < first_class_declaration_byte;
289+ let reorderable_element =
290+ classify_element ( * node, text, content, is_before_class_declaration) ?;
278291 classified_elements. push ( ClassifiedElement {
279292 node : * node,
280293 text : text. clone ( ) ,
@@ -464,13 +477,11 @@ fn classify_element(
464477 node : Node ,
465478 text : & str ,
466479 content : & str ,
480+ is_before_class_declaration : bool ,
467481) -> Result < Option < GDScriptTokenKind > , Box < dyn std:: error:: Error > > {
468482 match node. kind ( ) {
469483 "annotation" => {
470- if text. starts_with ( "@tool" )
471- || text. starts_with ( "@icon" )
472- || text. starts_with ( "@static_unload" )
473- {
484+ if is_before_class_declaration {
474485 Ok ( Some ( GDScriptTokenKind :: ClassAnnotation ( text. to_string ( ) ) ) )
475486 } else {
476487 Ok ( None )
0 commit comments