LanguageClient: Speed up DiagnosticManager::showDiagnostics()

- Do project file look-up only if we have diagnostics.
- Move hash access out of the loop.

Change-Id: I9dd03dbfe8d7515e731cbeb0ce51639d9df993b4
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2022-02-25 16:14:26 +01:00
parent 2a4c149e49
commit 22fb18c0a8

View File

@@ -125,12 +125,14 @@ void DiagnosticManager::showDiagnostics(const DocumentUri &uri, int version)
if (TextDocument *doc = TextDocument::textDocumentForFilePath(filePath)) {
QList<QTextEdit::ExtraSelection> extraSelections;
const VersionedDiagnostics &versionedDiagnostics = m_diagnostics.value(uri);
if (versionedDiagnostics.version.value_or(version) == version) {
if (versionedDiagnostics.version.value_or(version) == version
&& !versionedDiagnostics.diagnostics.isEmpty()) {
QList<TextEditor::TextMark *> &marks = m_marks[filePath];
const bool isProjectFile = m_client->project()
&& m_client->project()->isKnownFile(filePath);
for (const Diagnostic &diagnostic : versionedDiagnostics.diagnostics) {
extraSelections << toDiagnosticsSelections(diagnostic, doc->document());
m_marks[filePath].append(m_textMarkCreator(filePath, diagnostic, isProjectFile));
marks.append(m_textMarkCreator(filePath, diagnostic, isProjectFile));
}
}