Skip to content

Commit

Permalink
!!! WIP !!! Add debug plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexeev committed May 29, 2024
1 parent 1e6b11d commit c063ebe
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 40 deletions.
1 change: 1 addition & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
</member>
<member name="debug/gdscript/warnings/exclude_addons" type="bool" setter="" getter="" default="true">
If [code]true[/code], scripts in the [code]res://addons[/code] folder will not generate warnings.
[b]Note:[/b] ...TODO...
</member>
<member name="debug/gdscript/warnings/function_used_as_property" type="int" setter="" getter="" default="1" deprecated="This warning is never produced. When a function is used as a property, a [Callable] is returned.">
When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when using a function as if it is a property.
Expand Down
87 changes: 82 additions & 5 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,18 @@ void EditorNode::_notification(int p_what) {
case NOTIFICATION_READY: {
{
started_timestamp = Time::get_singleton()->get_unix_time_from_system();

_initializing_plugins = true;

Vector<String> addons_debug;
if (ProjectSettings::get_singleton()->has_setting("editor_plugins/debug")) {
addons_debug = GLOBAL_GET("editor_plugins/debug");
}

for (int i = 0; i < addons_debug.size(); i++) {
set_addon_debug_enabled(addons_debug[i], true);
}

Vector<String> addons;
if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) {
addons = GLOBAL_GET("editor_plugins/enabled");
Expand All @@ -713,6 +724,7 @@ void EditorNode::_notification(int p_what) {
for (int i = 0; i < addons.size(); i++) {
set_addon_plugin_enabled(addons[i], true);
}

_initializing_plugins = false;

if (!pending_addons.is_empty()) {
Expand Down Expand Up @@ -881,6 +893,18 @@ void EditorNode::_remove_plugin_from_enabled(const String &p_name) {
ps->set("editor_plugins/enabled", enabled_plugins);
}

void EditorNode::_remove_plugin_from_debug(const String &p_name) {
ProjectSettings *ps = ProjectSettings::get_singleton();
PackedStringArray plugins_debug = ps->get("editor_plugins/debug");
for (int i = 0; i < plugins_debug.size(); ++i) {
if (plugins_debug.get(i) == p_name) {
plugins_debug.remove_at(i);
break;
}
}
ps->set("editor_plugins/debug", plugins_debug);
}

void EditorNode::_plugin_over_edit(EditorPlugin *p_plugin, Object *p_object) {
if (p_object) {
editor_plugins_over->add_plugin(p_plugin);
Expand Down Expand Up @@ -3549,18 +3573,17 @@ void EditorNode::remove_extension_editor_plugin(const StringName &p_class_name)
singleton->editor_data.remove_extension_editor_plugin(p_class_name);
}

void EditorNode::_update_addon_config() {
void EditorNode::_update_addon_enabled_config() {
if (_initializing_plugins) {
return;
}

Vector<String> enabled_addons;

for (const KeyValue<String, EditorPlugin *> &E : addon_name_to_plugin) {
enabled_addons.push_back(E.key);
}

if (enabled_addons.size() == 0) {
if (enabled_addons.is_empty()) {
ProjectSettings::get_singleton()->set("editor_plugins/enabled", Variant());
} else {
enabled_addons.sort();
Expand All @@ -3585,7 +3608,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled,
remove_editor_plugin(addon, p_config_changed);
memdelete(addon);
addon_name_to_plugin.erase(addon_path);
_update_addon_config();
_update_addon_enabled_config();
return;
}

Expand Down Expand Up @@ -3656,7 +3679,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled,
addon_name_to_plugin[addon_path] = ep;
add_editor_plugin(ep, p_config_changed);

_update_addon_config();
_update_addon_enabled_config();
}

bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const {
Expand All @@ -3667,6 +3690,60 @@ bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const {
return addon_name_to_plugin.has("res://addons/" + p_addon + "/plugin.cfg");
}

void EditorNode::_update_addon_debug_config() {
if (_initializing_plugins) {
return;
}

Vector<String> addons_debug;
for (const String &addon_name : addons_debug_enabled) {
addons_debug.push_back(addon_name);
}

if (addons_debug.is_empty()) {
ProjectSettings::get_singleton()->set("editor_plugins/debug", Variant());
} else {
addons_debug.sort();
ProjectSettings::get_singleton()->set("editor_plugins/debug", addons_debug);
}

project_settings_editor->queue_save();
}

void EditorNode::set_addon_debug_enabled(const String &p_addon, bool p_enabled) {
String addon_path = p_addon;

if (!addon_path.begins_with("res://")) {
addon_path = "res://addons/" + addon_path + "/plugin.cfg";
}

ERR_FAIL_COND(p_enabled && addons_debug_enabled.has(addon_path));
ERR_FAIL_COND(!p_enabled && !addons_debug_enabled.has(addon_path));

if (!p_enabled) {
addons_debug_enabled.erase(addon_path);
_update_addon_debug_config();
return;
}

if (!DirAccess::exists(addon_path.get_base_dir())) {
_remove_plugin_from_debug(addon_path);
WARN_PRINT("Addon '" + addon_path + "' failed to load. No directory found. Removing from debug plugins.");
return;
}

addons_debug_enabled.insert(addon_path);
_update_addon_debug_config();
}

bool EditorNode::is_addon_debug_enabled(const String &p_addon) const {
if (p_addon.begins_with("res://")) {
return addons_debug_enabled.has(p_addon);
}

return addons_debug_enabled.has("res://addons/" + p_addon + "/plugin.cfg");
}

void EditorNode::_remove_edited_scene(bool p_change_tab) {
// When scene gets closed no node is edited anymore, so make sure the editors are notified before nodes are freed.
hide_unused_editors(SceneTreeDock::get_singleton());
Expand Down
8 changes: 7 additions & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class EditorNode : public Node {
Vector<EditorPlugin *> editor_plugins;
bool _initializing_plugins = false;
HashMap<String, EditorPlugin *> addon_name_to_plugin;
HashSet<String> addons_debug_enabled;
LocalVector<String> pending_addons;
HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
bool is_main_screen_editing = false;
Expand Down Expand Up @@ -541,6 +542,7 @@ class EditorNode : public Node {
void _update_file_menu_closed();

void _remove_plugin_from_enabled(const String &p_name);
void _remove_plugin_from_debug(const String &p_name);
void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
void _plugin_over_self_own(EditorPlugin *p_plugin);

Expand Down Expand Up @@ -635,7 +637,8 @@ class EditorNode : public Node {
void _update_layouts_menu();
void _layout_menu_option(int p_id);

void _update_addon_config();
void _update_addon_enabled_config();
void _update_addon_debug_config();

void _toggle_distraction_free_mode();

Expand Down Expand Up @@ -742,6 +745,9 @@ class EditorNode : public Node {
void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
bool is_addon_plugin_enabled(const String &p_addon) const;

void set_addon_debug_enabled(const String &p_addon, bool p_enabled);
bool is_addon_debug_enabled(const String &p_addon) const;

void edit_node(Node *p_node);
void edit_resource(const Ref<Resource> &p_resource);

Expand Down
50 changes: 29 additions & 21 deletions editor/plugins/editor_plugin_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ void EditorPluginSettings::update_plugins() {
String description = cfg->get_value("plugin", "description");
String scr = cfg->get_value("plugin", "script");

bool is_enabled = EditorNode::get_singleton()->is_addon_plugin_enabled(path);
Color disabled_color = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));
const bool is_enabled = EditorNode::get_singleton()->is_addon_plugin_enabled(path);
const bool is_debug = EditorNode::get_singleton()->is_addon_debug_enabled(path);
const Color disabled_color = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));

const PackedInt32Array boundaries = TS->string_get_word_breaks(description, "", 80);
String wrapped_description;
Expand All @@ -116,6 +117,10 @@ void EditorPluginSettings::update_plugins() {
item->set_text(COLUMN_STATUS, TTR("On"));
item->set_checked(COLUMN_STATUS, is_enabled);
item->set_editable(COLUMN_STATUS, true);
item->set_cell_mode(COLUMN_DEBUG, TreeItem::CELL_MODE_CHECK);
item->set_text(COLUMN_DEBUG, TTR("On"));
item->set_checked(COLUMN_DEBUG, is_debug);
item->set_editable(COLUMN_DEBUG, true);
item->add_button(COLUMN_EDIT, get_editor_theme_icon(SNAME("Edit")), BUTTON_PLUGIN_EDIT, false, TTR("Edit Plugin"));
}
}
Expand All @@ -124,29 +129,27 @@ void EditorPluginSettings::update_plugins() {
updating = false;
}

void EditorPluginSettings::_plugin_activity_changed() {
if (updating) {
return;
}

void EditorPluginSettings::_plugin_list_item_edited() {
TreeItem *ti = plugin_list->get_edited();
ERR_FAIL_NULL(ti);
bool checked = ti->is_checked(COLUMN_STATUS);
String name = ti->get_metadata(COLUMN_NAME);

EditorNode::get_singleton()->set_addon_plugin_enabled(name, checked, true);

bool is_enabled = EditorNode::get_singleton()->is_addon_plugin_enabled(name);
const String name = ti->get_metadata(COLUMN_NAME);

if (is_enabled != checked) {
updating = true;
ti->set_checked(COLUMN_STATUS, is_enabled);
updating = false;
const bool old_enabled = EditorNode::get_singleton()->is_addon_plugin_enabled(name);
const bool new_enabled = ti->is_checked(COLUMN_STATUS);
if (old_enabled != new_enabled) {
EditorNode::get_singleton()->set_addon_plugin_enabled(name, new_enabled, true);
if (new_enabled) {
ti->clear_custom_color(COLUMN_NAME);
} else {
ti->set_custom_color(COLUMN_NAME, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
}
}
if (is_enabled) {
ti->clear_custom_color(COLUMN_NAME);
} else {
ti->set_custom_color(COLUMN_NAME, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));

const bool old_debug = EditorNode::get_singleton()->is_addon_debug_enabled(name);
const bool new_debug = ti->is_checked(COLUMN_DEBUG);
if (old_debug != new_debug) {
EditorNode::get_singleton()->set_addon_debug_enabled(name, new_debug);
}
}

Expand Down Expand Up @@ -224,35 +227,40 @@ EditorPluginSettings::EditorPluginSettings() {
plugin_list->set_columns(COLUMN_MAX);
plugin_list->set_column_titles_visible(true);
plugin_list->set_column_title(COLUMN_STATUS, TTR("Enabled"));
plugin_list->set_column_title(COLUMN_DEBUG, TTR("Debug"));
plugin_list->set_column_title(COLUMN_NAME, TTR("Name"));
plugin_list->set_column_title(COLUMN_VERSION, TTR("Version"));
plugin_list->set_column_title(COLUMN_AUTHOR, TTR("Author"));
plugin_list->set_column_title(COLUMN_EDIT, TTR("Edit"));
plugin_list->set_column_title_alignment(COLUMN_STATUS, HORIZONTAL_ALIGNMENT_LEFT);
plugin_list->set_column_title_alignment(COLUMN_DEBUG, HORIZONTAL_ALIGNMENT_LEFT);
plugin_list->set_column_title_alignment(COLUMN_NAME, HORIZONTAL_ALIGNMENT_LEFT);
plugin_list->set_column_title_alignment(COLUMN_VERSION, HORIZONTAL_ALIGNMENT_LEFT);
plugin_list->set_column_title_alignment(COLUMN_AUTHOR, HORIZONTAL_ALIGNMENT_LEFT);
plugin_list->set_column_title_alignment(COLUMN_EDIT, HORIZONTAL_ALIGNMENT_LEFT);
plugin_list->set_column_expand(COLUMN_PADDING_LEFT, false);
plugin_list->set_column_expand(COLUMN_STATUS, false);
plugin_list->set_column_expand(COLUMN_DEBUG, false);
plugin_list->set_column_expand(COLUMN_NAME, true);
plugin_list->set_column_expand(COLUMN_VERSION, false);
plugin_list->set_column_expand(COLUMN_AUTHOR, false);
plugin_list->set_column_expand(COLUMN_EDIT, false);
plugin_list->set_column_expand(COLUMN_PADDING_RIGHT, false);
plugin_list->set_column_clip_content(COLUMN_STATUS, true);
plugin_list->set_column_clip_content(COLUMN_DEBUG, true);
plugin_list->set_column_clip_content(COLUMN_NAME, true);
plugin_list->set_column_clip_content(COLUMN_VERSION, true);
plugin_list->set_column_clip_content(COLUMN_AUTHOR, true);
plugin_list->set_column_clip_content(COLUMN_EDIT, true);
plugin_list->set_column_custom_minimum_width(COLUMN_PADDING_LEFT, 10 * EDSCALE);
plugin_list->set_column_custom_minimum_width(COLUMN_STATUS, 80 * EDSCALE);
plugin_list->set_column_custom_minimum_width(COLUMN_DEBUG, 80 * EDSCALE);
plugin_list->set_column_custom_minimum_width(COLUMN_VERSION, 100 * EDSCALE);
plugin_list->set_column_custom_minimum_width(COLUMN_AUTHOR, 250 * EDSCALE);
plugin_list->set_column_custom_minimum_width(COLUMN_EDIT, 40 * EDSCALE);
plugin_list->set_column_custom_minimum_width(COLUMN_PADDING_RIGHT, 10 * EDSCALE);
plugin_list->set_hide_root(true);
plugin_list->connect("item_edited", callable_mp(this, &EditorPluginSettings::_plugin_activity_changed), CONNECT_DEFERRED);
plugin_list->connect("item_edited", callable_mp(this, &EditorPluginSettings::_plugin_list_item_edited), CONNECT_DEFERRED);

VBoxContainer *mc = memnew(VBoxContainer);
mc->add_child(plugin_list);
Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/editor_plugin_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class EditorPluginSettings : public VBoxContainer {
enum {
COLUMN_PADDING_LEFT,
COLUMN_STATUS,
COLUMN_DEBUG,
COLUMN_NAME,
COLUMN_VERSION,
COLUMN_AUTHOR,
Expand All @@ -58,7 +59,7 @@ class EditorPluginSettings : public VBoxContainer {
Tree *plugin_list = nullptr;
bool updating = false;

void _plugin_activity_changed();
void _plugin_list_item_edited();
void _create_clicked();
void _cell_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);

Expand Down
22 changes: 17 additions & 5 deletions editor/plugins/plugin_config_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void PluginConfigDialog::_clear_fields() {
author_edit->set_text("");
version_edit->set_text("");
script_edit->set_text("");
debug_edit->set_pressed(true);
}

void PluginConfigDialog::_on_confirmed() {
Expand Down Expand Up @@ -310,15 +311,26 @@ PluginConfigDialog::PluginConfigDialog() {
script_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid->add_child(script_edit);

// Debug checkbox
Label *debug_label = memnew(Label);
debug_label->set_text(TTR("Debug:"));
debug_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
grid->add_child(debug_label);

debug_edit = memnew(CheckBox);
debug_edit->set_text(TTR("On"));
debug_edit->set_tooltip_text(TTR("Enable this to restore GDScript warnings for this plugin.\nIt's recommended to enable it for your own plugins and disable for third-party ones."));
debug_edit->set_pressed(true);
grid->add_child(debug_edit);

// Activate now checkbox
Label *active_label = memnew(Label);
active_label->set_text(TTR("Activate now?"));
active_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
grid->add_child(active_label);
plugin_edit_hidden_controls.push_back(active_label);
Control *active_empty = memnew(Control);
grid->add_child(active_empty);
plugin_edit_hidden_controls.push_back(active_empty);

active_edit = memnew(CheckBox);
active_edit->set_pressed(true);
active_edit->set_text(TTR("Activate now?"));
grid->add_child(active_edit);
plugin_edit_hidden_controls.push_back(active_edit);

Expand Down
1 change: 1 addition & 0 deletions editor/plugins/plugin_config_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class PluginConfigDialog : public ConfirmationDialog {
LineEdit *version_edit = nullptr;
OptionButton *script_option_edit = nullptr;
LineEdit *script_edit = nullptr;
CheckBox *debug_edit = nullptr;
CheckBox *active_edit = nullptr;

LocalVector<Control *> plugin_edit_hidden_controls;
Expand Down
5 changes: 5 additions & 0 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,11 @@ void GDScriptLanguage::init() {
_add_global(E.name, E.ptr);
}

#ifdef DEBUG_ENABLED
GDScriptParser::update_project_settings();
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp_static(&GDScriptParser::update_project_settings));
#endif

#ifdef TESTS_ENABLED
GDScriptTests::GDScriptTestRunner::handle_cmdline();
#endif
Expand Down
Loading

0 comments on commit c063ebe

Please sign in to comment.