From b20fa85bc082ef6bb6789bc6878f820a0c896d02 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 15 Jul 2020 16:11:26 +0200 Subject: [PATCH] ClangCodeModel: Fix race condition ... between semantic re-highlighting and document visibility update. Make semanticRehighlight() a no-op if the document is not currently visible, and call it explicitly on an editor change. Fixes: QTCREATORBUG-24290 Change-Id: Ife61f61d3fb82e8b283bf93ab77d16517f6c6f9c Reviewed-by: David Schulz --- .../clangcodemodel/clangeditordocumentprocessor.cpp | 7 ++++++- src/plugins/clangcodemodel/clangmodelmanagersupport.cpp | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index ed9917a7737..789ba940d26 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -139,8 +139,13 @@ void ClangEditorDocumentProcessor::recalculateSemanticInfoDetached(bool force) void ClangEditorDocumentProcessor::semanticRehighlight() { - m_semanticHighlighter.updateFormatMapFromFontSettings(); + const auto matchesEditor = [this](const Core::IEditor *editor) { + return editor->document()->filePath() == m_document.filePath(); + }; + if (!Utils::contains(Core::EditorManager::visibleEditors(), matchesEditor)) + return; + m_semanticHighlighter.updateFormatMapFromFontSettings(); if (m_projectPart) requestAnnotationsFromBackend(); } diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 3f441fc54d5..9e56b54b914 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -155,8 +155,10 @@ void ClangModelManagerSupport::onCurrentEditorChanged(Core::IEditor *editor) return; const ::Utils::FilePath filePath = editor->document()->filePath(); - if (auto processor = ClangEditorDocumentProcessor::get(filePath.toString())) + if (auto processor = ClangEditorDocumentProcessor::get(filePath.toString())) { + processor->semanticRehighlight(); processor->generateTaskHubIssues(); + } } void ClangModelManagerSupport::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)