From ecf6620ab7d61f98e5c998fb0e12de1c16399e53 Mon Sep 17 00:00:00 2001 From: Ivan Shakhov Date: Fri, 15 Aug 2025 15:36:06 +0200 Subject: [PATCH] Extend DAP to allow debug main/current/specific_scene and also commanline arguments - fix https://github.com/godotengine/godot-proposals/discussions/12121 Co-authored-by: Artemy Fedotov <47072685+fstxz@users.noreply.github.com> Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- .../debug_adapter/debug_adapter_parser.cpp | 24 ++++++++++++++++++- .../debug_adapter/debug_adapter_parser.h | 1 + editor/run/editor_run_bar.cpp | 6 ++--- editor/run/editor_run_bar.h | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp index a98f3911230..5351d5c966f 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp @@ -184,6 +184,20 @@ Dictionary DebugAdapterParser::req_launch(const Dictionary &p_params) const { return Dictionary(); } +Vector DebugAdapterParser::_extract_play_arguments(const Dictionary &p_args) const { + Vector play_args; + if (p_args.has("playArgs")) { + Variant v = p_args["playArgs"]; + if (v.get_type() == Variant::ARRAY) { + Array arr = v; + for (const Variant &arg : arr) { + play_args.push_back(String(arg)); + } + } + } + return play_args; +} + Dictionary DebugAdapterParser::_launch_process(const Dictionary &p_params) const { Dictionary args = p_params["arguments"]; ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger(); @@ -193,7 +207,15 @@ Dictionary DebugAdapterParser::_launch_process(const Dictionary &p_params) const String platform_string = args.get("platform", "host"); if (platform_string == "host") { - EditorRunBar::get_singleton()->play_main_scene(); + Vector play_args = _extract_play_arguments(args); + const String scene = args.get("scene", "main"); + if (scene == "main") { + EditorRunBar::get_singleton()->play_main_scene(false, play_args); + } else if (scene == "current") { + EditorRunBar::get_singleton()->play_current_scene(false, play_args); + } else { + EditorRunBar::get_singleton()->play_custom_scene(scene, play_args); + } } else { int device = args.get("device", -1); int idx = -1; diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.h b/editor/debugger/debug_adapter/debug_adapter_parser.h index 0691e87f41e..3eee62c8f93 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.h +++ b/editor/debugger/debug_adapter/debug_adapter_parser.h @@ -86,6 +86,7 @@ public: Dictionary req_godot_put_msg(const Dictionary &p_params) const; // Internal requests + Vector _extract_play_arguments(const Dictionary &p_args) const; Dictionary _launch_process(const Dictionary &p_params) const; // Events diff --git a/editor/run/editor_run_bar.cpp b/editor/run/editor_run_bar.cpp index c882b783539..646f3967f68 100644 --- a/editor/run/editor_run_bar.cpp +++ b/editor/run/editor_run_bar.cpp @@ -367,7 +367,7 @@ void EditorRunBar::recovery_mode_reload_project() { EditorNode::get_singleton()->trigger_menu_option(EditorNode::PROJECT_RELOAD_CURRENT_PROJECT, false); } -void EditorRunBar::play_main_scene(bool p_from_native) { +void EditorRunBar::play_main_scene(bool p_from_native, const Vector &p_play_args) { if (Engine::get_singleton()->is_recovery_mode_hint()) { EditorToaster::get_singleton()->popup_str(TTR("Recovery Mode is enabled. Disable it to run the project."), EditorToaster::SEVERITY_WARNING); return; @@ -379,7 +379,7 @@ void EditorRunBar::play_main_scene(bool p_from_native) { stop_playing(); current_mode = RunMode::RUN_MAIN; - _run_scene(); + _run_scene("", p_play_args); } } @@ -574,7 +574,7 @@ EditorRunBar::EditorRunBar() { play_button->set_toggle_mode(true); play_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); play_button->set_tooltip_text(TTRC("Run the project's default scene.")); - play_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::play_main_scene).bind(false)); + play_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::play_main_scene).bind(false, Vector())); ED_SHORTCUT_AND_COMMAND("editor/run_project", TTRC("Run Project"), Key::F5); ED_SHORTCUT_OVERRIDE("editor/run_project", "macos", KeyModifierMask::META | Key::B); diff --git a/editor/run/editor_run_bar.h b/editor/run/editor_run_bar.h index 36b7f4044ad..6f7376a0f02 100644 --- a/editor/run/editor_run_bar.h +++ b/editor/run/editor_run_bar.h @@ -113,7 +113,7 @@ public: void recovery_mode_show_dialog(); void recovery_mode_reload_project(); - void play_main_scene(bool p_from_native = false); + void play_main_scene(bool p_from_native = false, const Vector &p_play_args = Vector()); void play_current_scene(bool p_reload = false, const Vector &p_play_args = Vector()); void play_custom_scene(const String &p_custom, const Vector &p_play_args = Vector());