Selaa lähdekoodia

Debugging additions

HolonProduction 1 vuosi sitten
vanhempi
commit
1f42455e0a

+ 4 - 0
core/io/resource.cpp

@@ -31,6 +31,7 @@
 #include "resource.h"
 
 #include "core/core_string_names.h"
+#include "core/error/error_macros.h"
 #include "core/io/file_access.h"
 #include "core/io/resource_loader.h"
 #include "core/math/math_funcs.h"
@@ -84,6 +85,9 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
 	path_cache = p_path;
 
 	if (!path_cache.is_empty()) {
+		if (p_path.ends_with("class_a.notest.gd")) {
+			print_line("Setting resource path to class_a.notest.gd");
+		}
 		ResourceCache::resources[path_cache] = this;
 	}
 	ResourceCache::lock.unlock();

+ 17 - 0
core/io/resource_loader.cpp

@@ -242,6 +242,7 @@ ResourceLoader::LoadToken::~LoadToken() {
 }
 
 Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress) {
+	print_line("_load", p_path);
 	load_nesting++;
 	if (load_paths_stack->size()) {
 		thread_load_mutex.lock();
@@ -260,12 +261,14 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
 		if (!loader[i]->recognize_path(p_path, p_type_hint)) {
 			continue;
 		}
+		print_line("found a resource loader", loader[i]->get_class_name(), p_path);
 		found = true;
 		res = loader[i]->load(p_path, !p_original_path.is_empty() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode);
 		if (!res.is_null()) {
 			break;
 		}
 	}
+	print_line("end looking for resource loaders", p_path);
 
 	load_paths_stack->resize(load_paths_stack->size() - 1);
 	load_nesting--;
@@ -288,11 +291,14 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
 void ResourceLoader::_thread_load_function(void *p_userdata) {
 	ThreadLoadTask &load_task = *(ThreadLoadTask *)p_userdata;
 
+	print_line("_thread_load_function", load_task.remapped_path);
+
 	thread_load_mutex.lock();
 	caller_task_id = load_task.task_id;
 	if (cleaning_tasks) {
 		load_task.status = THREAD_LOAD_FAILED;
 		thread_load_mutex.unlock();
+		print_line("_thread_load_function aborting 1", load_task.remapped_path);
 		return;
 	}
 	thread_load_mutex.unlock();
@@ -434,12 +440,18 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String &
 }
 
 Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error) {
+	for (int i = 0; i < loader_count; i++) {
+		print_line("Handles GDScript:", loader[i]->handles_type("GDScript"));
+	}
+
+	print_line("loading", p_path);
 	if (r_error) {
 		*r_error = OK;
 	}
 
 	Ref<LoadToken> load_token = _load_start(p_path, p_type_hint, LOAD_THREAD_FROM_CURRENT, p_cache_mode);
 	if (!load_token.is_valid()) {
+		print_line("load token invalid", p_path);
 		if (r_error) {
 			*r_error = FAILED;
 		}
@@ -451,6 +463,7 @@ Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hi
 }
 
 Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path, const String &p_type_hint, LoadThreadMode p_thread_mode, ResourceFormatLoader::CacheMode p_cache_mode) {
+	print_line("_load_start", p_path, p_cache_mode);
 	String local_path = _validate_local_path(p_path);
 
 	Ref<LoadToken> load_token;
@@ -462,6 +475,7 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
 		MutexLock thread_load_lock(thread_load_mutex);
 
 		if (thread_load_tasks.has(local_path)) {
+			print_line("_load_start token already exists", p_path);
 			load_token = Ref<LoadToken>(thread_load_tasks[local_path].load_token);
 			if (!load_token.is_valid()) {
 				// The token is dying (reached 0 on another thread).
@@ -469,6 +483,7 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
 				thread_load_tasks[local_path].load_token->clear();
 			} else {
 				if (p_cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
+					print_line("_load_start token already exists return", p_path);
 					return load_token;
 				}
 			}
@@ -490,6 +505,7 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
 			if (p_cache_mode == ResourceFormatLoader::CACHE_MODE_REUSE) {
 				Ref<Resource> existing = ResourceCache::get_ref(local_path);
 				if (existing.is_valid()) {
+					print_line("existing is valid", p_path);
 					//referencing is fine
 					load_task.resource = existing;
 					load_task.status = THREAD_LOAD_LOADED;
@@ -512,6 +528,7 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
 		}
 
 		run_on_current_thread = must_not_register || p_thread_mode == LOAD_THREAD_FROM_CURRENT;
+		print_line("_load_start run on current thread", run_on_current_thread, p_path);
 
 		if (run_on_current_thread) {
 			load_task_ptr->thread_id = Thread::get_caller_id();

+ 15 - 1
modules/gdscript/gdscript.cpp

@@ -304,13 +304,22 @@ void GDScript::get_script_method_list(List<MethodInfo> *r_list) const {
 }
 
 void GDScript::_get_script_property_list(List<PropertyInfo> *r_list, bool p_include_base) const {
+	print_line("GDSCript get_script_property list");
 	const GDScript *sptr = this;
+	print_line(this);
 	List<PropertyInfo> props;
-
 	while (sptr) {
+		print_line("while running");
+		print_line(sptr->get_source_code());
+		print_line(sptr->reloading);
+		print_line(sptr->member_indices.size());
+		print_line(sptr->members.size());
+		print_line(sptr->get_members().size());
 		Vector<_GDScriptMemberSort> msort;
 		for (const KeyValue<StringName, MemberInfo> &E : sptr->member_indices) {
+			print_line(E.key);
 			if (!sptr->members.has(E.key)) {
+				print_line("skipping");
 				continue; // Skip base class members.
 			}
 			_GDScriptMemberSort ms;
@@ -330,6 +339,7 @@ void GDScript::_get_script_property_list(List<PropertyInfo> *r_list, bool p_incl
 #endif // TOOLS_ENABLED
 
 		for (const PropertyInfo &E : props) {
+			print_line("pushing_back", E.name);
 			r_list->push_back(E);
 		}
 
@@ -687,6 +697,7 @@ void GDScript::_restore_old_static_data() {
 #endif
 
 Error GDScript::reload(bool p_keep_state) {
+	print_line("reload", this->get_script_path());
 	if (reloading) {
 		return OK;
 	}
@@ -1016,6 +1027,7 @@ String GDScript::get_script_path() const {
 }
 
 Error GDScript::load_source_code(const String &p_path) {
+	print_line("load source code", p_path);
 	if (p_path.is_empty() || p_path.begins_with("gdscript://") || ResourceLoader::get_resource_type(p_path.get_slice("::", 0)) == "PackedScene") {
 		return OK;
 	}
@@ -2816,6 +2828,7 @@ Ref<GDScript> GDScriptLanguage::get_script_by_fully_qualified_name(const String
 /*************** RESOURCE ***************/
 
 Ref<Resource> ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
+	print_line("resource format loader load", p_path);
 	Error err;
 	bool ignoring = p_cache_mode == CACHE_MODE_IGNORE || p_cache_mode == CACHE_MODE_IGNORE_DEEP;
 	Ref<GDScript> scr = GDScriptCache::get_full_script(p_original_path, err, "", ignoring);
@@ -2839,6 +2852,7 @@ void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_ext
 }
 
 bool ResourceFormatLoaderGDScript::handles_type(const String &p_type) const {
+	print_line("GDScrip resource loader handles", p_type);
 	return (p_type == "Script" || p_type == "GDScript");
 }
 

+ 1 - 0
modules/gdscript/gdscript_cache.cpp

@@ -283,6 +283,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e
 }
 
 Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_error, const String &p_owner, bool p_update_from_disk) {
+	print_line("get full script", p_path);
 	MutexLock lock(singleton->mutex);
 
 	if (!p_owner.is_empty()) {

+ 13 - 0
modules/gdscript/gdscript_compiler.cpp

@@ -30,6 +30,7 @@
 
 #include "gdscript_compiler.h"
 
+#include "core/string/print_string.h"
 #include "gdscript.h"
 #include "gdscript_byte_codegen.h"
 #include "gdscript_cache.h"
@@ -2579,11 +2580,17 @@ Error GDScriptCompiler::_parse_setter_getter(GDScript *p_script, const GDScriptP
 // RPC info for its base classes first, then for itself, then for inner classes.
 // Warning: this function cannot initiate compilation of other classes, or it will result in cyclic dependency issues.
 Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptParser::ClassNode *p_class, bool p_keep_state) {
+	print_line("prepare compilation", p_script->get_script_path());
+	print_line(p_script->get_source_code());
+	//print_line(p_class->extends[0]);
+	print_line(p_class->members.size());
 	if (parsed_classes.has(p_script)) {
+		print_line("already parsed");
 		return OK;
 	}
 
 	if (parsing_classes.has(p_script)) {
+		print_line("already parsing");
 		String class_name = p_class->identifier ? String(p_class->identifier->name) : p_class->fqcn;
 		_set_error(vformat(R"(Cyclic class reference for "%s".)", class_name), p_class);
 		return ERR_PARSE_ERROR;
@@ -2712,8 +2719,11 @@ Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptP
 
 	for (int i = 0; i < p_class->members.size(); i++) {
 		const GDScriptParser::ClassNode::Member &member = p_class->members[i];
+		print_line(member.get_name());
+		print_line(member.type);
 		switch (member.type) {
 			case GDScriptParser::ClassNode::Member::VARIABLE: {
+				print_line("variable");
 				const GDScriptParser::VariableNode *variable = member.variable;
 				StringName name = variable->identifier->name;
 
@@ -2756,9 +2766,11 @@ Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptP
 				minfo.property_info = prop_info;
 
 				if (variable->is_static) {
+					print_line("static");
 					minfo.index = p_script->static_variables_indices.size();
 					p_script->static_variables_indices[name] = minfo;
 				} else {
+					print_line("inserting");
 					minfo.index = p_script->member_indices.size();
 					p_script->member_indices[name] = minfo;
 					p_script->members.insert(name);
@@ -3174,6 +3186,7 @@ void GDScriptCompiler::_get_function_ptr_replacements(HashMap<GDScriptFunction *
 }
 
 Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_script, bool p_keep_state) {
+	print_line("compile", p_script->get_script_path());
 	err_line = -1;
 	err_column = -1;
 	error = "";

+ 28 - 6
modules/gdscript/gdscript_editor.cpp

@@ -28,6 +28,7 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
 /**************************************************************************/
 
+#include "core/string/print_string.h"
 #include "gdscript.h"
 
 #include "gdscript_analyzer.h"
@@ -1128,15 +1129,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
 				print_line("identifier script");
 				Ref<Script> scr = base_type.script_type;
 				if (scr.is_valid()) {
-<<<<<<< HEAD
 					if (p_types_only) {
 						// TODO: Need to implement Script::get_script_enum_list and retrieve the enum list from a script.
 					} else if (!p_only_functions) {
-=======
-					print_line("script valid");
-					if (!p_only_functions) {
-						print_line("not only functions");
->>>>>>> ae78637b78 (Add test for `get_node` autocompletion)
 						if (!base_type.is_meta_type) {
 							print_line("no meta type");
 							List<PropertyInfo> members;
@@ -2056,6 +2051,7 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context,
 }
 
 static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context, const GDScriptParser::IdentifierNode *p_identifier, GDScriptCompletionIdentifier &r_type) {
+	print_line("guess identifier type");
 	static int recursion_depth = 0;
 	RecursionCheck recursion(&recursion_depth);
 	if (unlikely(recursion.check())) {
@@ -2114,7 +2110,9 @@ static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context,
 				break;
 		}
 	} else {
+		print_line("not local");
 		if (p_context.current_class) {
+			print_line("current class exists");
 			GDScriptCompletionIdentifier base_identifier;
 
 			GDScriptCompletionIdentifier base;
@@ -2302,6 +2300,7 @@ static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context,
 }
 
 static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &p_context, const GDScriptCompletionIdentifier &p_base, const StringName &p_identifier, GDScriptCompletionIdentifier &r_type) {
+	print_line("_guess_identifier_type_from_base");
 	static int recursion_depth = 0;
 	RecursionCheck recursion(&recursion_depth);
 	if (unlikely(recursion.check())) {
@@ -2313,7 +2312,9 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
 	while (base_type.is_set()) {
 		switch (base_type.kind) {
 			case GDScriptParser::DataType::CLASS:
+				print_line("CLASS");
 				if (base_type.class_type->has_member(p_identifier)) {
+					print_line("has member");
 					const GDScriptParser::ClassNode::Member &member = base_type.class_type->get_member(p_identifier);
 					switch (member.type) {
 						case GDScriptParser::ClassNode::Member::CONSTANT:
@@ -2323,29 +2324,40 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
 							}
 							return true;
 						case GDScriptParser::ClassNode::Member::VARIABLE:
+							print_line("variable");
 							if (!is_static || member.variable->is_static) {
+								print_line("1");
 								if (member.variable->get_datatype().is_set() && !member.variable->get_datatype().is_variant()) {
+									print_line("2");
 									r_type.type = member.variable->get_datatype();
 									return true;
 								} else if (member.variable->initializer) {
+									print_line("3");
 									const GDScriptParser::ExpressionNode *init = member.variable->initializer;
 									if (init->is_constant) {
+										print_line("4");
 										r_type.value = init->reduced_value;
 										r_type = _type_from_variant(init->reduced_value, p_context);
 										return true;
 									} else if (init->start_line == p_context.current_line) {
+										print_line("5");
 										return false;
 										// Detects if variable is assigned to itself
 									} else if (_is_expression_named_identifier(init, member.variable->identifier->name)) {
+										print_line("6");
 										if (member.variable->initializer->get_datatype().is_set()) {
+											print_line("7");
 											r_type.type = member.variable->initializer->get_datatype();
 										} else if (member.variable->get_datatype().is_set() && !member.variable->get_datatype().is_variant()) {
+											print_line("8");
 											r_type.type = member.variable->get_datatype();
 										}
 										return true;
 									} else if (_guess_expression_type(p_context, init, r_type)) {
+										print_line("9");
 										return true;
 									} else if (init->get_datatype().is_set() && !init->get_datatype().is_variant()) {
+										print_line("10");
 										r_type.type = init->get_datatype();
 										return true;
 									}
@@ -2847,6 +2859,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
 }
 
 static bool _get_subscript_type(GDScriptParser::CompletionContext &p_context, const GDScriptParser::SubscriptNode *p_subscript, GDScriptParser::DataType &r_base_type, Variant *r_base = nullptr) {
+	print_line("get subscript type");
 	if (p_context.base == nullptr) {
 		return false;
 	}
@@ -2859,10 +2872,13 @@ static bool _get_subscript_type(GDScriptParser::CompletionContext &p_context, co
 		} break;
 
 		case GDScriptParser::Node::IDENTIFIER: {
+			print_line("identifier");
 			if (p_subscript->base->datatype.type_source == GDScriptParser::DataType::ANNOTATED_EXPLICIT) {
+				print_line("annotated type takes precedence");
 				// Annotated type takes precedence.
 				return false;
 			}
+			print_line("annotated type did not work", p_subscript->base->datatype.type_source);
 
 			const GDScriptParser::IdentifierNode *identifier_node = static_cast<GDScriptParser::IdentifierNode *>(p_subscript->base);
 
@@ -3177,11 +3193,17 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
 			[[fallthrough]];
 		case GDScriptParser::COMPLETION_ATTRIBUTE: {
 			print_line("completion attribute");
+			if (completion_context.base != nullptr) {
+				print_line("base", completion_context.base->to_string());
+			} else {
+				print_line("no base");
+			}
 			r_forced = true;
 			const GDScriptParser::SubscriptNode *attr = static_cast<const GDScriptParser::SubscriptNode *>(completion_context.node);
 			if (attr->base) {
 				GDScriptCompletionIdentifier base;
 				bool found_type = _get_subscript_type(completion_context, attr, base.type);
+				print_line("found through subscript type", found_type);
 				if (!found_type && !_guess_expression_type(completion_context, attr->base, base)) {
 					break;
 				}

+ 1 - 0
modules/gdscript/register_types.cpp

@@ -142,6 +142,7 @@ static void _editor_init() {
 #endif // TOOLS_ENABLED
 
 void initialize_gdscript_module(ModuleInitializationLevel p_level) {
+	print_line("Initialize GDScript Module.");
 	if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
 		GDREGISTER_CLASS(GDScript);
 

+ 1 - 1
modules/gdscript/tests/scripts/completion/get_node/get_node.tscn

@@ -12,8 +12,8 @@
 unique_name_in_owner = true
 
 [node name="UniqueA" type="Node" parent="UniqueNames"]
-script = ExtResource("1_ldc4g")
 unique_name_in_owner = true
+script = ExtResource("1_ldc4g")
 
 [node name="A" type="Node" parent="."]
 script = ExtResource("1_ldc4g")

+ 3 - 2
modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/class_member_typehint_scene.gd

@@ -1,8 +1,9 @@
+@uid("uid://d04ev0gljq5yp") # Generated automatically, do not modify.
 extends Node
 
 const A := preload("res://completion/class_a.notest.gd")
 
-var test: A = $A
+@onready var test: A = $A
 
 func a():
-    test.➡
+	test.➡

+ 25 - 3
modules/gdscript/tests/test_completion.h

@@ -31,6 +31,9 @@
 #ifndef TEST_COMPLETION_H
 #define TEST_COMPLETION_H
 
+#include "core/io/resource.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_uid.h"
 #ifdef TOOLS_ENABLED
 
 #include "core/io/config_file.h"
@@ -140,8 +143,20 @@ static void test_directory(const String &p_dir) {
 			bool forced;
 
 			Node *owner = nullptr;
+			print_line("before owner load");
 			if (conf.has_section_key("input", "scene")) {
-				Ref<PackedScene> scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene");
+				/*List<String> deps;
+				ResourceLoader::get_dependencies(conf.get_value("input", "scene"), &deps);
+				for (const String &E : deps) {
+					print_line(E);
+					print_line(ResourceLoader::exists(E));
+					print_line(ResourceLoader::get_resource_type(E));
+					Ref<GDScript> s = ResourceLoader::load(E);
+					if (s->is_valid()) {
+						print_line(s->get_members().size());
+					}
+				}*/
+				Ref<PackedScene> scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP);
 				if (scene.is_valid()) {
 					owner = scene->instantiate();
 				}
@@ -151,11 +166,16 @@ static void test_directory(const String &p_dir) {
 					owner = scene->instantiate();
 				}
 			}
-
+			print_line("after owner load");
+			if (owner != nullptr) {
+				print_line("owner", owner->to_string());
+			} else {
+				print_line("no owner");
+			}
 			GDScriptLanguage::get_singleton()->complete_code(code, path.path_join(next), owner, &options, forced, call_hint);
 			String contains_excluded;
 			for (ScriptLanguage::CodeCompletionOption &option : options) {
-				print_line(option.display);
+				//print_line(option.display);
 				for (const Dictionary &E : exclude) {
 					if (match_option(E, option)) {
 						contains_excluded = option.display;
@@ -199,6 +219,8 @@ static void test_directory(const String &p_dir) {
 
 TEST_SUITE("[Modules][GDScript][Completion]") {
 	TEST_CASE("[Editor] Check suggestion list") {
+		ResourceUID::initialize_class();
+
 		// Set all editor settings that code completion relies on.
 		EditorSettings::get_singleton()->set_setting("text_editor/completion/use_single_quotes", false);
 		init_language("modules/gdscript/tests/scripts");