From 12c0aadc82da59f449bcfca46675da0b1d1a8935 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 14 Jan 2021 16:13:29 +0100 Subject: [PATCH] CppEditor: Fix race condition for highlighting of local usages Starting a renaming action involves looking up local usages. In this case, a different code path than normal updates the editor's extra selections, in order to make sure that the occurrence to be edited is rendered in a special way. We must therefore prevent the normal handler from taking action, as it would overwrite abovementioned special selection. Change-Id: Ia811b49b3023a0a366a43a69cc01e6b2b370acb5 Reviewed-by: David Schulz --- src/plugins/cppeditor/cppeditorwidget.cpp | 5 +++++ src/plugins/cppeditor/cppeditorwidget.h | 1 + src/plugins/cppeditor/cppuseselectionsupdater.cpp | 6 +++++- src/plugins/cppeditor/cppuseselectionsupdater.h | 8 ++++---- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 80044406cd9..dc75c68fda1 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -805,6 +805,11 @@ bool CppEditorWidget::isSemanticInfoValid() const return isSemanticInfoValidExceptLocalUses() && d->m_lastSemanticInfo.localUsesUpdated; } +bool CppEditorWidget::isRenaming() const +{ + return d->m_localRenaming.isActive(); +} + SemanticInfo CppEditorWidget::semanticInfo() const { return d->m_lastSemanticInfo; diff --git a/src/plugins/cppeditor/cppeditorwidget.h b/src/plugins/cppeditor/cppeditorwidget.h index bdb5ce313bc..2a02c210805 100644 --- a/src/plugins/cppeditor/cppeditorwidget.h +++ b/src/plugins/cppeditor/cppeditorwidget.h @@ -60,6 +60,7 @@ public: bool isSemanticInfoValidExceptLocalUses() const; bool isSemanticInfoValid() const; + bool isRenaming() const; QSharedPointer declDefLink() const; void applyDeclDefLinkChanges(bool jumpToMatch); diff --git a/src/plugins/cppeditor/cppuseselectionsupdater.cpp b/src/plugins/cppeditor/cppuseselectionsupdater.cpp index fc6123b94b9..2649a05355e 100644 --- a/src/plugins/cppeditor/cppuseselectionsupdater.cpp +++ b/src/plugins/cppeditor/cppuseselectionsupdater.cpp @@ -41,7 +41,7 @@ enum { updateUseSelectionsInternalInMs = 500 }; namespace CppEditor { namespace Internal { -CppUseSelectionsUpdater::CppUseSelectionsUpdater(TextEditor::TextEditorWidget *editorWidget) +CppUseSelectionsUpdater::CppUseSelectionsUpdater(CppEditorWidget *editorWidget) : m_editorWidget(editorWidget) { m_timer.setSingleShot(true); @@ -157,6 +157,10 @@ void CppUseSelectionsUpdater::onFindUsesFinished() emit finished(CppTools::SemanticInfo::LocalUseMap(), false); return; } + if (m_editorWidget->isRenaming()) { + emit finished({}, false); + return; + } processResults(m_runnerWatcher->result()); diff --git a/src/plugins/cppeditor/cppuseselectionsupdater.h b/src/plugins/cppeditor/cppuseselectionsupdater.h index b031420e93c..18982fcf1d6 100644 --- a/src/plugins/cppeditor/cppuseselectionsupdater.h +++ b/src/plugins/cppeditor/cppuseselectionsupdater.h @@ -32,18 +32,18 @@ #include #include -namespace TextEditor { class TextEditorWidget; } - namespace CppEditor { namespace Internal { +class CppEditorWidget; + class CppUseSelectionsUpdater : public QObject { Q_OBJECT Q_DISABLE_COPY(CppUseSelectionsUpdater) public: - explicit CppUseSelectionsUpdater(TextEditor::TextEditorWidget *editorWidget); + explicit CppUseSelectionsUpdater(CppEditorWidget *editorWidget); ~CppUseSelectionsUpdater() override; void scheduleUpdate(); @@ -73,7 +73,7 @@ private: void updateUnusedSelections(const CursorInfo::Ranges &selections); private: - TextEditor::TextEditorWidget *m_editorWidget; + CppEditorWidget * const m_editorWidget; QTimer m_timer;