From bee2d9bccea940689c7483e04e2384f0144d53ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 15 Jun 2020 09:51:53 +0200 Subject: [PATCH] GDScript LSP: Fix wrong error checks added in #39385 Reverts `latest_client_id` back to 0, as I misunderstood how the client IDs are assigned and, without further testing and debugging, I can't say if this was a bug or a valid default value. Similarly, a `latest_client_id` of -1 is no longer raising an error. Fixes #39548. (cherry picked from commit 786f4ada35a491fb75cdb14f2f34085e4adb8668) --- .../gdscript/language_server/gdscript_language_protocol.cpp | 6 ++---- .../gdscript/language_server/gdscript_language_protocol.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index b49bbf38d147..33397a9a6033 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -191,9 +191,7 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) { params["path"] = workspace->root; Dictionary request = make_notification("gdscript_client/changeWorkspace", params); - ERR_FAIL_COND_V_MSG(latest_client_id == -1, ret.to_json(), - "GDScriptLanguageProtocol: Can't initialize as no client is connected."); - ERR_FAIL_INDEX_V_MSG((uint64_t)latest_client_id, clients.size(), ret.to_json(), + ERR_FAIL_COND_V_MSG(!clients.has(latest_client_id), ret.to_json(), vformat("GDScriptLanguageProtocol: Can't initialize invalid peer '%d'.", latest_client_id)); Ref peer = clients.get(latest_client_id); if (peer != NULL) { @@ -280,7 +278,7 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia "GDScript LSP: Can't notify client as none was connected."); p_client_id = latest_client_id; } - ERR_FAIL_INDEX((uint64_t)p_client_id, clients.size()); + ERR_FAIL_COND(!clients.has(p_client_id)); Ref peer = clients.get(p_client_id); ERR_FAIL_COND(peer == NULL); diff --git a/modules/gdscript/language_server/gdscript_language_protocol.h b/modules/gdscript/language_server/gdscript_language_protocol.h index 5e1a5763b9e7..af789edecabd 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.h +++ b/modules/gdscript/language_server/gdscript_language_protocol.h @@ -70,7 +70,7 @@ class GDScriptLanguageProtocol : public JSONRPC { HashMap > clients; Ref server; - int latest_client_id = -1; + int latest_client_id = 0; int next_client_id = 0; Ref text_document;