forked from qt-creator/qt-creator
ClangCodeModel: Get document symbols immediately
... when doing a decl/def switch via clangd. The delay is fine for e.g. populating the outline, but shouldn't be used when dealing with explicit user requests. Change-Id: I0350ed6daf8220ec3b702a3876fbf0f726da8a67 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -1421,7 +1421,7 @@ void ClangdClient::switchDeclDef(TextEditor::TextDocument *document, const QText
|
||||
|
||||
});
|
||||
sendContent(astRequest, SendDocUpdates::Ignore);
|
||||
documentSymbolCache()->requestSymbols(d->switchDeclDefData->uri);
|
||||
documentSymbolCache()->requestSymbols(d->switchDeclDefData->uri, Schedule::Now);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ Client::Client(BaseClientInterface *clientInterface)
|
||||
m_documentUpdateTimer.setSingleShot(true);
|
||||
m_documentUpdateTimer.setInterval(500);
|
||||
connect(&m_documentUpdateTimer, &QTimer::timeout, this,
|
||||
[this] { sendPostponedDocumentUpdates(SemanticTokensUpdateMode::Now); });
|
||||
[this] { sendPostponedDocumentUpdates(Schedule::Now); });
|
||||
|
||||
m_contentHandler.insert(JsonRpcMessageHandler::jsonRpcMimeType(),
|
||||
&JsonRpcMessageHandler::parseContent);
|
||||
@@ -410,7 +410,7 @@ void Client::sendContent(const IContent &content, SendDocUpdates sendUpdates)
|
||||
QTC_ASSERT(m_clientInterface, return);
|
||||
QTC_ASSERT(m_state == Initialized, return);
|
||||
if (sendUpdates == SendDocUpdates::Send)
|
||||
sendPostponedDocumentUpdates(SemanticTokensUpdateMode::Delayed);
|
||||
sendPostponedDocumentUpdates(Schedule::Delayed);
|
||||
if (Utils::optional<ResponseHandler> responseHandler = content.responseHandler())
|
||||
m_responseHandlers[responseHandler->id] = responseHandler->callback;
|
||||
QString error;
|
||||
@@ -1216,7 +1216,7 @@ void Client::resetAssistProviders(TextEditor::TextDocument *document)
|
||||
document->setQuickFixAssistProvider(providers.quickFixAssistProvider);
|
||||
}
|
||||
|
||||
void Client::sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticTokensUpdateMode)
|
||||
void Client::sendPostponedDocumentUpdates(Schedule semanticTokensSchedule)
|
||||
{
|
||||
m_documentUpdateTimer.stop();
|
||||
if (m_documentsToUpdate.empty())
|
||||
@@ -1251,14 +1251,17 @@ void Client::sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticToken
|
||||
if (currentWidget && currentWidget->textDocument() == update.document)
|
||||
requestDocumentHighlights(currentWidget);
|
||||
|
||||
if (semanticTokensUpdateMode == SemanticTokensUpdateMode::Now) {
|
||||
switch (semanticTokensSchedule) {
|
||||
case Schedule::Now:
|
||||
m_tokenSupport.updateSemanticTokens(update.document);
|
||||
} else {
|
||||
break;
|
||||
case Schedule::Delayed:
|
||||
QTimer::singleShot(m_documentUpdateTimer.interval(), this,
|
||||
[this, doc = QPointer(update.document)] {
|
||||
if (doc && m_documentsToUpdate.find(doc) == m_documentsToUpdate.end())
|
||||
m_tokenSupport.updateSemanticTokens(doc);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,8 +229,7 @@ private:
|
||||
void removeDiagnostics(const LanguageServerProtocol::DocumentUri &uri);
|
||||
void resetAssistProviders(TextEditor::TextDocument *document);
|
||||
|
||||
enum class SemanticTokensUpdateMode { Now, Delayed };
|
||||
void sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticTokensUpdateMode);
|
||||
void sendPostponedDocumentUpdates(Schedule semanticTokensSchedule);
|
||||
|
||||
void updateCompletionProvider(TextEditor::TextDocument *document);
|
||||
void updateFunctionHintProvider(TextEditor::TextDocument *document);
|
||||
|
||||
@@ -54,10 +54,17 @@ DocumentSymbolCache::DocumentSymbolCache(Client *client)
|
||||
connect(&m_compressionTimer, &QTimer::timeout, this, &DocumentSymbolCache::requestSymbolsImpl);
|
||||
}
|
||||
|
||||
void DocumentSymbolCache::requestSymbols(const DocumentUri &uri)
|
||||
void DocumentSymbolCache::requestSymbols(const DocumentUri &uri, Schedule schedule)
|
||||
{
|
||||
m_compressedUris.insert(uri);
|
||||
m_compressionTimer.start(200);
|
||||
switch (schedule) {
|
||||
case Schedule::Now:
|
||||
requestSymbolsImpl();
|
||||
break;
|
||||
case Schedule::Delayed:
|
||||
m_compressionTimer.start(200);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentSymbolCache::requestSymbolsImpl()
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "languageclient_global.h"
|
||||
#include "languageclientutils.h"
|
||||
|
||||
#include "utils/optional.h"
|
||||
|
||||
@@ -47,7 +48,7 @@ class LANGUAGECLIENT_EXPORT DocumentSymbolCache : public QObject
|
||||
public:
|
||||
DocumentSymbolCache(Client *client);
|
||||
|
||||
void requestSymbols(const LanguageServerProtocol::DocumentUri &uri);
|
||||
void requestSymbols(const LanguageServerProtocol::DocumentUri &uri, Schedule schedule);
|
||||
|
||||
signals:
|
||||
void gotSymbols(const LanguageServerProtocol::DocumentUri &uri,
|
||||
|
||||
@@ -155,10 +155,10 @@ LanguageClientOutlineWidget::LanguageClientOutlineWidget(Client *client,
|
||||
&LanguageClientOutlineWidget::handleResponse);
|
||||
connect(client, &Client::documentUpdated, this, [this](TextEditor::TextDocument *document) {
|
||||
if (m_client && m_uri == DocumentUri::fromFilePath(document->filePath()))
|
||||
m_client->documentSymbolCache()->requestSymbols(m_uri);
|
||||
m_client->documentSymbolCache()->requestSymbols(m_uri, Schedule::Delayed);
|
||||
});
|
||||
|
||||
client->documentSymbolCache()->requestSymbols(m_uri);
|
||||
client->documentSymbolCache()->requestSymbols(m_uri, Schedule::Delayed);
|
||||
|
||||
auto *layout = new QVBoxLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
@@ -367,7 +367,7 @@ void OutlineComboBox::activateEntry()
|
||||
void OutlineComboBox::documentUpdated(TextEditor::TextDocument *document)
|
||||
{
|
||||
if (document == m_editorWidget->textDocument())
|
||||
m_client->documentSymbolCache()->requestSymbols(m_uri);
|
||||
m_client->documentSymbolCache()->requestSymbols(m_uri, Schedule::Delayed);
|
||||
}
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace LanguageClient {
|
||||
|
||||
class Client;
|
||||
|
||||
enum class Schedule { Now, Delayed };
|
||||
|
||||
Utils::ChangeSet editsToChangeSet(const QList<LanguageServerProtocol::TextEdit> &edits,
|
||||
const QTextDocument *doc);
|
||||
bool LANGUAGECLIENT_EXPORT applyWorkspaceEdit(const Client *client, const LanguageServerProtocol::WorkspaceEdit &edit);
|
||||
|
||||
@@ -148,7 +148,7 @@ void DocumentLocatorFilter::prepareSearch(const QString &/*entry*/)
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (m_symbolCache && !m_currentSymbols.has_value()) {
|
||||
locker.unlock();
|
||||
m_symbolCache->requestSymbols(m_currentUri);
|
||||
m_symbolCache->requestSymbols(m_currentUri, Schedule::Delayed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user