Commit 86e21bc2 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Look at the working copy when searching for references.

parent 4bc4bd0f
...@@ -322,6 +322,7 @@ CppFindReferences::~CppFindReferences() ...@@ -322,6 +322,7 @@ CppFindReferences::~CppFindReferences()
} }
static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future, static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
const QMap<QString, QString> wl,
Snapshot snapshot, Snapshot snapshot,
Symbol *symbol) Symbol *symbol)
{ {
...@@ -339,7 +340,6 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future, ...@@ -339,7 +340,6 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
future.setProgressRange(0, files.size()); future.setProgressRange(0, files.size());
tm.start();
for (int i = 0; i < files.size(); ++i) { for (int i = 0; i < files.size(); ++i) {
const QString &fn = files.at(i); const QString &fn = files.at(i);
future.setProgressValueAndText(i, QFileInfo(fn).fileName()); future.setProgressValueAndText(i, QFileInfo(fn).fileName());
...@@ -356,9 +356,20 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future, ...@@ -356,9 +356,20 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
if (! f.open(QFile::ReadOnly)) if (! f.open(QFile::ReadOnly))
continue; continue;
const QString source = QTextStream(&f).readAll(); // ### FIXME QByteArray source;
const QByteArray preprocessedCode = snapshot.preprocessedCode(source, fn);
Document::Ptr doc = snapshot.documentFromSource(preprocessedCode, fn); if (wl.contains(fileName))
source = snapshot.preprocessedCode(wl.value(fileName), fileName);
else {
QFile file(fileName);
if (! file.open(QFile::ReadOnly))
continue;
const QString contents = QTextStream(&file).readAll(); // ### FIXME
source = snapshot.preprocessedCode(contents, fileName);
}
Document::Ptr doc = snapshot.documentFromSource(source, fileName);
doc->tokenize(); doc->tokenize();
Control *control = doc->control(); Control *control = doc->control();
...@@ -369,17 +380,21 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future, ...@@ -369,17 +380,21 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
process(symbol, id, unit->ast()); process(symbol, id, unit->ast());
} }
} }
future.setProgressValue(files.size()); future.setProgressValue(files.size());
} }
void CppFindReferences::findAll(const Snapshot &snapshot, Symbol *symbol) void CppFindReferences::findAll(Symbol *symbol)
{ {
_resultWindow->clearContents(); _resultWindow->clearContents();
_resultWindow->popup(true); _resultWindow->popup(true);
const Snapshot snapshot = _modelManager->snapshot();
const QMap<QString, QString> wl = _modelManager->buildWorkingCopyList();
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
QFuture<Core::Utils::FileSearchResult> result = QtConcurrent::run(&find_helper, snapshot, symbol); QFuture<Core::Utils::FileSearchResult> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol);
m_watcher.setFuture(result); m_watcher.setFuture(result);
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching..."), Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching..."),
......
...@@ -62,7 +62,7 @@ Q_SIGNALS: ...@@ -62,7 +62,7 @@ Q_SIGNALS:
void changed(); void changed();
public: public:
void findAll(const CPlusPlus::Snapshot &snapshot, CPlusPlus::Symbol *symbol); void findAll(CPlusPlus::Symbol *symbol);
private Q_SLOTS: private Q_SLOTS:
void displayResult(int); void displayResult(int);
......
...@@ -742,7 +742,7 @@ void CppModelManager::removeEditorSupport(AbstractEditorSupport *editorSupport) ...@@ -742,7 +742,7 @@ void CppModelManager::removeEditorSupport(AbstractEditorSupport *editorSupport)
void CppModelManager::findReferences(CPlusPlus::Symbol *symbol) void CppModelManager::findReferences(CPlusPlus::Symbol *symbol)
{ {
if (symbol->identifier()) if (symbol->identifier())
m_findReferences->findAll(snapshot(), symbol); m_findReferences->findAll(symbol);
} }
QMap<QString, QString> CppModelManager::buildWorkingCopyList() QMap<QString, QString> CppModelManager::buildWorkingCopyList()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment