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)
|
if (!processor)
|
||||||
return defaultCallback();
|
return defaultCallback();
|
||||||
|
|
||||||
QFuture<CppTools::CursorInfo> future = processor->requestLocalReferences(data.cursor());
|
QFuture<CppTools::CursorInfo> cursorFuture = processor->requestLocalReferences(data.cursor());
|
||||||
if (future.isCanceled())
|
if (cursorFuture.isCanceled())
|
||||||
return defaultCallback();
|
return defaultCallback();
|
||||||
|
|
||||||
// QFuture::waitForFinished seems to block completely, not even
|
QObject::connect(&m_watcher, &FutureCursorWatcher::finished, [=]() {
|
||||||
// allowing to process events from QLocalSocket.
|
const CppTools::CursorInfo info = m_watcher.result();
|
||||||
while (!future.isFinished()) {
|
if (info.useRanges.empty())
|
||||||
if (future.isCanceled())
|
|
||||||
return defaultCallback();
|
return defaultCallback();
|
||||||
|
|
||||||
QTC_ASSERT(startRevision == data.cursor().document()->revision(), return;);
|
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
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();
|
m_watcher.setFuture(cursorFuture);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cpptools/refactoringengineinterface.h>
|
#include <cpptools/refactoringengineinterface.h>
|
||||||
|
#include <cpptools/cppcursorinfo.h>
|
||||||
|
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
class RefactoringClientInterface;
|
class RefactoringClientInterface;
|
||||||
@@ -49,6 +52,10 @@ public:
|
|||||||
{
|
{
|
||||||
return Link();
|
return Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
using FutureCursorWatcher = QFutureWatcher<CppTools::CursorInfo>;
|
||||||
|
FutureCursorWatcher m_watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangRefactoring
|
} // namespace ClangRefactoring
|
||||||
|
|||||||
Reference in New Issue
Block a user