Commit 86799309 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Keep the locator database in sync with the current snapshot.

Thanks to this patch we can move the filtering of C++ symbols
in a background thread.

Done-with: Erik Verbruggen
parent 6863b02e
......@@ -375,6 +375,9 @@ struct CanonicalSymbol
};
int numberOfClosedEditors = 0;
} // end of anonymous namespace
CPPEditorEditable::CPPEditorEditable(CPPEditor *editor)
......@@ -428,6 +431,12 @@ CPPEditor::~CPPEditor()
m_semanticHighlighter->abort();
m_semanticHighlighter->wait();
++numberOfClosedEditors;
if (numberOfClosedEditors == 5) {
m_modelManager->GC();
numberOfClosedEditors = 0;
}
}
TextEditor::BaseTextEditorEditable *CPPEditor::createEditableInterface()
......
......@@ -56,7 +56,7 @@ CppLocatorFilter::~CppLocatorFilter()
void CppLocatorFilter::onDocumentUpdated(CPlusPlus::Document::Ptr doc)
{
m_searchList[doc->fileName()] = Info(doc);
m_searchList[doc->fileName()] = search(doc);
}
void CppLocatorFilter::onAboutToRemoveFiles(const QStringList &files)
......@@ -88,20 +88,12 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(const QString &origEntr
return goodEntries;
bool hasWildcard = (entry.contains(asterisk) || entry.contains('?'));
QMutableMapIterator<QString, Info> it(m_searchList);
QHashIterator<QString, QList<ModelItemInfo> > it(m_searchList);
while (it.hasNext()) {
it.next();
Info info = it.value();
if (info.dirty) {
info.dirty = false;
info.items = search(info.doc);
it.setValue(info);
}
QList<ModelItemInfo> items = info.items;
foreach (ModelItemInfo info, items) {
const QList<ModelItemInfo> items = it.value();
foreach (const ModelItemInfo &info, items) {
if ((hasWildcard && regexp.exactMatch(info.symbolName))
|| (!hasWildcard && matcher.indexIn(info.symbolName) != -1)) {
......
......@@ -31,7 +31,6 @@
#define CPPLOCATORFILTER_H
#include "searchsymbols.h"
#include <locator/ilocatorfilter.h>
namespace CppTools {
......@@ -63,16 +62,7 @@ private slots:
private:
CppModelManager *m_manager;
struct Info {
Info(): dirty(true) {}
Info(CPlusPlus::Document::Ptr doc): doc(doc), dirty(true) {}
CPlusPlus::Document::Ptr doc;
QList<ModelItemInfo> items;
bool dirty;
};
QMap<QString, Info> m_searchList;
QHash<QString, QList<ModelItemInfo> > m_searchList;
QList<ModelItemInfo> m_previousResults;
bool m_forceNewSearchList;
QString m_previousEntry;
......
......@@ -67,6 +67,7 @@ QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, const QString
accept(doc->globalSymbolAt(i));
}
(void) switchScope(previousScope);
strings.clear();
return items;
}
......@@ -216,10 +217,17 @@ void SearchSymbols::appendItem(const QString &name,
QStringList fullyQualifiedName;
foreach (const Name *name, LookupContext::fullyQualifiedName(symbol))
fullyQualifiedName.append(overview.prettyName(name));
QString path = m_paths.value(symbol->fileId(), QString());
if (path.isEmpty()) {
path = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
m_paths.insert(symbol->fileId(), path);
}
const QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, info, type,
fullyQualifiedName,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
path,
symbol->line(),
symbol->column() - 1, // 1-based vs 0-based column
icon));
......
......@@ -40,6 +40,7 @@
#include <QMetaType>
#include <QString>
#include <QSet>
#include <QHash>
#include <functional>
......@@ -66,33 +67,33 @@ struct ModelItemInfo
const QIcon &icon)
: symbolName(symbolName),
symbolType(symbolType),
type(type),
fullyQualifiedName(fullyQualifiedName),
fileName(fileName),
icon(icon),
type(type),
line(line),
column(column),
icon(icon)
column(column)
{ }
ModelItemInfo(const ModelItemInfo &otherInfo)
: symbolName(otherInfo.symbolName),
symbolType(otherInfo.symbolType),
type(otherInfo.type),
fullyQualifiedName(otherInfo.fullyQualifiedName),
fileName(otherInfo.fileName),
icon(otherInfo.icon),
type(otherInfo.type),
line(otherInfo.line),
column(otherInfo.column),
icon(otherInfo.icon)
column(otherInfo.column)
{ }
QString symbolName;
QString symbolType;
ItemType type;
QStringList fullyQualifiedName;
QString fileName;
QIcon icon;
ItemType type;
int line;
int column;
QIcon icon;
};
class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<ModelItemInfo> >,
......@@ -152,6 +153,7 @@ private:
CPlusPlus::Icons icons;
QList<ModelItemInfo> items;
SymbolTypes symbolsToSearchFor;
QHash<const CPlusPlus::StringLiteral *, QString> m_paths;
bool separateScope;
};
......
......@@ -439,7 +439,6 @@ static void filter_helper(QFutureInterface<FilterEntry> &entries, QList<ILocator
foreach (const FilterEntry &entry, filter->matchesFor(searchText)) {
if (checkDuplicates && alreadyAdded.contains(entry))
continue;
//entries.append(entry);
entries.reportResult(entry);
if (checkDuplicates)
alreadyAdded.insert(entry);
......@@ -457,7 +456,6 @@ void LocatorWidget::updateCompletionList(const QString &text)
QFuture<FilterEntry> future = QtConcurrent::run(filter_helper, filters, searchText);
m_entriesWatcher->setFuture(future);
future.waitForFinished();
}
void LocatorWidget::updateEntries()
......
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