Add a menu action to open C++ source on GitHub in the editor debugger

This helps user find back the source code where the error/warning
was emitted from.
This commit is contained in:
Hugo Locurcio 2021-04-18 02:07:05 +02:00
parent 0ee744ff5f
commit 5bc746e60a
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
2 changed files with 66 additions and 24 deletions

View file

@ -35,6 +35,8 @@
#include "core/debugger/remote_debugger.h"
#include "core/io/marshalls.h"
#include "core/string/ustring.h"
#include "core/version.h"
#include "core/version_hash.gen.h"
#include "editor/debugger/editor_network_profiler.h"
#include "editor/debugger/editor_performance_profiler.h"
#include "editor/debugger/editor_profiler.h"
@ -1371,7 +1373,8 @@ void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
item_menu->set_size(Size2(1, 1));
if (error_tree->is_anything_selected()) {
item_menu->add_icon_item(get_theme_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), 0);
item_menu->add_icon_item(get_theme_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), ACTION_COPY_ERROR);
item_menu->add_icon_item(get_theme_icon("Instance", "EditorIcons"), TTR("Open C++ Source on GitHub"), ACTION_OPEN_SOURCE);
}
if (item_menu->get_item_count() > 0) {
@ -1381,6 +1384,8 @@ void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
}
void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
switch (p_option) {
case ACTION_COPY_ERROR: {
TreeItem *ti = error_tree->get_selected();
while (ti->get_parent() != error_tree->get_root()) {
ti = ti->get_parent();
@ -1405,6 +1410,38 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
}
DisplayServer::get_singleton()->clipboard_set(text);
} break;
case ACTION_OPEN_SOURCE: {
TreeItem *ti = error_tree->get_selected();
while (ti->get_parent() != error_tree->get_root()) {
ti = ti->get_parent();
}
// We only need the first child here (C++ source stack trace).
TreeItem *ci = ti->get_children();
// Parse back the `file:line @ method()` string.
const Vector<String> file_line_number = ci->get_text(1).split("@")[0].strip_edges().split(":");
ERR_FAIL_COND_MSG(file_line_number.size() < 2, "Incorrect C++ source stack trace file:line format (please report).");
const String file = file_line_number[0];
const int line_number = file_line_number[1].to_int();
// Construct a GitHub repository URL and open it in the user's default web browser.
if (String(VERSION_HASH).length() >= 1) {
// Git commit hash information available; use it for greater accuracy, including for development versions.
OS::get_singleton()->shell_open(vformat("https://github.com/godotengine/godot/blob/%s/%s#L%d",
VERSION_HASH,
file,
line_number));
} else {
// Git commit hash information unavailable; fall back to tagged releases.
OS::get_singleton()->shell_open(vformat("https://github.com/godotengine/godot/blob/%s-stable/%s#L%d",
VERSION_NUMBER,
file,
line_number));
}
} break;
}
}
void ScriptEditorDebugger::_tab_changed(int p_tab) {

View file

@ -74,6 +74,11 @@ private:
PROFILER_SCRIPTS_SERVERS
};
enum Actions {
ACTION_COPY_ERROR,
ACTION_OPEN_SOURCE,
};
AcceptDialog *msgdialog;
LineEdit *clicked_ctrl;