Merge pull request #89284 from mihe/lsp-multiple-messages
Allow LSP to process multiple messages per poll
This commit is contained in:
commit
877cd12da8
|
@ -105,7 +105,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.is_empty()) {
|
while (!res_queue.is_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);
|
||||||
|
@ -229,7 +229,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();
|
||||||
}
|
}
|
||||||
|
@ -244,16 +246,22 @@ void GDScriptLanguageProtocol::poll() {
|
||||||
E = clients.begin();
|
E = clients.begin();
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (peer->connection->get_available_bytes() > 0) {
|
Error err = OK;
|
||||||
|
while (peer->connection->get_available_bytes() > 0) {
|
||||||
latest_client_id = E->key;
|
latest_client_id = E->key;
|
||||||
Error err = peer->handle_data();
|
err = peer->handle_data();
|
||||||
|
if (err != OK || OS::get_singleton()->get_ticks_usec() >= target_ticks) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (err != OK && err != ERR_BUSY) {
|
if (err != OK && err != ERR_BUSY) {
|
||||||
on_client_disconnected(E->key);
|
on_client_disconnected(E->key);
|
||||||
E = clients.begin();
|
E = clients.begin();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Error err = peer->send_data();
|
err = peer->send_data();
|
||||||
if (err != OK && err != ERR_BUSY) {
|
if (err != OK && err != ERR_BUSY) {
|
||||||
on_client_disconnected(E->key);
|
on_client_disconnected(E->key);
|
||||||
E = clients.begin();
|
E = clients.begin();
|
||||||
|
|
|
@ -105,7 +105,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 IPAddress &p_bind_ip);
|
Error start(int p_port, const IPAddress &p_bind_ip);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,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) {
|
||||||
|
@ -58,7 +59,7 @@ void GDScriptLanguageServer::_notification(int p_what) {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -70,7 +71,8 @@ void GDScriptLanguageServer::_notification(int p_what) {
|
||||||
String remote_host = String(_EDITOR_GET("network/language_server/remote_host"));
|
String remote_host = String(_EDITOR_GET("network/language_server/remote_host"));
|
||||||
int remote_port = (GDScriptLanguageServer::port_override > -1) ? GDScriptLanguageServer::port_override : (int)_EDITOR_GET("network/language_server/remote_port");
|
int remote_port = (GDScriptLanguageServer::port_override > -1) ? GDScriptLanguageServer::port_override : (int)_EDITOR_GET("network/language_server/remote_port");
|
||||||
bool remote_use_thread = (bool)_EDITOR_GET("network/language_server/use_thread");
|
bool remote_use_thread = (bool)_EDITOR_GET("network/language_server/use_thread");
|
||||||
if (remote_host != host || remote_port != port || remote_use_thread != use_thread) {
|
int remote_poll_limit = (int)_EDITOR_GET("network/language_server/poll_limit_usec");
|
||||||
|
if (remote_host != host || remote_port != port || remote_use_thread != use_thread || remote_poll_limit != poll_limit_usec) {
|
||||||
stop();
|
stop();
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +85,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +94,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 (protocol.start(port, IPAddress(host)) == OK) {
|
if (protocol.start(port, IPAddress(host)) == OK) {
|
||||||
EditorNode::get_log()->add_message("--- GDScript language server started on port " + itos(port) + " ---", 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) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ class GDScriptLanguageServer : public EditorPlugin {
|
||||||
bool use_thread = false;
|
bool use_thread = false;
|
||||||
String host = "127.0.0.1";
|
String host = "127.0.0.1";
|
||||||
int port = 6005;
|
int port = 6005;
|
||||||
|
int poll_limit_usec = 100000;
|
||||||
static void thread_main(void *p_userdata);
|
static void thread_main(void *p_userdata);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue