From 7c79e18831a0961838e020dd3e7d3a7a5907d1d3 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 7 Jul 2022 13:37:26 +0200 Subject: [PATCH] LanguageClient: cancel running semantic token request ... when we are about to send a new semantic token request. Change-Id: Ibd421dd29bf3ea0e2b502c227341ff03259b2370 Reviewed-by: Christian Kandeler --- .../languageclient/semantichighlightsupport.cpp | 10 ++++++++++ src/plugins/languageclient/semantichighlightsupport.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/plugins/languageclient/semantichighlightsupport.cpp b/src/plugins/languageclient/semantichighlightsupport.cpp index 9536052b811..7fbf6645912 100644 --- a/src/plugins/languageclient/semantichighlightsupport.cpp +++ b/src/plugins/languageclient/semantichighlightsupport.cpp @@ -88,6 +88,7 @@ void SemanticTokenSupport::reloadSemanticTokensImpl(TextDocument *textDocument, filePath, documentVersion = m_client->documentVersion(filePath)]( const SemanticTokensFullRequest::Response &response) { + m_runningRequests.remove(filePath); if (const auto error = response.error()) { qCDebug(LOGLSPHIGHLIGHT) << "received error" << error->code() << error->message() << "for" << filePath; @@ -120,6 +121,10 @@ void SemanticTokenSupport::reloadSemanticTokensImpl(TextDocument *textDocument, request.setResponseCallback(responseCallback); qCDebug(LOGLSPHIGHLIGHT) << "Requesting all tokens for" << filePath << "with version" << m_client->documentVersion(filePath); + MessageId &id = m_runningRequests[filePath]; + if (id.isValid()) + m_client->cancelRequest(id); + id = request.id(); m_client->sendMessage(request); } } @@ -151,6 +156,7 @@ void SemanticTokenSupport::updateSemanticTokensImpl(TextDocument *textDocument, request.setResponseCallback( [this, filePath, documentVersion, remainingRerequests]( const SemanticTokensFullDeltaRequest::Response &response) { + m_runningRequests.remove(filePath); if (const auto error = response.error()) { qCDebug(LOGLSPHIGHLIGHT) << "received error" << error->code() << error->message() << "for" << filePath; @@ -168,6 +174,10 @@ void SemanticTokenSupport::updateSemanticTokensImpl(TextDocument *textDocument, }); qCDebug(LOGLSPHIGHLIGHT) << "Requesting delta for" << filePath << "with version" << documentVersion; + MessageId &id = m_runningRequests[filePath]; + if (id.isValid()) + m_client->cancelRequest(id); + id = request.id(); m_client->sendMessage(request); return; } diff --git a/src/plugins/languageclient/semantichighlightsupport.h b/src/plugins/languageclient/semantichighlightsupport.h index a03947c9153..d8314979111 100644 --- a/src/plugins/languageclient/semantichighlightsupport.h +++ b/src/plugins/languageclient/semantichighlightsupport.h @@ -120,6 +120,7 @@ private: QStringList m_tokenTypeStrings; QStringList m_tokenModifierStrings; QSet m_docReloadQueue; + QHash m_runningRequests; }; } // namespace LanguageClient