mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-22 11:56:49 +01:00
Allow LSP to process multiple messages per poll
(cherry-picked from commit e2485044a1b33628e6149d4f930b6fe065743c9d)
This commit is contained in:
parent
18335d938c
commit
bffa53c645
@ -106,7 +106,7 @@ Error GDScriptLanguageProtocol::LSPeer::handle_data() {
|
|||||||
|
|
||||||
Error GDScriptLanguageProtocol::LSPeer::send_data() {
|
Error GDScriptLanguageProtocol::LSPeer::send_data() {
|
||||||
int sent = 0;
|
int sent = 0;
|
||||||
if (!res_queue.empty()) {
|
while (!res_queue.empty()) {
|
||||||
CharString c_res = res_queue[0];
|
CharString c_res = res_queue[0];
|
||||||
if (res_sent < c_res.size()) {
|
if (res_sent < c_res.size()) {
|
||||||
Error err = connection->put_partial_data((const uint8_t *)c_res.get_data() + res_sent, c_res.size() - res_sent - 1, sent);
|
Error err = connection->put_partial_data((const uint8_t *)c_res.get_data() + res_sent, c_res.size() - res_sent - 1, sent);
|
||||||
@ -230,7 +230,9 @@ void GDScriptLanguageProtocol::initialized(const Variant &p_params) {
|
|||||||
notify_client("gdscript/capabilities", capabilities.to_json());
|
notify_client("gdscript/capabilities", capabilities.to_json());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptLanguageProtocol::poll() {
|
void GDScriptLanguageProtocol::poll(int p_limit_usec) {
|
||||||
|
uint64_t target_ticks = OS::get_singleton()->get_ticks_usec() + p_limit_usec;
|
||||||
|
|
||||||
if (server->is_connection_available()) {
|
if (server->is_connection_available()) {
|
||||||
on_client_connected();
|
on_client_connected();
|
||||||
}
|
}
|
||||||
@ -242,15 +244,22 @@ void GDScriptLanguageProtocol::poll() {
|
|||||||
on_client_disconnected(*id);
|
on_client_disconnected(*id);
|
||||||
id = nullptr;
|
id = nullptr;
|
||||||
} else {
|
} else {
|
||||||
if (peer->connection->get_available_bytes() > 0) {
|
Error err = OK;
|
||||||
|
while (peer->connection->get_available_bytes() > 0) {
|
||||||
latest_client_id = *id;
|
latest_client_id = *id;
|
||||||
Error err = peer->handle_data();
|
err = peer->handle_data();
|
||||||
if (err != OK && err != ERR_BUSY) {
|
if (err != OK || OS::get_singleton()->get_ticks_usec() >= target_ticks) {
|
||||||
on_client_disconnected(*id);
|
break;
|
||||||
id = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Error err = peer->send_data();
|
|
||||||
|
if (err != OK && err != ERR_BUSY) {
|
||||||
|
on_client_disconnected(*id);
|
||||||
|
id = nullptr;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = peer->send_data();
|
||||||
if (err != OK && err != ERR_BUSY) {
|
if (err != OK && err != ERR_BUSY) {
|
||||||
on_client_disconnected(*id);
|
on_client_disconnected(*id);
|
||||||
id = nullptr;
|
id = nullptr;
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
_FORCE_INLINE_ Ref<GDScriptTextDocument> get_text_document() { return text_document; }
|
_FORCE_INLINE_ Ref<GDScriptTextDocument> get_text_document() { return text_document; }
|
||||||
_FORCE_INLINE_ bool is_initialized() const { return _initialized; }
|
_FORCE_INLINE_ bool is_initialized() const { return _initialized; }
|
||||||
|
|
||||||
void poll();
|
void poll(int p_limit_usec);
|
||||||
Error start(int p_port, const IP_Address &p_bind_ip);
|
Error start(int p_port, const IP_Address &p_bind_ip);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ GDScriptLanguageServer::GDScriptLanguageServer() {
|
|||||||
use_thread = false;
|
use_thread = false;
|
||||||
host = "127.0.0.1";
|
host = "127.0.0.1";
|
||||||
port = 6008;
|
port = 6008;
|
||||||
|
poll_limit_usec = 100000;
|
||||||
|
|
||||||
_EDITOR_DEF("network/language_server/enabled", enabled, true);
|
_EDITOR_DEF("network/language_server/enabled", enabled, true);
|
||||||
_EDITOR_DEF("network/language_server/remote_host", host);
|
_EDITOR_DEF("network/language_server/remote_host", host);
|
||||||
@ -53,6 +54,7 @@ GDScriptLanguageServer::GDScriptLanguageServer() {
|
|||||||
_EDITOR_DEF("network/language_server/enable_smart_resolve", true);
|
_EDITOR_DEF("network/language_server/enable_smart_resolve", true);
|
||||||
_EDITOR_DEF("network/language_server/show_native_symbols_in_editor", false);
|
_EDITOR_DEF("network/language_server/show_native_symbols_in_editor", false);
|
||||||
_EDITOR_DEF("network/language_server/use_thread", use_thread);
|
_EDITOR_DEF("network/language_server/use_thread", use_thread);
|
||||||
|
_EDITOR_DEF("network/language_server/poll_limit_usec", poll_limit_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptLanguageServer::_notification(int p_what) {
|
void GDScriptLanguageServer::_notification(int p_what) {
|
||||||
@ -65,7 +67,7 @@ void GDScriptLanguageServer::_notification(int p_what) {
|
|||||||
break;
|
break;
|
||||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||||
if (started && !use_thread) {
|
if (started && !use_thread) {
|
||||||
protocol.poll();
|
protocol.poll(poll_limit_usec);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
||||||
@ -76,7 +78,8 @@ void GDScriptLanguageServer::_notification(int p_what) {
|
|||||||
String host = String(_EDITOR_GET("network/language_server/remote_host"));
|
String host = String(_EDITOR_GET("network/language_server/remote_host"));
|
||||||
int port = (GDScriptLanguageServer::port_override > -1) ? GDScriptLanguageServer::port_override : (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) {
|
int remote_poll_limit = (int)_EDITOR_GET("network/language_server/poll_limit_usec");
|
||||||
|
if (host != this->host || port != this->port || use_thread != this->use_thread || remote_poll_limit != poll_limit_usec) {
|
||||||
this->stop();
|
this->stop();
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
@ -88,7 +91,7 @@ void GDScriptLanguageServer::thread_main(void *p_userdata) {
|
|||||||
GDScriptLanguageServer *self = static_cast<GDScriptLanguageServer *>(p_userdata);
|
GDScriptLanguageServer *self = static_cast<GDScriptLanguageServer *>(p_userdata);
|
||||||
while (self->thread_running) {
|
while (self->thread_running) {
|
||||||
// Poll 20 times per second
|
// Poll 20 times per second
|
||||||
self->protocol.poll();
|
self->protocol.poll(self->poll_limit_usec);
|
||||||
OS::get_singleton()->delay_usec(50000);
|
OS::get_singleton()->delay_usec(50000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,6 +101,7 @@ void GDScriptLanguageServer::start() {
|
|||||||
host = String(_EDITOR_GET("network/language_server/remote_host"));
|
host = String(_EDITOR_GET("network/language_server/remote_host"));
|
||||||
port = (GDScriptLanguageServer::port_override > -1) ? GDScriptLanguageServer::port_override : (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");
|
||||||
|
poll_limit_usec = (int)_EDITOR_GET("network/language_server/poll_limit_usec");
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -48,6 +48,7 @@ class GDScriptLanguageServer : public EditorPlugin {
|
|||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
int poll_limit_usec;
|
||||||
|
|
||||||
static void thread_main(void *p_userdata);
|
static void thread_main(void *p_userdata);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user