LanguageClient: more log output in the semantic highlighter

Task-number: QTCREATORBUG-26624
Change-Id: Ib276662f1ce2cf355015258c564f6f9c817a3d8a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-11-26 12:33:11 +01:00
parent 0215a31c4a
commit b38251659b

View File

@@ -191,6 +191,7 @@ SemanticTokenSupport::SemanticTokenSupport(Client *client)
void SemanticTokenSupport::refresh()
{
qCDebug(LOGLSPHIGHLIGHT) << "refresh all semantic highlights for" << m_client->name();
m_tokens.clear();
for (Core::IEditor *editor : Core::EditorManager::visibleEditors())
onCurrentEditorChanged(editor);
@@ -226,6 +227,8 @@ void SemanticTokenSupport::reloadSemanticTokens(TextDocument *textDocument)
params.setTextDocument(docId);
SemanticTokensFullRequest request(params);
request.setResponseCallback(responseCallback);
qCDebug(LOGLSPHIGHLIGHT) << "Requesting all tokens for" << filePath << "with version"
<< m_client->documentVersion(filePath);
m_client->sendContent(request);
}
}
@@ -238,19 +241,22 @@ void SemanticTokenSupport::updateSemanticTokens(TextDocument *textDocument)
const VersionedTokens versionedToken = m_tokens.value(filePath);
const QString &previousResultId = versionedToken.tokens.resultId().value_or(QString());
if (!previousResultId.isEmpty()) {
if (m_client->documentVersion(filePath) == versionedToken.version)
const int documentVersion = m_client->documentVersion(filePath);
if (documentVersion == versionedToken.version)
return;
SemanticTokensDeltaParams params;
params.setTextDocument(TextDocumentIdentifier(DocumentUri::fromFilePath(filePath)));
params.setPreviousResultId(previousResultId);
SemanticTokensFullDeltaRequest request(params);
request.setResponseCallback(
[this, filePath, documentVersion = m_client->documentVersion(filePath)](
[this, filePath, documentVersion](
const SemanticTokensFullDeltaRequest::Response &response) {
handleSemanticTokensDelta(filePath,
response.result().value_or(nullptr),
documentVersion);
});
qCDebug(LOGLSPHIGHLIGHT)
<< "Requesting delta for" << filePath << "with version" << documentVersion;
m_client->sendContent(request);
return;
}
@@ -411,8 +417,10 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
const LanguageServerProtocol::SemanticTokensDeltaResult &result,
int documentVersion)
{
qCDebug(LOGLSPHIGHLIGHT) << "Handle Tokens for " << filePath;
if (auto tokens = Utils::get_if<SemanticTokens>(&result)) {
m_tokens[filePath] = {*tokens, documentVersion};
qCDebug(LOGLSPHIGHLIGHT) << "New Data " << tokens->data();
} else if (auto tokensDelta = Utils::get_if<SemanticTokensDelta>(&result)) {
m_tokens[filePath].version = documentVersion;
QList<SemanticTokensEdit> edits = tokensDelta->edits();
@@ -434,7 +442,7 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
auto it = data.begin();
const auto end = data.end();
qCDebug(LOGLSPHIGHLIGHT) << "Edit Tokens for " << filePath;
qCDebug(LOGLSPHIGHLIGHT) << "Edit Tokens";
qCDebug(LOGLSPHIGHLIGHT) << "Data before edit " << data;
for (const SemanticTokensEdit &edit : qAsConst(edits)) {
if (edit.start() > data.size()) // prevent edits after the previously reported data
@@ -469,6 +477,7 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
tokens.setResultId(tokensDelta->resultId());
} else {
m_tokens.remove(filePath);
qCDebug(LOGLSPHIGHLIGHT) << "Data cleared";
return;
}
highlight(filePath);
@@ -476,6 +485,7 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
void SemanticTokenSupport::highlight(const Utils::FilePath &filePath, bool force)
{
qCDebug(LOGLSPHIGHLIGHT) << "highlight" << filePath;
TextDocument *doc = TextDocument::textDocumentForFilePath(filePath);
if (!doc || LanguageClientManager::clientForDocument(doc) != m_client)
return;
@@ -486,6 +496,7 @@ void SemanticTokenSupport::highlight(const Utils::FilePath &filePath, bool force
const QList<SemanticToken> tokens = versionedTokens.tokens
.toTokens(m_tokenTypes, m_tokenModifiers);
if (m_tokensHandler) {
qCDebug(LOGLSPHIGHLIGHT) << "use tokens handler" << filePath;
int line = 1;
int column = 1;
QList<ExpandedSemanticToken> expandedTokens;