forked from qt-creator/qt-creator
Fix starting a usage search while another one is running.
Theoretically it could now run multiple searches in parallel, but since a single search grabs all available threads from the pool, any search request afterwards is queued for execution when the previous one finished. Task-number: QTCREATORBUG-6101 Change-Id: Ifada0ccdd1ce7cfb4aaaaa4de2db070025f91a3a Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/filesearch.h>
|
#include <utils/filesearch.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <coreplugin/progressmanager/futureprogress.h>
|
#include <coreplugin/progressmanager/futureprogress.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -163,9 +164,6 @@ CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager)
|
|||||||
: QObject(modelManager),
|
: QObject(modelManager),
|
||||||
_modelManager(modelManager)
|
_modelManager(modelManager)
|
||||||
{
|
{
|
||||||
m_watcher.setPendingResultsLimit(1);
|
|
||||||
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
|
|
||||||
connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppFindReferences::~CppFindReferences()
|
CppFindReferences::~CppFindReferences()
|
||||||
@@ -218,23 +216,18 @@ static void find_helper(QFutureInterface<Usage> &future,
|
|||||||
|
|
||||||
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol);
|
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol);
|
||||||
UpdateUI reduce(&future);
|
UpdateUI reduce(&future);
|
||||||
|
|
||||||
QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce);
|
QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce);
|
||||||
|
|
||||||
future.setProgressValue(files.size());
|
future.setProgressValue(files.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context)
|
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context)
|
||||||
{
|
{
|
||||||
Overview overview;
|
Overview overview;
|
||||||
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(tr("C++ Usages:"),
|
Find::SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(tr("C++ Usages:"),
|
||||||
QString(),
|
QString(),
|
||||||
overview(context.fullyQualifiedName(symbol)),
|
overview(context.fullyQualifiedName(symbol)),
|
||||||
Find::SearchResultWindow::SearchOnly);
|
Find::SearchResultWindow::SearchOnly);
|
||||||
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
|
findAll_helper(search, symbol, context);
|
||||||
this, SLOT(openEditor(Find::SearchResultItem)));
|
|
||||||
|
|
||||||
findAll_helper(symbol, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
|
void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
|
||||||
@@ -245,39 +238,38 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus:
|
|||||||
? QString::fromUtf8(id->chars(), id->size()) : replacement;
|
? QString::fromUtf8(id->chars(), id->size()) : replacement;
|
||||||
|
|
||||||
Overview overview;
|
Overview overview;
|
||||||
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
|
Find::SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(
|
||||||
tr("C++ Usages:"),
|
tr("C++ Usages:"),
|
||||||
QString(),
|
QString(),
|
||||||
overview(context.fullyQualifiedName(symbol)),
|
overview(context.fullyQualifiedName(symbol)),
|
||||||
Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor"));
|
Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor"));
|
||||||
m_currentSearch->setTextToReplace(textToReplace);
|
search->setTextToReplace(textToReplace);
|
||||||
|
|
||||||
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
|
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
||||||
this, SLOT(openEditor(Find::SearchResultItem)));
|
|
||||||
|
|
||||||
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
|
||||||
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
|
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
|
||||||
|
|
||||||
findAll_helper(symbol, context);
|
findAll_helper(search, symbol, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &context)
|
void CppFindReferences::findAll_helper(Find::SearchResult *search,
|
||||||
|
Symbol *symbol, const LookupContext &context)
|
||||||
{
|
{
|
||||||
if (! (symbol && symbol->identifier()))
|
if (! (symbol && symbol->identifier())) {
|
||||||
|
search->finishSearch();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
|
||||||
|
connect(search, SIGNAL(activated(Find::SearchResultItem)),
|
||||||
|
this, SLOT(openEditor(Find::SearchResultItem)));
|
||||||
|
|
||||||
Find::SearchResultWindow::instance()->popup(true);
|
Find::SearchResultWindow::instance()->popup(true);
|
||||||
|
|
||||||
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
|
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
|
||||||
|
QFuture<Usage> result;
|
||||||
|
result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol);
|
||||||
|
createWatcher(result, search);
|
||||||
|
|
||||||
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
|
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
|
||||||
|
|
||||||
QFuture<Usage> result;
|
|
||||||
|
|
||||||
result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol);
|
|
||||||
m_watcher.setFuture(result);
|
|
||||||
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
|
|
||||||
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
|
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
|
||||||
CppTools::Constants::TASK_SEARCH);
|
CppTools::Constants::TASK_SEARCH);
|
||||||
|
|
||||||
@@ -296,13 +288,16 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
|
|||||||
|
|
||||||
void CppFindReferences::displayResults(int first, int last)
|
void CppFindReferences::displayResults(int first, int last)
|
||||||
{
|
{
|
||||||
if (!m_currentSearch) {
|
QFutureWatcher<Usage> *watcher = static_cast<QFutureWatcher<Usage> *>(sender());
|
||||||
m_watcher.cancel();
|
Find::SearchResult *search = m_watchers.value(watcher);
|
||||||
|
if (!search) {
|
||||||
|
// search was deleted while it was running
|
||||||
|
watcher->cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int index = first; index != last; ++index) {
|
for (int index = first; index != last; ++index) {
|
||||||
Usage result = m_watcher.future().resultAt(index);
|
Usage result = watcher->future().resultAt(index);
|
||||||
m_currentSearch->addResult(result.path,
|
search->addResult(result.path,
|
||||||
result.line,
|
result.line,
|
||||||
result.lineText,
|
result.lineText,
|
||||||
result.col,
|
result.col,
|
||||||
@@ -312,15 +307,20 @@ void CppFindReferences::displayResults(int first, int last)
|
|||||||
|
|
||||||
void CppFindReferences::searchFinished()
|
void CppFindReferences::searchFinished()
|
||||||
{
|
{
|
||||||
if (m_currentSearch)
|
QFutureWatcher<Usage> *watcher = static_cast<QFutureWatcher<Usage> *>(sender());
|
||||||
m_currentSearch->finishSearch();
|
Find::SearchResult *search = m_watchers.value(watcher);
|
||||||
m_currentSearch = 0;
|
if (search)
|
||||||
emit changed();
|
search->finishSearch();
|
||||||
|
m_watchers.remove(watcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::cancel()
|
void CppFindReferences::cancel()
|
||||||
{
|
{
|
||||||
m_watcher.cancel();
|
Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender());
|
||||||
|
QTC_ASSERT(search, return);
|
||||||
|
QFutureWatcher<Usage> *watcher = m_watchers.key(search);
|
||||||
|
QTC_ASSERT(watcher, return);
|
||||||
|
watcher->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
|
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
|
||||||
@@ -430,7 +430,7 @@ static void findMacroUses_helper(QFutureInterface<Usage> &future,
|
|||||||
|
|
||||||
void CppFindReferences::findMacroUses(const Macro ¯o)
|
void CppFindReferences::findMacroUses(const Macro ¯o)
|
||||||
{
|
{
|
||||||
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
|
Find::SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(
|
||||||
tr("C++ Macro Usages:"),
|
tr("C++ Macro Usages:"),
|
||||||
QString(),
|
QString(),
|
||||||
macro.name(),
|
macro.name(),
|
||||||
@@ -438,8 +438,9 @@ void CppFindReferences::findMacroUses(const Macro ¯o)
|
|||||||
|
|
||||||
Find::SearchResultWindow::instance()->popup(true);
|
Find::SearchResultWindow::instance()->popup(true);
|
||||||
|
|
||||||
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
|
connect(search, SIGNAL(activated(Find::SearchResultItem)),
|
||||||
this, SLOT(openEditor(Find::SearchResultItem)));
|
this, SLOT(openEditor(Find::SearchResultItem)));
|
||||||
|
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
|
||||||
|
|
||||||
const Snapshot snapshot = _modelManager->snapshot();
|
const Snapshot snapshot = _modelManager->snapshot();
|
||||||
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
|
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
|
||||||
@@ -448,14 +449,13 @@ void CppFindReferences::findMacroUses(const Macro ¯o)
|
|||||||
{
|
{
|
||||||
// ### FIXME: Encoding?
|
// ### FIXME: Encoding?
|
||||||
const QByteArray &source = getSource(macro.fileName(), workingCopy).toLatin1();
|
const QByteArray &source = getSource(macro.fileName(), workingCopy).toLatin1();
|
||||||
m_currentSearch->addResult(macro.fileName(), macro.line(),
|
search->addResult(macro.fileName(), macro.line(),
|
||||||
source.mid(macro.offset(), macro.length()), 0, macro.length());
|
source.mid(macro.offset(), macro.length()), 0, macro.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<Usage> result;
|
QFuture<Usage> result;
|
||||||
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, this, macro);
|
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, this, macro);
|
||||||
m_watcher.setFuture(result);
|
createWatcher(result, search);
|
||||||
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
|
|
||||||
|
|
||||||
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
|
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
|
||||||
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
|
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
|
||||||
@@ -488,3 +488,13 @@ void CppFindReferences::setDependencyTable(const CPlusPlus::DependencyTable &new
|
|||||||
Q_UNUSED(locker);
|
Q_UNUSED(locker);
|
||||||
m_deps = newTable;
|
m_deps = newTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppFindReferences::createWatcher(const QFuture<Usage> &future, Find::SearchResult *search)
|
||||||
|
{
|
||||||
|
QFutureWatcher<Usage> *watcher = new QFutureWatcher<Usage>();
|
||||||
|
watcher->setFuture(future);
|
||||||
|
watcher->setPendingResultsLimit(1);
|
||||||
|
connect(watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
|
||||||
|
connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
|
||||||
|
m_watchers.insert(watcher, search);
|
||||||
|
}
|
||||||
|
|||||||
@@ -68,9 +68,6 @@ public:
|
|||||||
|
|
||||||
QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) const;
|
QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void changed();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
|
void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
|
||||||
void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
|
void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
|
||||||
@@ -88,14 +85,15 @@ private Q_SLOTS:
|
|||||||
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
|
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void findAll_helper(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
|
void findAll_helper(Find::SearchResult *search,
|
||||||
|
CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
|
||||||
CPlusPlus::DependencyTable dependencyTable() const;
|
CPlusPlus::DependencyTable dependencyTable() const;
|
||||||
void setDependencyTable(const CPlusPlus::DependencyTable &newTable);
|
void setDependencyTable(const CPlusPlus::DependencyTable &newTable);
|
||||||
|
void createWatcher(const QFuture<CPlusPlus::Usage> &future, Find::SearchResult *search);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<CPlusPlus::CppModelManagerInterface> _modelManager;
|
QPointer<CPlusPlus::CppModelManagerInterface> _modelManager;
|
||||||
QPointer<Find::SearchResult> m_currentSearch;
|
QMap<QFutureWatcher<CPlusPlus::Usage> *, QPointer<Find::SearchResult> > m_watchers;
|
||||||
QFutureWatcher<CPlusPlus::Usage> m_watcher;
|
|
||||||
|
|
||||||
mutable QMutex m_depsLock;
|
mutable QMutex m_depsLock;
|
||||||
CPlusPlus::DependencyTable m_deps;
|
CPlusPlus::DependencyTable m_deps;
|
||||||
|
|||||||
Reference in New Issue
Block a user