Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript: Fix extension comparison for exported scripts #88365

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,18 @@ 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 path_b = p_path_b;
if (path_b.get_extension() == "gdc") {
path_b = path_b.get_basename() + ".gd";
}
return path_a == path_b;
}

GDScript::UpdatableFuncPtr::UpdatableFuncPtr(GDScriptFunction *p_function) {
if (p_function == nullptr) {
return;
Expand Down
2 changes: 2 additions & 0 deletions modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ class GDScript : public Script {
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);

_FORCE_INLINE_ StringName get_local_name() const { return local_name; }

void clear(GDScript::ClearData *p_clear_data = nullptr);
Expand Down
6 changes: 3 additions & 3 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) && (ScriptServer::get_global_class_path(class_name) != parser->script_path || p_class != parser->head)) {
} 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)) {
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);
Expand Down Expand Up @@ -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 (base_path == parser->script_path) {
if (GDScript::is_equal_gdscript_paths(base_path, parser->script_path)) {
base = parser->head->get_datatype();
} else {
Ref<GDScriptParserRef> base_parser = get_parser_for(base_path);
Expand Down Expand Up @@ -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 (parser->script_path == ScriptServer::get_global_class_path(first)) {
if (GDScript::is_equal_gdscript_paths(parser->script_path, ScriptServer::get_global_class_path(first))) {
result = parser->head->get_datatype();
} else {
String path = ScriptServer::get_global_class_path(first);
Expand Down
4 changes: 2 additions & 2 deletions modules/gdscript/language_server/gdscript_workspace.cpp
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gdc probably shouldn't appear in LSP, but I fixed it here too just in case.

Original file line number Diff line number Diff line change
Expand Up @@ -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() && scr->get_path() == path) {
if (scr.is_valid() && GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
break;
}
for (int i = 0; i < current->get_child_count(); ++i) {
Expand All @@ -650,7 +650,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
}

Ref<GDScript> scr = current->get_script();
if (!scr.is_valid() || scr->get_path() != path) {
if (!scr.is_valid() || !GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
current = owner_scene_node;
}
}
Expand Down
17 changes: 10 additions & 7 deletions modules/gdscript/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@ Ref<GDScriptEditorTranslationParserPlugin> gdscript_translation_parser_plugin;
class EditorExportGDScript : public EditorExportPlugin {
GDCLASS(EditorExportGDScript, EditorExportPlugin);

public:
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
int script_mode = EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED;
static constexpr int DEFAULT_SCRIPT_MODE = EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED;
int script_mode = DEFAULT_SCRIPT_MODE;

const Ref<EditorExportPreset> &preset = get_export_preset();
protected:
virtual void _export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) override {
script_mode = DEFAULT_SCRIPT_MODE;

const Ref<EditorExportPreset> &preset = get_export_preset();
if (preset.is_valid()) {
script_mode = preset->get_script_export_mode();
}
}

if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
if (p_path.get_extension() != "gd" || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
return;
}

Expand All @@ -110,10 +114,9 @@ class EditorExportGDScript : public EditorExportPlugin {
}

add_file(p_path.get_basename() + ".gdc", file, true);

return;
}

public:
virtual String get_name() const override { return "GDScript"; }
};

Expand Down
Loading