Commit 0f301f86 authored by Roberto Raggi's avatar Roberto Raggi

New implementation of CPlusPlus::FindUsages

parent f72a080d
This diff is collapsed.
This diff is collapsed.
......@@ -739,12 +739,14 @@ void CPPEditor::markSymbolsNow()
setExtraSelections(CodeSemanticsSelection, selections);
}
static QList<int> lazyFindReferences(Scope *scope, QString code, const LookupContext &context)
static QList<int> lazyFindReferences(Scope *scope, QString code, Document::Ptr doc, Snapshot snapshot)
{
TypeOfExpression typeOfExpression;
typeOfExpression.init(context.thisDocument(), context.snapshot(), context.bindings());
if (Symbol *canonicalSymbol = CanonicalSymbol::canonicalSymbol(scope, code, typeOfExpression))
return CppTools::CppModelManagerInterface::instance()->references(canonicalSymbol, context);
snapshot.insert(doc);
typeOfExpression.init(doc, snapshot);
if (Symbol *canonicalSymbol = CanonicalSymbol::canonicalSymbol(scope, code, typeOfExpression)) {
return CppTools::CppModelManagerInterface::instance()->references(canonicalSymbol, typeOfExpression.context());
}
return QList<int>();
}
......@@ -758,12 +760,10 @@ void CPPEditor::markSymbols(const QTextCursor &tc, const SemanticInfo &info)
CanonicalSymbol cs(this, info);
QString expression;
if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) {
LookupContext context(info.doc, info.snapshot);
m_references.cancel();
m_referencesRevision = info.revision;
m_referencesCursorPosition = position();
m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, context);
m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, info.doc, info.snapshot);
m_referencesWatcher.setFuture(m_references);
} else {
const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection);
......
......@@ -52,6 +52,7 @@
#include <cplusplus/CppDocument.h>
#include <cplusplus/Overview.h>
#include <cplusplus/FindUsages.h>
#include <QtCore/QTime>
#include <QtCore/QTimer>
......@@ -108,18 +109,25 @@ public:
return usages; // skip this document, it's not using symbolId.
}
QByteArray source = snapshot.preprocessedCode(
getSource(fileName, workingCopy), fileName);
Document::Ptr doc;
QByteArray source;
Document::Ptr doc = snapshot.documentFromSource(source, fileName);
doc->tokenize();
if (symbolDocument && fileName == symbolDocument->fileName())
doc = symbolDocument;
else {
source = snapshot.preprocessedCode(getSource(fileName, workingCopy), fileName);
doc = snapshot.documentFromSource(source, fileName);
doc->tokenize();
}
Control *control = doc->control();
if (control->findIdentifier(symbolId->chars(), symbolId->size()) != 0) {
doc->check();
if (doc != symbolDocument)
doc->check();
FindUsages process(doc, snapshot);
process(symbol);
usages = process.usages();
}
......
......@@ -56,6 +56,7 @@
#include "TypeMatcher.h"
#include <map>
#include <set>
#include <algorithm>
using namespace CPlusPlus;
......@@ -770,3 +771,8 @@ const Identifier *Control::objcCopyId() const
const Identifier *Control::objcNonatomicId() const
{ return d->objcNonatomicId; }
bool Control::hasSymbol(Symbol *symbol) const
{
return std::find(d->symbols.begin(), d->symbols.end(), symbol) != d->symbols.end();
}
......@@ -209,6 +209,8 @@ public:
const NumericLiteral *findOrInsertNumericLiteral(const char *chars, unsigned size);
const NumericLiteral *findOrInsertNumericLiteral(const char *chars);
bool hasSymbol(Symbol *symbol) const;
private:
class Data;
friend class Data;
......
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