forked from qt-creator/qt-creator
LanguageClient: Do not update semantic tokens on every document update
Due to the potential cost of the re-highlighting procedure, we'd like to delay the semantic tokens update request to a time where the new token information won't get invalidated right away due to further document changes. While the document updates in principle have such a delay already, it is often "sabotaged", for instance due to auto-completion requests which require the server to know the current document contents right away. Therefore, we request new semantic tokens along with a document update only if it's the "regular" delayed one, and otherwise add an additional delay. Change-Id: I074647d1cdfdbcc6aa5fc5ec2a2d5ae6ccd493ba Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -93,7 +93,8 @@ Client::Client(BaseClientInterface *clientInterface)
|
||||
|
||||
m_documentUpdateTimer.setSingleShot(true);
|
||||
m_documentUpdateTimer.setInterval(500);
|
||||
connect(&m_documentUpdateTimer, &QTimer::timeout, this, &Client::sendPostponedDocumentUpdates);
|
||||
connect(&m_documentUpdateTimer, &QTimer::timeout, this,
|
||||
[this] { sendPostponedDocumentUpdates(SemanticTokensUpdateMode::Now); });
|
||||
|
||||
m_contentHandler.insert(JsonRpcMessageHandler::jsonRpcMimeType(),
|
||||
&JsonRpcMessageHandler::parseContent);
|
||||
@@ -409,7 +410,7 @@ void Client::sendContent(const IContent &content, SendDocUpdates sendUpdates)
|
||||
QTC_ASSERT(m_clientInterface, return);
|
||||
QTC_ASSERT(m_state == Initialized, return);
|
||||
if (sendUpdates == SendDocUpdates::Send)
|
||||
sendPostponedDocumentUpdates();
|
||||
sendPostponedDocumentUpdates(SemanticTokensUpdateMode::Delayed);
|
||||
if (Utils::optional<ResponseHandler> responseHandler = content.responseHandler())
|
||||
m_responseHandlers[responseHandler->id] = responseHandler->callback;
|
||||
QString error;
|
||||
@@ -1215,7 +1216,7 @@ void Client::resetAssistProviders(TextEditor::TextDocument *document)
|
||||
document->setQuickFixAssistProvider(providers.quickFixAssistProvider);
|
||||
}
|
||||
|
||||
void Client::sendPostponedDocumentUpdates()
|
||||
void Client::sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticTokensUpdateMode)
|
||||
{
|
||||
m_documentUpdateTimer.stop();
|
||||
if (m_documentsToUpdate.empty())
|
||||
@@ -1250,7 +1251,15 @@ void Client::sendPostponedDocumentUpdates()
|
||||
if (currentWidget && currentWidget->textDocument() == update.document)
|
||||
requestDocumentHighlights(currentWidget);
|
||||
|
||||
m_tokenSupport.updateSemanticTokens(update.document);
|
||||
if (semanticTokensUpdateMode == SemanticTokensUpdateMode::Now) {
|
||||
m_tokenSupport.updateSemanticTokens(update.document);
|
||||
} else {
|
||||
QTimer::singleShot(m_documentUpdateTimer.interval(), this,
|
||||
[this, doc = QPointer(update.document)] {
|
||||
if (doc && m_documentsToUpdate.find(doc) == m_documentsToUpdate.end())
|
||||
m_tokenSupport.updateSemanticTokens(doc);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user