forked from qt-creator/qt-creator
LanguageClient: Improve use of Client::m_documentsToUpdate
In particular, calling keys() and then take() for all the keys is wasteful (and obscures what's going on). Change-Id: Ic66803cf3579a39c23c32f1fc65e2c9399dcc583 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -808,7 +808,7 @@ TextEditor::HighlightingResult createHighlightingResult(const SymbolInformation
|
|||||||
void Client::cursorPositionChanged(TextEditor::TextEditorWidget *widget)
|
void Client::cursorPositionChanged(TextEditor::TextEditorWidget *widget)
|
||||||
{
|
{
|
||||||
TextEditor::TextDocument *document = widget->textDocument();
|
TextEditor::TextDocument *document = widget->textDocument();
|
||||||
if (m_documentsToUpdate.contains(document))
|
if (m_documentsToUpdate.find(document) != m_documentsToUpdate.end())
|
||||||
return; // we are currently changing this document so postpone the DocumentHighlightsRequest
|
return; // we are currently changing this document so postpone the DocumentHighlightsRequest
|
||||||
QTimer *timer = m_documentHighlightsTimer[widget];
|
QTimer *timer = m_documentHighlightsTimer[widget];
|
||||||
if (!timer) {
|
if (!timer) {
|
||||||
@@ -1218,7 +1218,7 @@ void Client::resetAssistProviders(TextEditor::TextDocument *document)
|
|||||||
void Client::sendPostponedDocumentUpdates()
|
void Client::sendPostponedDocumentUpdates()
|
||||||
{
|
{
|
||||||
m_documentUpdateTimer.stop();
|
m_documentUpdateTimer.stop();
|
||||||
if (m_documentsToUpdate.isEmpty())
|
if (m_documentsToUpdate.empty())
|
||||||
return;
|
return;
|
||||||
TextEditor::TextEditorWidget *currentWidget
|
TextEditor::TextEditorWidget *currentWidget
|
||||||
= TextEditor::TextEditorWidget::currentTextEditorWidget();
|
= TextEditor::TextEditorWidget::currentTextEditorWidget();
|
||||||
@@ -1228,11 +1228,9 @@ void Client::sendPostponedDocumentUpdates()
|
|||||||
TextEditor::TextDocument *document;
|
TextEditor::TextDocument *document;
|
||||||
DidChangeTextDocumentNotification notification;
|
DidChangeTextDocumentNotification notification;
|
||||||
};
|
};
|
||||||
|
const auto updates = Utils::transform<QList<DocumentUpdate>>(m_documentsToUpdate,
|
||||||
QList<DocumentUpdate> updates;
|
[this](const auto &elem) {
|
||||||
|
TextEditor::TextDocument * const document = elem.first;
|
||||||
const QList<TextEditor::TextDocument *> documents = m_documentsToUpdate.keys();
|
|
||||||
for (auto document : documents) {
|
|
||||||
const FilePath &filePath = document->filePath();
|
const FilePath &filePath = document->filePath();
|
||||||
const auto uri = DocumentUri::fromFilePath(filePath);
|
const auto uri = DocumentUri::fromFilePath(filePath);
|
||||||
m_highlights[uri].clear();
|
m_highlights[uri].clear();
|
||||||
@@ -1240,13 +1238,13 @@ void Client::sendPostponedDocumentUpdates()
|
|||||||
docId.setVersion(m_documentVersions[filePath]);
|
docId.setVersion(m_documentVersions[filePath]);
|
||||||
DidChangeTextDocumentParams params;
|
DidChangeTextDocumentParams params;
|
||||||
params.setTextDocument(docId);
|
params.setTextDocument(docId);
|
||||||
params.setContentChanges(m_documentsToUpdate.take(document));
|
params.setContentChanges(elem.second);
|
||||||
|
return DocumentUpdate{document, DidChangeTextDocumentNotification(params)};
|
||||||
|
});
|
||||||
|
m_documentsToUpdate.clear();
|
||||||
|
|
||||||
updates.append({document, DidChangeTextDocumentNotification(params)});
|
for (const DocumentUpdate &update : updates) {
|
||||||
}
|
sendContent(update.notification, SendDocUpdates::Ignore);
|
||||||
|
|
||||||
for (const DocumentUpdate &update : qAsConst(updates)) {
|
|
||||||
sendContent(update.notification);
|
|
||||||
emit documentUpdated(update.document);
|
emit documentUpdated(update.document);
|
||||||
|
|
||||||
if (currentWidget && currentWidget->textDocument() == update.document)
|
if (currentWidget && currentWidget->textDocument() == update.document)
|
||||||
@@ -1423,8 +1421,8 @@ void Client::rehighlight()
|
|||||||
|
|
||||||
bool Client::documentUpdatePostponed(const Utils::FilePath &fileName) const
|
bool Client::documentUpdatePostponed(const Utils::FilePath &fileName) const
|
||||||
{
|
{
|
||||||
return Utils::contains(m_documentsToUpdate.keys(), [fileName](const TextEditor::TextDocument *doc) {
|
return Utils::contains(m_documentsToUpdate, [fileName](const auto &elem) {
|
||||||
return doc->filePath() == fileName;
|
return elem.first->filePath() == fileName;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,8 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace Core { class IDocument; }
|
namespace Core { class IDocument; }
|
||||||
namespace ProjectExplorer { class Project; }
|
namespace ProjectExplorer { class Project; }
|
||||||
namespace TextEditor
|
namespace TextEditor
|
||||||
@@ -252,7 +254,7 @@ private:
|
|||||||
QMap<TextEditor::TextDocument *, QString> m_openedDocument;
|
QMap<TextEditor::TextDocument *, QString> m_openedDocument;
|
||||||
QSet<TextEditor::TextDocument *> m_postponedDocuments;
|
QSet<TextEditor::TextDocument *> m_postponedDocuments;
|
||||||
QMap<Utils::FilePath, int> m_documentVersions;
|
QMap<Utils::FilePath, int> m_documentVersions;
|
||||||
QMap<TextEditor::TextDocument *,
|
std::unordered_map<TextEditor::TextDocument *,
|
||||||
QList<LanguageServerProtocol::DidChangeTextDocumentParams::TextDocumentContentChangeEvent>>
|
QList<LanguageServerProtocol::DidChangeTextDocumentParams::TextDocumentContentChangeEvent>>
|
||||||
m_documentsToUpdate;
|
m_documentsToUpdate;
|
||||||
QMap<TextEditor::TextEditorWidget *, QTimer *> m_documentHighlightsTimer;
|
QMap<TextEditor::TextEditorWidget *, QTimer *> m_documentHighlightsTimer;
|
||||||
|
|||||||
Reference in New Issue
Block a user