forked from qt-creator/qt-creator
Save the usages.
This commit is contained in:
@@ -57,17 +57,23 @@ void FindUsages::setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBi
|
|||||||
_globalNamespaceBinding = globalNamespaceBinding;
|
_globalNamespaceBinding = globalNamespaceBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> FindUsages::operator()(Symbol *symbol, const Identifier *id, AST *ast)
|
QList<Usage> FindUsages::usages() const
|
||||||
|
{ return _usages; }
|
||||||
|
|
||||||
|
QList<int> FindUsages::references() const
|
||||||
|
{ return _references; }
|
||||||
|
|
||||||
|
void FindUsages::operator()(Symbol *symbol, const Identifier *id, AST *ast)
|
||||||
{
|
{
|
||||||
_processed.clear();
|
_processed.clear();
|
||||||
_references.clear();
|
_references.clear();
|
||||||
|
_usages.clear();
|
||||||
_declSymbol = symbol;
|
_declSymbol = symbol;
|
||||||
_id = id;
|
_id = id;
|
||||||
if (_declSymbol && _id) {
|
if (_declSymbol && _id) {
|
||||||
_exprDoc = Document::create("<references>");
|
_exprDoc = Document::create("<references>");
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
return _references;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FindUsages::matchingLine(const Token &tk) const
|
QString FindUsages::matchingLine(const Token &tk) const
|
||||||
@@ -120,9 +126,11 @@ void FindUsages::reportResult(unsigned tokenIndex)
|
|||||||
|
|
||||||
const int len = tk.f.length;
|
const int len = tk.f.length;
|
||||||
|
|
||||||
if (_future) {
|
const Usage u(_doc->fileName(), line, lineText, col, len);
|
||||||
_future->reportResult(Usage(_doc->fileName(), line, lineText, col, len));
|
_usages.append(u);
|
||||||
}
|
|
||||||
|
if (_future)
|
||||||
|
_future->reportResult(u);
|
||||||
|
|
||||||
_references.append(tokenIndex);
|
_references.append(tokenIndex);
|
||||||
}
|
}
|
||||||
|
@@ -47,12 +47,12 @@ public:
|
|||||||
: line(0), col(0), len(0) {}
|
: line(0), col(0), len(0) {}
|
||||||
|
|
||||||
Usage(const QString &path, int line, const QString &lineText, int col, int len)
|
Usage(const QString &path, int line, const QString &lineText, int col, int len)
|
||||||
: path(path), line(line), lineText(lineText), col(col), len(len) {}
|
: path(path), lineText(lineText), line(line), col(col), len(len) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString path;
|
QString path;
|
||||||
int line;
|
|
||||||
QString lineText;
|
QString lineText;
|
||||||
|
int line;
|
||||||
int col;
|
int col;
|
||||||
int len;
|
int len;
|
||||||
};
|
};
|
||||||
@@ -64,7 +64,10 @@ public:
|
|||||||
|
|
||||||
void setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding);
|
void setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding);
|
||||||
|
|
||||||
QList<int> operator()(Symbol *symbol, const Identifier *id, AST *ast);
|
void operator()(Symbol *symbol, const Identifier *id, AST *ast);
|
||||||
|
|
||||||
|
QList<Usage> usages() const;
|
||||||
|
QList<int> references() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using ASTVisitor::visit;
|
using ASTVisitor::visit;
|
||||||
@@ -112,6 +115,7 @@ private:
|
|||||||
QList<PostfixExpressionAST *> _postfixExpressionStack;
|
QList<PostfixExpressionAST *> _postfixExpressionStack;
|
||||||
QList<QualifiedNameAST *> _qualifiedNameStack;
|
QList<QualifiedNameAST *> _qualifiedNameStack;
|
||||||
QList<int> _references;
|
QList<int> _references;
|
||||||
|
QList<Usage> _usages;
|
||||||
LookupContext _previousContext;
|
LookupContext _previousContext;
|
||||||
int _inSimpleDeclaration;
|
int _inSimpleDeclaration;
|
||||||
QSet<unsigned> _processed;
|
QSet<unsigned> _processed;
|
||||||
|
@@ -91,9 +91,10 @@ QList<int> CppFindReferences::references(Symbol *symbol,
|
|||||||
TranslationUnit *translationUnit = doc->translationUnit();
|
TranslationUnit *translationUnit = doc->translationUnit();
|
||||||
Q_ASSERT(translationUnit != 0);
|
Q_ASSERT(translationUnit != 0);
|
||||||
|
|
||||||
FindUsages process(doc, snapshot, /*future = */ 0);
|
FindUsages findUsages(doc, snapshot, /*future = */ 0);
|
||||||
process.setGlobalNamespaceBinding(bind(doc, snapshot));
|
findUsages.setGlobalNamespaceBinding(bind(doc, snapshot));
|
||||||
references = process(symbol, id, translationUnit->ast());
|
findUsages(symbol, id, translationUnit->ast());
|
||||||
|
references = findUsages.references();
|
||||||
|
|
||||||
return references;
|
return references;
|
||||||
}
|
}
|
||||||
@@ -229,7 +230,10 @@ void CppFindReferences::findAll_helper(Symbol *symbol)
|
|||||||
const QMap<QString, QString> wl = _modelManager->workingCopy();
|
const QMap<QString, QString> wl = _modelManager->workingCopy();
|
||||||
|
|
||||||
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
|
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
|
||||||
QFuture<Usage> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol);
|
|
||||||
|
QFuture<Usage> result;
|
||||||
|
|
||||||
|
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..."),
|
||||||
|
Reference in New Issue
Block a user