[3.x] Add --lsp-port as a command line argument

This commit is contained in:
ryanabx 2023-09-17 22:09:18 -05:00
parent ddba96755f
commit 22c9ac1540
3 changed files with 30 additions and 4 deletions

View file

@ -86,6 +86,12 @@
#endif #endif
#endif #endif
#ifdef MODULE_GDSCRIPT_ENABLED
#if defined(TOOLS_ENABLED) && !defined(GDSCRIPT_NO_LSP)
#include "modules/gdscript/language_server/gdscript_language_server.h"
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
#endif // MODULE_GDSCRIPT_ENABLED
/* Static members */ /* Static members */
// Singletons // Singletons
@ -268,6 +274,9 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" -e, --editor Start the editor instead of running the scene.\n"); OS::get_singleton()->print(" -e, --editor Start the editor instead of running the scene.\n");
OS::get_singleton()->print(" -p, --project-manager Start the project manager, even if a project is auto-detected.\n"); OS::get_singleton()->print(" -p, --project-manager Start the project manager, even if a project is auto-detected.\n");
OS::get_singleton()->print(" --debug-server <address> Start the editor debug server (<IP>:<port>, e.g. 127.0.0.1:6007)\n"); OS::get_singleton()->print(" --debug-server <address> Start the editor debug server (<IP>:<port>, e.g. 127.0.0.1:6007)\n");
#if defined(MODULE_GDSCRIPT_ENABLED) && !defined(GDSCRIPT_NO_LSP)
OS::get_singleton()->print(" --lsp-port <port> Use the specified port for the language server protocol. The port must be between 0 to 65535.\n");
#endif // MODULE_GDSCRIPT_ENABLED && !GDSCRIPT_NO_LSP
#endif #endif
OS::get_singleton()->print(" -q, --quit Quit after the first iteration.\n"); OS::get_singleton()->print(" -q, --quit Quit after the first iteration.\n");
OS::get_singleton()->print(" -l, --language <locale> Use a specific locale (<locale> being a two-letter code).\n"); OS::get_singleton()->print(" -l, --language <locale> Use a specific locale (<locale> being a two-letter code).\n");
@ -941,7 +950,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing <path> argument for --benchmark-file <path>.\n"); OS::get_singleton()->print("Missing <path> argument for --benchmark-file <path>.\n");
goto error; goto error;
} }
#if defined(TOOLS_ENABLED) && !defined(GDSCRIPT_NO_LSP)
} else if (I->get() == "--lsp-port") {
if (I->next()) {
int port_override = I->next()->get().to_int();
if (port_override < 0 || port_override > 65535) {
OS::get_singleton()->print("<port> argument for --lsp-port <port> must be between 0 and 65535.\n");
goto error;
}
GDScriptLanguageServer::port_override = port_override;
N = I->next()->next();
} else {
OS::get_singleton()->print("Missing <port> argument for --lsp-port <port>.\n");
goto error;
}
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
} else { } else {
main_args.push_back(I->get()); main_args.push_back(I->get());
} }

View file

@ -35,6 +35,8 @@
#include "editor/editor_log.h" #include "editor/editor_log.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
int GDScriptLanguageServer::port_override = -1;
GDScriptLanguageServer::GDScriptLanguageServer() { GDScriptLanguageServer::GDScriptLanguageServer() {
thread_running = false; thread_running = false;
started = false; started = false;
@ -64,7 +66,7 @@ void GDScriptLanguageServer::_notification(int p_what) {
} break; } break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
String host = String(_EDITOR_GET("network/language_server/remote_host")); String host = String(_EDITOR_GET("network/language_server/remote_host"));
int port = (int)_EDITOR_GET("network/language_server/remote_port"); int port = (GDScriptLanguageServer::port_override > -1) ? GDScriptLanguageServer::port_override : (int)_EDITOR_GET("network/language_server/remote_port");
bool use_thread = (bool)_EDITOR_GET("network/language_server/use_thread"); bool use_thread = (bool)_EDITOR_GET("network/language_server/use_thread");
if (host != this->host || port != this->port || use_thread != this->use_thread) { if (host != this->host || port != this->port || use_thread != this->use_thread) {
this->stop(); this->stop();
@ -85,10 +87,10 @@ void GDScriptLanguageServer::thread_main(void *p_userdata) {
void GDScriptLanguageServer::start() { void GDScriptLanguageServer::start() {
host = String(_EDITOR_GET("network/language_server/remote_host")); host = String(_EDITOR_GET("network/language_server/remote_host"));
port = (int)_EDITOR_GET("network/language_server/remote_port"); port = (GDScriptLanguageServer::port_override > -1) ? GDScriptLanguageServer::port_override : (int)_EDITOR_GET("network/language_server/remote_port");
use_thread = (bool)_EDITOR_GET("network/language_server/use_thread"); use_thread = (bool)_EDITOR_GET("network/language_server/use_thread");
if (protocol.start(port, IP_Address(host)) == OK) { if (protocol.start(port, IP_Address(host)) == OK) {
EditorNode::get_log()->add_message("--- GDScript language server started ---", EditorLog::MSG_TYPE_EDITOR); EditorNode::get_log()->add_message("--- GDScript language server started on port " + itos(port) + " ---", EditorLog::MSG_TYPE_EDITOR);
if (use_thread) { if (use_thread) {
thread_running = true; thread_running = true;
thread.start(GDScriptLanguageServer::thread_main, this); thread.start(GDScriptLanguageServer::thread_main, this);

View file

@ -52,6 +52,7 @@ private:
void _notification(int p_what); void _notification(int p_what);
public: public:
static int port_override;
GDScriptLanguageServer(); GDScriptLanguageServer();
void start(); void start();
void stop(); void stop();