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:
David Schulz
2021-07-05 09:45:44 +02:00
parent e4376e6b3d
commit 5d33982513

View File

@@ -39,10 +39,11 @@ using namespace LanguageServerProtocol;
using namespace TextEditor;
namespace LanguageClient {
namespace SemanticHighligtingSupport {
static Q_LOGGING_CATEGORY(LOGLSPHIGHLIGHT, "qtc.languageclient.highlight", QtWarningMsg);
namespace SemanticHighligtingSupport {
static const QList<QList<QString>> highlightScopes(const ServerCapabilities &capabilities)
{
return capabilities.semanticHighlighting()
@@ -399,15 +400,27 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
newData.reserve(newDataSize);
auto it = data.begin();
const auto end = data.end();
for (const SemanticTokensEdit &edit : qAsConst(edits)) {
if (edit.start() > data.size()) // prevent edits after the previously reported data
return;
for (const auto start = data.begin() + edit.start(); it < start; ++it)
newData.append(*it);
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;
}
for (const auto end = data.end(); it != end; ++it)
it += deleteCount;
}
for (; it != end; ++it)
newData.append(*it);
tokens.setData(newData);