File tree Expand file tree Collapse file tree 3 files changed +25
-15
lines changed
Expand file tree Collapse file tree 3 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -672,14 +672,16 @@ void GDScriptParser::parse_program() {
672672 }
673673 }
674674
675+ if (current.type == GDScriptTokenizer::Token::CLASS_NAME || current.type == GDScriptTokenizer::Token::EXTENDS) {
676+ // Set range of the class to only start at extends or class_name if present.
677+ reset_extents (head, current);
678+ }
679+
675680 while (can_have_class_or_extends) {
676681 // Order here doesn't matter, but there should be only one of each at most.
677682 switch (current.type ) {
678683 case GDScriptTokenizer::Token::CLASS_NAME:
679684 PUSH_PENDING_ANNOTATIONS_TO_HEAD;
680- if (head->start_line == 1 ) {
681- reset_extents (head, current);
682- }
683685 advance ();
684686 if (head->identifier != nullptr ) {
685687 push_error (R"( "class_name" can only be used once.)" );
@@ -689,9 +691,6 @@ void GDScriptParser::parse_program() {
689691 break ;
690692 case GDScriptTokenizer::Token::EXTENDS:
691693 PUSH_PENDING_ANNOTATIONS_TO_HEAD;
692- if (head->start_line == 1 ) {
693- reset_extents (head, current);
694- }
695694 advance ();
696695 if (head->extends_used ) {
697696 push_error (R"( "extends" can only be used once.)" );
Original file line number Diff line number Diff line change 1+ class_name Test
2+ extends Node
3+
4+ func _init ():
5+ pass
Original file line number Diff line number Diff line change @@ -492,15 +492,21 @@ func f():
492492 REQUIRE (proto);
493493
494494 SUBCASE (" selectionRange of root class must be inside range" ) {
495- String path = " res://lsp/first_line_comment.gd" ;
496- assert_no_errors_in (path);
497- GDScriptLanguageProtocol::get_singleton ()->get_workspace ()->parse_local_script (path);
498- ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton ()->get_workspace ()->parse_results [path];
499- REQUIRE (parser);
500- lsp::DocumentSymbol cls = parser->get_symbols ();
501-
502- REQUIRE (((cls.range .start .line == cls.selectionRange .start .line && cls.range .start .character <= cls.selectionRange .start .character ) || (cls.range .start .line < cls.selectionRange .start .line )));
503- REQUIRE (((cls.range .end .line == cls.selectionRange .end .line && cls.range .end .character >= cls.selectionRange .end .character ) || (cls.range .end .line > cls.selectionRange .end .line )));
495+ LocalVector<String> paths = {
496+ " res://lsp/first_line_comment.gd" , // Comment on first line
497+ " res://lsp/first_line_class_name.gd" , // class_name (and thus selection range) before extends
498+ };
499+
500+ for (const String &path : paths) {
501+ assert_no_errors_in (path);
502+ GDScriptLanguageProtocol::get_singleton ()->get_workspace ()->parse_local_script (path);
503+ ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton ()->get_workspace ()->parse_results [path];
504+ REQUIRE (parser);
505+ lsp::DocumentSymbol cls = parser->get_symbols ();
506+
507+ REQUIRE (((cls.range .start .line == cls.selectionRange .start .line && cls.range .start .character <= cls.selectionRange .start .character ) || (cls.range .start .line < cls.selectionRange .start .line )));
508+ REQUIRE (((cls.range .end .line == cls.selectionRange .end .line && cls.range .end .character >= cls.selectionRange .end .character ) || (cls.range .end .line > cls.selectionRange .end .line )));
509+ }
504510 }
505511
506512 memdelete (proto);
You can’t perform that action at this time.
0 commit comments