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