LanguageClient: compress requests from the symbol cache

Change-Id: I58c6863fae6e275073c377558eaba18f7f32b4f2
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-01-29 11:17:47 +01:00
parent 820fa993a6
commit b9f4719571
2 changed files with 27 additions and 13 deletions

View File

@@ -50,10 +50,19 @@ DocumentSymbolCache::DocumentSymbolCache(Client *client)
&Core::EditorManager::documentOpened,
this,
connectDocument);
m_compressionTimer.setSingleShot(true);
connect(&m_compressionTimer, &QTimer::timeout, this, &DocumentSymbolCache::requestSymbolsImpl);
}
void DocumentSymbolCache::requestSymbols(const DocumentUri &uri)
{
m_compressedUris.insert(uri);
m_compressionTimer.start(200);
}
void DocumentSymbolCache::requestSymbolsImpl()
{
for (const DocumentUri &uri : qAsConst(m_compressedUris)) {
auto entry = m_cache.find(uri);
if (entry != m_cache.end()) {
emit gotSymbols(uri, entry.value());
@@ -69,6 +78,7 @@ void DocumentSymbolCache::requestSymbols(const DocumentUri &uri)
});
m_client->sendContent(request);
}
}
void DocumentSymbolCache::handleResponse(const DocumentUri &uri,
const DocumentSymbolsRequest::Response &response)

View File

@@ -30,6 +30,7 @@
#include <languageserverprotocol/languagefeatures.h>
#include <QObject>
#include <QTimer>
namespace LanguageClient {
@@ -48,11 +49,14 @@ signals:
const LanguageServerProtocol::DocumentSymbolsResult &symbols);
private:
void requestSymbolsImpl();
void handleResponse(const LanguageServerProtocol::DocumentUri &uri,
const LanguageServerProtocol::DocumentSymbolsRequest::Response &response);
QMap<LanguageServerProtocol::DocumentUri, LanguageServerProtocol::DocumentSymbolsResult> m_cache;
Client *m_client = nullptr;
QTimer m_compressionTimer;
QSet<LanguageServerProtocol::DocumentUri> m_compressedUris;
};
} // namespace LanguageClient