forked from qt-creator/qt-creator
LanguageClient: prevent assert in semantic highlighter
Do not send messages to server that are not reachable, but queue the highlighting requests until the client is fully initialized. Change-Id: I7da140ec33fb1974d3eaed03110ed85dc3a87594 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -68,12 +68,16 @@ void SemanticTokenSupport::refresh()
|
||||
|
||||
void SemanticTokenSupport::reloadSemanticTokens(TextDocument *textDocument)
|
||||
{
|
||||
if (m_client->reachable())
|
||||
reloadSemanticTokensImpl(textDocument);
|
||||
else
|
||||
queueDocumentReload(textDocument);
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::reloadSemanticTokensImpl(TextDocument *textDocument,
|
||||
int remainingRerequests)
|
||||
{
|
||||
m_docReloadQueue.remove(textDocument);
|
||||
const SemanticRequestTypes supportedRequests = supportedSemanticRequests(textDocument);
|
||||
if (supportedRequests.testFlag(SemanticRequestType::None))
|
||||
return;
|
||||
@@ -122,7 +126,10 @@ void SemanticTokenSupport::reloadSemanticTokensImpl(TextDocument *textDocument,
|
||||
|
||||
void SemanticTokenSupport::updateSemanticTokens(TextDocument *textDocument)
|
||||
{
|
||||
if (m_client->reachable())
|
||||
updateSemanticTokensImpl(textDocument);
|
||||
else
|
||||
queueDocumentReload(textDocument);
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::updateSemanticTokensImpl(TextDocument *textDocument,
|
||||
@@ -168,6 +175,22 @@ void SemanticTokenSupport::updateSemanticTokensImpl(TextDocument *textDocument,
|
||||
reloadSemanticTokens(textDocument);
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::queueDocumentReload(TextEditor::TextDocument *doc)
|
||||
{
|
||||
if (m_docReloadQueue.contains(doc))
|
||||
return;
|
||||
m_docReloadQueue << doc;
|
||||
connect(
|
||||
m_client,
|
||||
&Client::initialized,
|
||||
this,
|
||||
[this, doc = QPointer<TextDocument>(doc)]() {
|
||||
if (doc)
|
||||
reloadSemanticTokensImpl(doc);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::clearHighlight(TextEditor::TextDocument *doc)
|
||||
{
|
||||
if (m_tokens.contains(doc->filePath())){
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QTextCharFormat>
|
||||
|
||||
#include <functional>
|
||||
@@ -86,6 +87,7 @@ public:
|
||||
private:
|
||||
void reloadSemanticTokensImpl(TextEditor::TextDocument *doc, int remainingRerequests = 3);
|
||||
void updateSemanticTokensImpl(TextEditor::TextDocument *doc, int remainingRerequests = 3);
|
||||
void queueDocumentReload(TextEditor::TextDocument *doc);
|
||||
LanguageServerProtocol::SemanticRequestTypes supportedSemanticRequests(
|
||||
TextEditor::TextDocument *document) const;
|
||||
void handleSemanticTokens(const Utils::FilePath &filePath,
|
||||
@@ -117,6 +119,7 @@ private:
|
||||
SemanticTokensHandler m_tokensHandler;
|
||||
QStringList m_tokenTypeStrings;
|
||||
QStringList m_tokenModifierStrings;
|
||||
QSet<TextEditor::TextDocument *> m_docReloadQueue;
|
||||
};
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
Reference in New Issue
Block a user