1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-20 14:45:44 +00:00

Open source code errors in external editor

This commit is contained in:
kobewi
2025-10-31 23:12:21 +01:00
parent 08705259f2
commit edceae18a1
3 changed files with 82 additions and 65 deletions

View File

@@ -2554,63 +2554,11 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
if (use_external_editor &&
(EditorDebuggerNode::get_singleton()->get_dump_stack_script() != p_resource || EditorDebuggerNode::get_singleton()->get_debug_with_external_editor()) &&
p_resource->get_path().is_resource_file()) {
String path = EDITOR_GET("text_editor/external/exec_path");
String flags = EDITOR_GET("text_editor/external/exec_flags");
List<String> args;
bool has_file_flag = false;
String script_path = ProjectSettings::get_singleton()->globalize_path(p_resource->get_path());
if (flags.size()) {
String project_path = ProjectSettings::get_singleton()->get_resource_path();
flags = flags.replacen("{line}", itos(MAX(p_line + 1, 1)));
flags = flags.replacen("{col}", itos(p_col + 1));
flags = flags.strip_edges().replace("\\\\", "\\");
int from = 0;
int num_chars = 0;
bool inside_quotes = false;
for (int i = 0; i < flags.size(); i++) {
if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) {
if (!inside_quotes) {
from++;
}
inside_quotes = !inside_quotes;
} else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) {
String arg = flags.substr(from, num_chars);
if (arg.contains("{file}")) {
has_file_flag = true;
}
// do path replacement here, else there will be issues with spaces and quotes
arg = arg.replacen("{project}", project_path);
arg = arg.replacen("{file}", script_path);
args.push_back(arg);
from = i + 1;
num_chars = 0;
} else {
num_chars++;
}
}
if (ScriptEditorPlugin::open_in_external_editor(ProjectSettings::get_singleton()->globalize_path(p_resource->get_path()), p_line, p_col)) {
return false;
} else {
ERR_PRINT("Couldn't open external text editor, falling back to the internal editor. Review your `text_editor/external/` editor settings.");
}
// Default to passing script path if no {file} flag is specified.
if (!has_file_flag) {
args.push_back(script_path);
}
if (!path.is_empty()) {
Error err = OS::get_singleton()->create_process(path, args);
if (err == OK) {
return false;
}
}
ERR_PRINT("Couldn't open external text editor, falling back to the internal editor. Review your `text_editor/external/` editor settings.");
}
for (int i = 0; i < tab_container->get_tab_count(); i++) {
@@ -4629,6 +4577,63 @@ void ScriptEditorPlugin::_notification(int p_what) {
}
}
bool ScriptEditorPlugin::open_in_external_editor(const String &p_path, int p_line, int p_col, bool p_ignore_project) {
const String path = EDITOR_GET("text_editor/external/exec_path");
if (path.is_empty()) {
return false;
}
String flags = EDITOR_GET("text_editor/external/exec_flags");
List<String> args;
bool has_file_flag = false;
if (!flags.is_empty()) {
flags = flags.replacen("{line}", itos(MAX(p_line + 1, 1)));
flags = flags.replacen("{col}", itos(p_col + 1));
flags = flags.strip_edges().replace("\\\\", "\\");
int from = 0;
int num_chars = 0;
bool inside_quotes = false;
for (int i = 0; i < flags.size(); i++) {
if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) {
if (!inside_quotes) {
from++;
}
inside_quotes = !inside_quotes;
} else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) {
String arg = flags.substr(from, num_chars);
if (arg.contains("{file}")) {
has_file_flag = true;
}
// Do path replacement here, else there will be issues with spaces and quotes
if (p_ignore_project) {
arg = arg.replacen("{project}", String());
} else {
arg = arg.replacen("{project}", ProjectSettings::get_singleton()->get_resource_path());
}
arg = arg.replacen("{file}", p_path);
args.push_back(arg);
from = i + 1;
num_chars = 0;
} else {
num_chars++;
}
}
}
// Default to passing script path if no {file} flag is specified.
if (!has_file_flag) {
args.push_back(p_path);
}
return OS::get_singleton()->create_process(path, args) == OK;
}
void ScriptEditorPlugin::edit(Object *p_object) {
if (Object::cast_to<Script>(p_object)) {
Script *p_script = Object::cast_to<Script>(p_object);