forked from qt-creator/qt-creator
Clang: Do not call processEvents call in local renaming
Use QFutureWatcher and lambda instead. Task-number: QTCREATORBUG-19799 Change-Id: I00e9439d46609902cbfb02906280c0c96b8c884e Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -47,32 +47,30 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
||||
if (!processor)
|
||||
return defaultCallback();
|
||||
|
||||
QFuture<CppTools::CursorInfo> future = processor->requestLocalReferences(data.cursor());
|
||||
if (future.isCanceled())
|
||||
QFuture<CppTools::CursorInfo> cursorFuture = processor->requestLocalReferences(data.cursor());
|
||||
if (cursorFuture.isCanceled())
|
||||
return defaultCallback();
|
||||
|
||||
// QFuture::waitForFinished seems to block completely, not even
|
||||
// allowing to process events from QLocalSocket.
|
||||
while (!future.isFinished()) {
|
||||
if (future.isCanceled())
|
||||
QObject::connect(&m_watcher, &FutureCursorWatcher::finished, [=]() {
|
||||
const CppTools::CursorInfo info = m_watcher.result();
|
||||
if (info.useRanges.empty())
|
||||
return defaultCallback();
|
||||
|
||||
QTC_ASSERT(startRevision == data.cursor().document()->revision(), return;);
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
|
||||
info.useRanges.first().length);
|
||||
const QString symbolName = cursor.selectedText();
|
||||
ClangBackEnd::SourceLocationsContainer container;
|
||||
for (auto& use : info.useRanges) {
|
||||
container.insertSourceLocation(ClangBackEnd::FilePathId(),
|
||||
use.line,
|
||||
use.column,
|
||||
use.length);
|
||||
}
|
||||
renameSymbolsCallback(symbolName, container, data.cursor().document()->revision());
|
||||
});
|
||||
|
||||
const CppTools::CursorInfo info = future.result();
|
||||
if (info.useRanges.empty())
|
||||
return defaultCallback();
|
||||
|
||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
|
||||
info.useRanges.first().length);
|
||||
const QString symbolName = cursor.selectedText();
|
||||
ClangBackEnd::SourceLocationsContainer container;
|
||||
for (auto& use : info.useRanges)
|
||||
container.insertSourceLocation(ClangBackEnd::FilePathId(), use.line, use.column, use.length);
|
||||
renameSymbolsCallback(symbolName, container, data.cursor().document()->revision());
|
||||
m_watcher.setFuture(cursorFuture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cpptools/refactoringengineinterface.h>
|
||||
#include <cpptools/cppcursorinfo.h>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class RefactoringClientInterface;
|
||||
@@ -49,6 +52,10 @@ public:
|
||||
{
|
||||
return Link();
|
||||
}
|
||||
|
||||
private:
|
||||
using FutureCursorWatcher = QFutureWatcher<CppTools::CursorInfo>;
|
||||
FutureCursorWatcher m_watcher;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
Reference in New Issue
Block a user