forked from qt-creator/qt-creator
LSP: reload semantic token if we encounter corrupted data
Change-Id: I73185b0b7be57d348fc1a461b1db0383313d7208 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -39,10 +39,11 @@ using namespace LanguageServerProtocol;
|
|||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace LanguageClient {
|
namespace LanguageClient {
|
||||||
namespace SemanticHighligtingSupport {
|
|
||||||
|
|
||||||
static Q_LOGGING_CATEGORY(LOGLSPHIGHLIGHT, "qtc.languageclient.highlight", QtWarningMsg);
|
static Q_LOGGING_CATEGORY(LOGLSPHIGHLIGHT, "qtc.languageclient.highlight", QtWarningMsg);
|
||||||
|
|
||||||
|
namespace SemanticHighligtingSupport {
|
||||||
|
|
||||||
static const QList<QList<QString>> highlightScopes(const ServerCapabilities &capabilities)
|
static const QList<QList<QString>> highlightScopes(const ServerCapabilities &capabilities)
|
||||||
{
|
{
|
||||||
return capabilities.semanticHighlighting()
|
return capabilities.semanticHighlighting()
|
||||||
@@ -399,15 +400,27 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
|
|||||||
newData.reserve(newDataSize);
|
newData.reserve(newDataSize);
|
||||||
|
|
||||||
auto it = data.begin();
|
auto it = data.begin();
|
||||||
|
const auto end = data.end();
|
||||||
for (const SemanticTokensEdit &edit : qAsConst(edits)) {
|
for (const SemanticTokensEdit &edit : qAsConst(edits)) {
|
||||||
if (edit.start() > data.size()) // prevent edits after the previously reported data
|
if (edit.start() > data.size()) // prevent edits after the previously reported data
|
||||||
return;
|
return;
|
||||||
for (const auto start = data.begin() + edit.start(); it < start; ++it)
|
for (const auto start = data.begin() + edit.start(); it < start; ++it)
|
||||||
newData.append(*it);
|
newData.append(*it);
|
||||||
newData.append(edit.data().value_or(QList<int>()));
|
newData.append(edit.data().value_or(QList<int>()));
|
||||||
it += edit.deleteCount();
|
int deleteCount = edit.deleteCount();
|
||||||
|
if (deleteCount > std::distance(it, end)) {
|
||||||
|
qCDebug(LOGLSPHIGHLIGHT)
|
||||||
|
<< "We shall delete more highlight data entries than we actually have, "
|
||||||
|
"so we are out of sync with the server. "
|
||||||
|
"Request full semantic tokens again.";
|
||||||
|
TextDocument *doc = TextDocument::textDocumentForFilePath(filePath);
|
||||||
|
if (doc && LanguageClientManager::clientForDocument(doc) == m_client)
|
||||||
|
reloadSemanticTokens(doc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
it += deleteCount;
|
||||||
}
|
}
|
||||||
for (const auto end = data.end(); it != end; ++it)
|
for (; it != end; ++it)
|
||||||
newData.append(*it);
|
newData.append(*it);
|
||||||
|
|
||||||
tokens.setData(newData);
|
tokens.setData(newData);
|
||||||
|
Reference in New Issue
Block a user