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