summaryrefslogtreecommitdiffstats
path: root/modules/gdscript
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2024-02-26 10:46:24 +0300
committerDanil Alexeev <danil@alexeev.xyz>2024-02-26 10:46:24 +0300
commit8ffc50ee8ce2a8ee8a59334bc500a0f46198c904 (patch)
treef22716c1f8a29aaf78b2ab5187841f8c2525743d /modules/gdscript
parent81f3d43cc1ba01136795fb2059bbaa55bc514a16 (diff)
downloadredot-engine-8ffc50ee8ce2a8ee8a59334bc500a0f46198c904.tar.gz
GDScript: Canonicalize script path in FQCN
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript.cpp13
-rw-r--r--modules/gdscript/gdscript.h5
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp6
-rw-r--r--modules/gdscript/gdscript_parser.cpp4
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp4
5 files changed, 15 insertions, 17 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 20d7fdb601..2d6c0c1d11 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -1405,16 +1405,11 @@ String GDScript::debug_get_script_name(const Ref<Script> &p_script) {
}
#endif
-bool GDScript::is_equal_gdscript_paths(const String &p_path_a, const String &p_path_b) {
- String path_a = p_path_a;
- if (path_a.get_extension() == "gdc") {
- path_a = path_a.get_basename() + ".gd";
+String GDScript::canonicalize_path(const String &p_path) {
+ if (p_path.get_extension() == "gdc") {
+ return p_path.get_basename() + ".gd";
}
- String path_b = p_path_b;
- if (path_b.get_extension() == "gdc") {
- path_b = path_b.get_basename() + ".gd";
- }
- return path_a == path_b;
+ return p_path;
}
GDScript::UpdatableFuncPtr::UpdatableFuncPtr(GDScriptFunction *p_function) {
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 981cbb3734..7c471c285b 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -230,7 +230,10 @@ public:
static String debug_get_script_name(const Ref<Script> &p_script);
#endif
- static bool is_equal_gdscript_paths(const String &p_path_a, const String &p_path_b);
+ static String canonicalize_path(const String &p_path);
+ _FORCE_INLINE_ static bool is_canonically_equal_paths(const String &p_path_a, const String &p_path_b) {
+ return canonicalize_path(p_path_a) == canonicalize_path(p_path_b);
+ }
_FORCE_INLINE_ StringName get_local_name() const { return local_name; }
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 2f1ae3380e..98d4a19a87 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -361,7 +361,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
push_error(vformat(R"(Class "%s" hides a built-in type.)", class_name), p_class->identifier);
} else if (class_exists(class_name)) {
push_error(vformat(R"(Class "%s" hides a native class.)", class_name), p_class->identifier);
- } else if (ScriptServer::is_global_class(class_name) && (!GDScript::is_equal_gdscript_paths(ScriptServer::get_global_class_path(class_name), parser->script_path) || p_class != parser->head)) {
+ } else if (ScriptServer::is_global_class(class_name) && (!GDScript::is_canonically_equal_paths(ScriptServer::get_global_class_path(class_name), parser->script_path) || p_class != parser->head)) {
push_error(vformat(R"(Class "%s" hides a global script class.)", class_name), p_class->identifier);
} else if (ProjectSettings::get_singleton()->has_autoload(class_name) && ProjectSettings::get_singleton()->get_autoload(class_name).is_singleton) {
push_error(vformat(R"(Class "%s" hides an autoload singleton.)", class_name), p_class->identifier);
@@ -425,7 +425,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
if (ScriptServer::is_global_class(name)) {
String base_path = ScriptServer::get_global_class_path(name);
- if (GDScript::is_equal_gdscript_paths(base_path, parser->script_path)) {
+ if (GDScript::is_canonically_equal_paths(base_path, parser->script_path)) {
base = parser->head->get_datatype();
} else {
Ref<GDScriptParserRef> base_parser = get_parser_for(base_path);
@@ -698,7 +698,7 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
result.builtin_type = Variant::OBJECT;
result.native_type = first;
} else if (ScriptServer::is_global_class(first)) {
- if (GDScript::is_equal_gdscript_paths(parser->script_path, ScriptServer::get_global_class_path(first))) {
+ if (GDScript::is_canonically_equal_paths(parser->script_path, ScriptServer::get_global_class_path(first))) {
result = parser->head->get_datatype();
} else {
String path = ScriptServer::get_global_class_path(first);
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 4625855329..f63b2ce0ee 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -551,7 +551,7 @@ void GDScriptParser::end_statement(const String &p_context) {
void GDScriptParser::parse_program() {
head = alloc_node<ClassNode>();
- head->fqcn = script_path;
+ head->fqcn = GDScript::canonicalize_path(script_path);
current_class = head;
bool can_have_class_or_extends = true;
@@ -709,7 +709,7 @@ GDScriptParser::ClassNode *GDScriptParser::parse_class(bool p_is_static) {
if (n_class->outer) {
String fqcn = n_class->outer->fqcn;
if (fqcn.is_empty()) {
- fqcn = script_path;
+ fqcn = GDScript::canonicalize_path(script_path);
}
n_class->fqcn = fqcn + "::" + n_class->identifier->name;
} else {
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp
index 979b7e8579..853a8e0f19 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -641,7 +641,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
while (!stack.is_empty()) {
current = Object::cast_to<Node>(stack.pop_back());
Ref<GDScript> scr = current->get_script();
- if (scr.is_valid() && GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
+ if (scr.is_valid() && GDScript::is_canonically_equal_paths(scr->get_path(), path)) {
break;
}
for (int i = 0; i < current->get_child_count(); ++i) {
@@ -650,7 +650,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
}
Ref<GDScript> scr = current->get_script();
- if (!scr.is_valid() || !GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
+ if (!scr.is_valid() || !GDScript::is_canonically_equal_paths(scr->get_path(), path)) {
current = owner_scene_node;
}
}