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);
|
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.setSingleShot(true);
|
||||||
m_documentUpdateTimer.setInterval(500);
|
m_documentUpdateTimer.setInterval(500);
|
||||||
connect(&m_documentUpdateTimer, &QTimer::timeout, this,
|
connect(&m_documentUpdateTimer, &QTimer::timeout, this,
|
||||||
[this] { sendPostponedDocumentUpdates(SemanticTokensUpdateMode::Now); });
|
[this] { sendPostponedDocumentUpdates(Schedule::Now); });
|
||||||
|
|
||||||
m_contentHandler.insert(JsonRpcMessageHandler::jsonRpcMimeType(),
|
m_contentHandler.insert(JsonRpcMessageHandler::jsonRpcMimeType(),
|
||||||
&JsonRpcMessageHandler::parseContent);
|
&JsonRpcMessageHandler::parseContent);
|
||||||
@@ -410,7 +410,7 @@ void Client::sendContent(const IContent &content, SendDocUpdates sendUpdates)
|
|||||||
QTC_ASSERT(m_clientInterface, return);
|
QTC_ASSERT(m_clientInterface, return);
|
||||||
QTC_ASSERT(m_state == Initialized, return);
|
QTC_ASSERT(m_state == Initialized, return);
|
||||||
if (sendUpdates == SendDocUpdates::Send)
|
if (sendUpdates == SendDocUpdates::Send)
|
||||||
sendPostponedDocumentUpdates(SemanticTokensUpdateMode::Delayed);
|
sendPostponedDocumentUpdates(Schedule::Delayed);
|
||||||
if (Utils::optional<ResponseHandler> responseHandler = content.responseHandler())
|
if (Utils::optional<ResponseHandler> responseHandler = content.responseHandler())
|
||||||
m_responseHandlers[responseHandler->id] = responseHandler->callback;
|
m_responseHandlers[responseHandler->id] = responseHandler->callback;
|
||||||
QString error;
|
QString error;
|
||||||
@@ -1216,7 +1216,7 @@ void Client::resetAssistProviders(TextEditor::TextDocument *document)
|
|||||||
document->setQuickFixAssistProvider(providers.quickFixAssistProvider);
|
document->setQuickFixAssistProvider(providers.quickFixAssistProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticTokensUpdateMode)
|
void Client::sendPostponedDocumentUpdates(Schedule semanticTokensSchedule)
|
||||||
{
|
{
|
||||||
m_documentUpdateTimer.stop();
|
m_documentUpdateTimer.stop();
|
||||||
if (m_documentsToUpdate.empty())
|
if (m_documentsToUpdate.empty())
|
||||||
@@ -1251,14 +1251,17 @@ void Client::sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticToken
|
|||||||
if (currentWidget && currentWidget->textDocument() == update.document)
|
if (currentWidget && currentWidget->textDocument() == update.document)
|
||||||
requestDocumentHighlights(currentWidget);
|
requestDocumentHighlights(currentWidget);
|
||||||
|
|
||||||
if (semanticTokensUpdateMode == SemanticTokensUpdateMode::Now) {
|
switch (semanticTokensSchedule) {
|
||||||
|
case Schedule::Now:
|
||||||
m_tokenSupport.updateSemanticTokens(update.document);
|
m_tokenSupport.updateSemanticTokens(update.document);
|
||||||
} else {
|
break;
|
||||||
|
case Schedule::Delayed:
|
||||||
QTimer::singleShot(m_documentUpdateTimer.interval(), this,
|
QTimer::singleShot(m_documentUpdateTimer.interval(), this,
|
||||||
[this, doc = QPointer(update.document)] {
|
[this, doc = QPointer(update.document)] {
|
||||||
if (doc && m_documentsToUpdate.find(doc) == m_documentsToUpdate.end())
|
if (doc && m_documentsToUpdate.find(doc) == m_documentsToUpdate.end())
|
||||||
m_tokenSupport.updateSemanticTokens(doc);
|
m_tokenSupport.updateSemanticTokens(doc);
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,8 +229,7 @@ private:
|
|||||||
void removeDiagnostics(const LanguageServerProtocol::DocumentUri &uri);
|
void removeDiagnostics(const LanguageServerProtocol::DocumentUri &uri);
|
||||||
void resetAssistProviders(TextEditor::TextDocument *document);
|
void resetAssistProviders(TextEditor::TextDocument *document);
|
||||||
|
|
||||||
enum class SemanticTokensUpdateMode { Now, Delayed };
|
void sendPostponedDocumentUpdates(Schedule semanticTokensSchedule);
|
||||||
void sendPostponedDocumentUpdates(SemanticTokensUpdateMode semanticTokensUpdateMode);
|
|
||||||
|
|
||||||
void updateCompletionProvider(TextEditor::TextDocument *document);
|
void updateCompletionProvider(TextEditor::TextDocument *document);
|
||||||
void updateFunctionHintProvider(TextEditor::TextDocument *document);
|
void updateFunctionHintProvider(TextEditor::TextDocument *document);
|
||||||
|
|||||||
@@ -54,10 +54,17 @@ DocumentSymbolCache::DocumentSymbolCache(Client *client)
|
|||||||
connect(&m_compressionTimer, &QTimer::timeout, this, &DocumentSymbolCache::requestSymbolsImpl);
|
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_compressedUris.insert(uri);
|
||||||
|
switch (schedule) {
|
||||||
|
case Schedule::Now:
|
||||||
|
requestSymbolsImpl();
|
||||||
|
break;
|
||||||
|
case Schedule::Delayed:
|
||||||
m_compressionTimer.start(200);
|
m_compressionTimer.start(200);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentSymbolCache::requestSymbolsImpl()
|
void DocumentSymbolCache::requestSymbolsImpl()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "languageclient_global.h"
|
#include "languageclient_global.h"
|
||||||
|
#include "languageclientutils.h"
|
||||||
|
|
||||||
#include "utils/optional.h"
|
#include "utils/optional.h"
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ class LANGUAGECLIENT_EXPORT DocumentSymbolCache : public QObject
|
|||||||
public:
|
public:
|
||||||
DocumentSymbolCache(Client *client);
|
DocumentSymbolCache(Client *client);
|
||||||
|
|
||||||
void requestSymbols(const LanguageServerProtocol::DocumentUri &uri);
|
void requestSymbols(const LanguageServerProtocol::DocumentUri &uri, Schedule schedule);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void gotSymbols(const LanguageServerProtocol::DocumentUri &uri,
|
void gotSymbols(const LanguageServerProtocol::DocumentUri &uri,
|
||||||
|
|||||||
@@ -155,10 +155,10 @@ LanguageClientOutlineWidget::LanguageClientOutlineWidget(Client *client,
|
|||||||
&LanguageClientOutlineWidget::handleResponse);
|
&LanguageClientOutlineWidget::handleResponse);
|
||||||
connect(client, &Client::documentUpdated, this, [this](TextEditor::TextDocument *document) {
|
connect(client, &Client::documentUpdated, this, [this](TextEditor::TextDocument *document) {
|
||||||
if (m_client && m_uri == DocumentUri::fromFilePath(document->filePath()))
|
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;
|
auto *layout = new QVBoxLayout;
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
@@ -367,7 +367,7 @@ void OutlineComboBox::activateEntry()
|
|||||||
void OutlineComboBox::documentUpdated(TextEditor::TextDocument *document)
|
void OutlineComboBox::documentUpdated(TextEditor::TextDocument *document)
|
||||||
{
|
{
|
||||||
if (document == m_editorWidget->textDocument())
|
if (document == m_editorWidget->textDocument())
|
||||||
m_client->documentSymbolCache()->requestSymbols(m_uri);
|
m_client->documentSymbolCache()->requestSymbols(m_uri, Schedule::Delayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ namespace LanguageClient {
|
|||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
|
||||||
|
enum class Schedule { Now, Delayed };
|
||||||
|
|
||||||
Utils::ChangeSet editsToChangeSet(const QList<LanguageServerProtocol::TextEdit> &edits,
|
Utils::ChangeSet editsToChangeSet(const QList<LanguageServerProtocol::TextEdit> &edits,
|
||||||
const QTextDocument *doc);
|
const QTextDocument *doc);
|
||||||
bool LANGUAGECLIENT_EXPORT applyWorkspaceEdit(const Client *client, const LanguageServerProtocol::WorkspaceEdit &edit);
|
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);
|
QMutexLocker locker(&m_mutex);
|
||||||
if (m_symbolCache && !m_currentSymbols.has_value()) {
|
if (m_symbolCache && !m_currentSymbols.has_value()) {
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
m_symbolCache->requestSymbols(m_currentUri);
|
m_symbolCache->requestSymbols(m_currentUri, Schedule::Delayed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user