@@ -20,12 +20,12 @@ const PracticeDonePopup := preload("components/popups/PracticeDonePopup.gd")
2020const PracticeLeaveUnfinishedPopup := preload ("components/popups/PracticeLeaveUnfinishedPopup.gd" )
2121const documentation_resource : Documentation = preload ("res://course/Documentation.tres" )
2222
23- var REGEX_DIVSION_BY_ZERO := RegEx .new ()
23+ static var REGEX_DIVSION_BY_ZERO := RegEx .create_from_string ((r "[/%] *0" ))
24+ static var REGEX_CLASS_NAME := RegEx .create_from_string (r "\s *class_name\s " )
2425
2526@export var lesson_test_practice : String
2627@export_range (0 , 1 , 1 , "or_greater" ) var test_practice : int
2728@export var _layout_container : Control
28- @export var _output_container : Control
2929@export var _game_container : Container
3030@export var _game_view : GameView
3131@export var _output_console : OutputConsole
@@ -331,15 +331,30 @@ func _validate_and_run_student_code() -> void:
331331 _code_editor .unlock_editor ()
332332 return
333333
334- var verifier := OfflineScriptVerifier .new (script_text )
334+ var verifier_script := script_text
335+ var script_is_desynced_by_one_line := false
336+
337+ if not _has_class_name (verifier_script ):
338+ # required by GDScriptAnalyzer, since otherwise it has no external parser to cache
339+ verifier_script = "class_name TEMP_UserScript\n " + verifier_script
340+ script_is_desynced_by_one_line = true
341+
342+ var verifier := OfflineScriptVerifier .new (verifier_script )
335343 verifier .test ()
336344 var errors := verifier .errors
337345
338346 if not errors .is_empty ():
347+ if script_is_desynced_by_one_line :
348+ for error : ScriptError in errors :
349+ error .error_range .start .line -= 1
350+ error .error_range .end .line -= 1
339351 _code_editor .slice_editor .errors = errors
340352
341353 for index in errors .size ():
342354 var error : ScriptError = errors [index ]
355+ # GDScriptAnalyzer benign issue; script didn't exist until now
356+ if error .message == 'Error while getting cache for script "".' :
357+ continue
343358 MessageBus .print_script_error (error , script_file_name )
344359
345360 var is_missing_parser_error : bool = (
@@ -399,7 +414,7 @@ func _validate_and_run_student_code() -> void:
399414 if script_is_valid != OK :
400415 var error := ScriptError .new ()
401416 error .message = tr (
402- "Oh no! The script has an error, but the Script Verifier did not catch it" ,
417+ "Oh no! The script has an error (code %s ) , but the Script Verifier did not catch it" % script_is_valid ,
403418 )
404419 error .severity = 1
405420 error .code = GDQuestCodes .ErrorCode .INVALID_NO_CATCH
@@ -690,6 +705,10 @@ func _on_init_set_javascript() -> void:
690705 GDQUEST .events .onError .connect (_on_js_error_feedback_ref )
691706
692707
708+ func _has_class_name (source : String ) -> bool :
709+ return REGEX_CLASS_NAME .search (source ) != null
710+
711+
693712# Checks if the script text has mixed tabs and spaces in indentation.
694713# Returns the line number of the error or -1 if there's no error
695714func _check_for_mixed_indentation (text : String ) -> int :
0 commit comments