forked from qt-creator/qt-creator
LanguageClient: support semanticTokens/refresh
Fixes: QTCREATORBUG-26499 Change-Id: Icd5879609bb856797fa223394357a1f15554d2cf Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -170,6 +170,9 @@ static ClientCapabilities generateClientCapabilities()
|
||||
workspaceCapabilities.setDidChangeConfiguration(allowDynamicRegistration);
|
||||
workspaceCapabilities.setExecuteCommand(allowDynamicRegistration);
|
||||
workspaceCapabilities.setConfiguration(true);
|
||||
SemanticTokensWorkspaceClientCapabilities semanticTokensWorkspaceClientCapabilities;
|
||||
semanticTokensWorkspaceClientCapabilities.setRefreshSupport(true);
|
||||
workspaceCapabilities.setSemanticTokens(semanticTokensWorkspaceClientCapabilities);
|
||||
capabilities.setWorkspace(workspaceCapabilities);
|
||||
|
||||
TextDocumentClientCapabilities documentCapabilities;
|
||||
@@ -1363,6 +1366,11 @@ void Client::handleMethod(const QString &method, const MessageId &id, const ICon
|
||||
dynamic_cast<const WorkDoneProgressCreateRequest *>(content)->id());
|
||||
response.setResult(nullptr);
|
||||
sendContent(response);
|
||||
} else if (method == SemanticTokensRefreshRequest::methodName) {
|
||||
m_tokenSupport.refresh();
|
||||
Response<std::nullptr_t, JsonObject> response(id);
|
||||
response.setResult(nullptr);
|
||||
sendContent(response);
|
||||
} else if (method == ProgressNotification::methodName) {
|
||||
if (Utils::optional<ProgressParams> params
|
||||
= dynamic_cast<const ProgressNotification *>(content)->params()) {
|
||||
|
||||
@@ -71,6 +71,7 @@ LanguageClientManager::LanguageClientManager(QObject *parent)
|
||||
JsonRpcMessageHandler::registerMessageProvider<UnregisterCapabilityRequest>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<WorkDoneProgressCreateRequest>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<ProgressNotification>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<SemanticTokensRefreshRequest>();
|
||||
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
||||
this, &LanguageClientManager::editorOpened);
|
||||
connect(EditorManager::instance(), &EditorManager::documentOpened,
|
||||
|
||||
@@ -183,6 +183,17 @@ SemanticTokenSupport::SemanticTokenSupport(Client *client)
|
||||
&TextEditorSettings::fontSettingsChanged,
|
||||
client,
|
||||
[this]() { updateFormatHash(); });
|
||||
QObject::connect(Core::EditorManager::instance(),
|
||||
&Core::EditorManager::currentEditorChanged,
|
||||
this,
|
||||
&SemanticTokenSupport::onCurrentEditorChanged);
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::refresh()
|
||||
{
|
||||
m_tokens.clear();
|
||||
for (Core::IEditor *editor : Core::EditorManager::visibleEditors())
|
||||
onCurrentEditorChanged(editor);
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::reloadSemanticTokens(TextDocument *textDocument)
|
||||
@@ -224,8 +235,11 @@ void SemanticTokenSupport::updateSemanticTokens(TextDocument *textDocument)
|
||||
const SemanticRequestTypes supportedRequests = supportedSemanticRequests(textDocument);
|
||||
if (supportedRequests.testFlag(SemanticRequestType::FullDelta)) {
|
||||
const Utils::FilePath filePath = textDocument->filePath();
|
||||
const QString &previousResultId = m_tokens.value(filePath).tokens.resultId().value_or(QString());
|
||||
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)
|
||||
return;
|
||||
SemanticTokensDeltaParams params;
|
||||
params.setTextDocument(TextDocumentIdentifier(DocumentUri::fromFilePath(filePath)));
|
||||
params.setPreviousResultId(previousResultId);
|
||||
@@ -325,6 +339,12 @@ void SemanticTokenSupport::updateFormatHash()
|
||||
rehighlight();
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::onCurrentEditorChanged(Core::IEditor *editor)
|
||||
{
|
||||
if (auto textEditor = qobject_cast<BaseTextEditor *>(editor))
|
||||
updateSemanticTokens(textEditor->textDocument());
|
||||
}
|
||||
|
||||
void SemanticTokenSupport::setTokenTypesMap(const QMap<QString, int> &tokenTypesMap)
|
||||
{
|
||||
m_tokenTypesMap = tokenTypesMap;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Core { class IEditor; }
|
||||
|
||||
namespace LanguageClient {
|
||||
class Client;
|
||||
|
||||
@@ -62,11 +64,12 @@ void applyHighlight(TextEditor::TextDocument *doc,
|
||||
|
||||
} // namespace SemanticHighligtingSupport
|
||||
|
||||
class SemanticTokenSupport
|
||||
class SemanticTokenSupport : public QObject
|
||||
{
|
||||
public:
|
||||
explicit SemanticTokenSupport(Client *client);
|
||||
|
||||
void refresh();
|
||||
void reloadSemanticTokens(TextEditor::TextDocument *doc);
|
||||
void updateSemanticTokens(TextEditor::TextDocument *doc);
|
||||
void rehighlight();
|
||||
@@ -94,6 +97,7 @@ private:
|
||||
void highlight(const Utils::FilePath &filePath);
|
||||
void updateFormatHash();
|
||||
void currentEditorChanged();
|
||||
void onCurrentEditorChanged(Core::IEditor *editor);
|
||||
|
||||
Client *m_client = nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user