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

[DAP] Add --dap-port as a command line argument #92336

Merged
merged 1 commit into from
May 30, 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
8 changes: 5 additions & 3 deletions editor/debugger/debug_adapter/debug_adapter_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"

int DebugAdapterServer::port_override = -1;

DebugAdapterServer::DebugAdapterServer() {
_EDITOR_DEF("network/debug_adapter/remote_port", remote_port);
_EDITOR_DEF("network/debug_adapter/request_timeout", protocol._request_timeout);
Expand Down Expand Up @@ -67,7 +69,7 @@ void DebugAdapterServer::_notification(int p_what) {
}
protocol._request_timeout = EDITOR_GET("network/debug_adapter/request_timeout");
protocol._sync_breakpoints = EDITOR_GET("network/debug_adapter/sync_breakpoints");
int port = _EDITOR_GET("network/debug_adapter/remote_port");
int port = (DebugAdapterServer::port_override > -1) ? DebugAdapterServer::port_override : (int)_EDITOR_GET("network/debug_adapter/remote_port");
if (port != remote_port) {
stop();
start();
Expand All @@ -77,9 +79,9 @@ void DebugAdapterServer::_notification(int p_what) {
}

void DebugAdapterServer::start() {
remote_port = (int)_EDITOR_GET("network/debug_adapter/remote_port");
remote_port = (DebugAdapterServer::port_override > -1) ? DebugAdapterServer::port_override : (int)_EDITOR_GET("network/debug_adapter/remote_port");
if (protocol.start(remote_port, IPAddress("127.0.0.1")) == OK) {
EditorNode::get_log()->add_message("--- Debug adapter server started ---", EditorLog::MSG_TYPE_EDITOR);
EditorNode::get_log()->add_message("--- Debug adapter server started on port " + itos(remote_port) + " ---", EditorLog::MSG_TYPE_EDITOR);
set_process_internal(true);
started = true;
}
Expand Down
1 change: 1 addition & 0 deletions editor/debugger/debug_adapter/debug_adapter_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DebugAdapterServer : public EditorPlugin {
void _notification(int p_what);

public:
static int port_override;
DebugAdapterServer();
void start();
void stop();
Expand Down
19 changes: 18 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#endif

#ifdef TOOLS_ENABLED
#include "editor/debugger/debug_adapter/debug_adapter_server.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/doc_data_class_path.gen.h"
#include "editor/doc_tools.h"
Expand Down Expand Up @@ -518,8 +519,9 @@ void Main::print_help(const char *p_binary) {
print_help_option("-e, --editor", "Start the editor instead of running the scene.\n", CLI_OPTION_AVAILABILITY_EDITOR);
print_help_option("-p, --project-manager", "Start the project manager, even if a project is auto-detected.\n", CLI_OPTION_AVAILABILITY_EDITOR);
print_help_option("--debug-server <uri>", "Start the editor debug server (<protocol>://<host/IP>[:port], e.g. tcp://127.0.0.1:6007)\n", CLI_OPTION_AVAILABILITY_EDITOR);
print_help_option("--dap-port <port>", "Use the specified port for the GDScript Debugger Adaptor protocol. Recommended port range [1024, 49151].\n", CLI_OPTION_AVAILABILITY_EDITOR);
#if defined(MODULE_GDSCRIPT_ENABLED) && !defined(GDSCRIPT_NO_LSP)
print_help_option("--lsp-port <port>", "Use the specified port for the GDScript language server protocol. The port should be between 1025 and 49150.\n", CLI_OPTION_AVAILABILITY_EDITOR);
print_help_option("--lsp-port <port>", "Use the specified port for the GDScript language server protocol. Recommended port range [1024, 49151].\n", CLI_OPTION_AVAILABILITY_EDITOR);
#endif // MODULE_GDSCRIPT_ENABLED && !GDSCRIPT_NO_LSP
#endif
print_help_option("--quit", "Quit after the first iteration.\n");
Expand Down Expand Up @@ -1714,6 +1716,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
goto error;
}
#endif // TOOLS_ENABLED && MODULE_GDSCRIPT_ENABLED && !GDSCRIPT_NO_LSP
#if defined(TOOLS_ENABLED)
} else if (arg == "--dap-port") {
if (N) {
int port_override = N->get().to_int();
if (port_override < 0 || port_override > 65535) {
OS::get_singleton()->print("<port> argument for --dap-port <port> must be between 0 and 65535.\n");
van800 marked this conversation as resolved.
Show resolved Hide resolved
goto error;
}
DebugAdapterServer::port_override = port_override;
N = N->next();
} else {
OS::get_singleton()->print("Missing <port> argument for --dap-port <port>.\n");
goto error;
}
#endif // TOOLS_ENABLED
} else if (arg == "--" || arg == "++") {
adding_user_args = true;
} else {
Expand Down
Loading