forked from qt-creator/qt-creator
Make the symbols used in the current editors.
This commit is contained in:
@@ -830,11 +830,11 @@ void CPPEditor::reformatDocument()
|
|||||||
c.insertText(QString::fromUtf8(str.c_str(), str.length()));
|
c.insertText(QString::fromUtf8(str.c_str(), str.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPEditor::findReferences()
|
CPlusPlus::Symbol *CPPEditor::findCanonicalSymbol(const QTextCursor &cursor,
|
||||||
|
Document::Ptr doc,
|
||||||
|
const Snapshot &snapshot) const
|
||||||
{
|
{
|
||||||
QTextCursor tc = textCursor();
|
QTextCursor tc = cursor;
|
||||||
m_currentRenameSelection = -1;
|
|
||||||
|
|
||||||
int line, col;
|
int line, col;
|
||||||
convertPosition(tc.position(), &line, &col);
|
convertPosition(tc.position(), &line, &col);
|
||||||
++col;
|
++col;
|
||||||
@@ -843,10 +843,9 @@ void CPPEditor::findReferences()
|
|||||||
|
|
||||||
ExpressionUnderCursor expressionUnderCursor;
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
const QString code = expressionUnderCursor(tc);
|
const QString code = expressionUnderCursor(tc);
|
||||||
qDebug() << "code:" << code;
|
// qDebug() << "code:" << code;
|
||||||
|
|
||||||
Snapshot snapshot = m_modelManager->snapshot();
|
const QString fileName = const_cast<CPPEditor *>(this)->file()->fileName();
|
||||||
Document::Ptr doc = snapshot.value(file()->fileName());
|
|
||||||
|
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.setSnapshot(snapshot);
|
typeOfExpression.setSnapshot(snapshot);
|
||||||
@@ -857,8 +856,46 @@ void CPPEditor::findReferences()
|
|||||||
lastVisibleSymbol,
|
lastVisibleSymbol,
|
||||||
TypeOfExpression::Preprocess);
|
TypeOfExpression::Preprocess);
|
||||||
|
|
||||||
if (Symbol *canonicalSymbol = LookupContext::canonicalSymbol(results)) {
|
Symbol *canonicalSymbol = LookupContext::canonicalSymbol(results);
|
||||||
m_modelManager->findReferences(canonicalSymbol);
|
return canonicalSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPPEditor::findReferences()
|
||||||
|
{
|
||||||
|
m_currentRenameSelection = -1;
|
||||||
|
|
||||||
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
|
|
||||||
|
SemanticInfo info = m_lastSemanticInfo;
|
||||||
|
|
||||||
|
if (info.doc) {
|
||||||
|
if (Symbol *canonicalSymbol = findCanonicalSymbol(textCursor(), info.doc, info.snapshot)) {
|
||||||
|
TranslationUnit *unit = info.doc->translationUnit();
|
||||||
|
|
||||||
|
const QList<int> references = m_modelManager->references(canonicalSymbol, info.doc, info.snapshot);
|
||||||
|
foreach (int index, references) {
|
||||||
|
unsigned line, column;
|
||||||
|
unit->getTokenPosition(index, &line, &column);
|
||||||
|
|
||||||
|
if (column)
|
||||||
|
--column; // adjust the column position.
|
||||||
|
|
||||||
|
const int len = unit->tokenAt(index).f.length;
|
||||||
|
|
||||||
|
QTextCursor cursor(document()->findBlockByNumber(line - 1));
|
||||||
|
cursor.setPosition(cursor.position() + column);
|
||||||
|
cursor.setPosition(cursor.position() + len, QTextCursor::KeepAnchor);
|
||||||
|
|
||||||
|
QTextEdit::ExtraSelection sel;
|
||||||
|
sel.format = m_occurrencesFormat;
|
||||||
|
sel.cursor = cursor;
|
||||||
|
selections.append(sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
setExtraSelections(CodeSemanticsSelection, selections);
|
||||||
|
|
||||||
|
m_modelManager->findReferences(canonicalSymbol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2015,7 +2052,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
|
|||||||
doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName);
|
doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName);
|
||||||
doc->check();
|
doc->check();
|
||||||
|
|
||||||
snapshot = source.snapshot.simplified(doc);
|
snapshot = source.snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
Control *control = doc->control();
|
Control *control = doc->control();
|
||||||
|
@@ -223,6 +223,10 @@ protected:
|
|||||||
|
|
||||||
bool isInComment(const QTextCursor &cursor) const;
|
bool isInComment(const QTextCursor &cursor) const;
|
||||||
|
|
||||||
|
CPlusPlus::Symbol *findCanonicalSymbol(const QTextCursor &cursor,
|
||||||
|
CPlusPlus::Document::Ptr doc,
|
||||||
|
const CPlusPlus::Snapshot &snapshot) const;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateFileName();
|
void updateFileName();
|
||||||
void jumpToMethod(int index);
|
void jumpToMethod(int index);
|
||||||
|
@@ -67,8 +67,8 @@ namespace {
|
|||||||
struct Process: protected ASTVisitor
|
struct Process: protected ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Process(QFutureInterface<Core::Utils::FileSearchResult> &future,
|
Process(Document::Ptr doc, const Snapshot &snapshot,
|
||||||
Document::Ptr doc, const Snapshot &snapshot)
|
QFutureInterface<Core::Utils::FileSearchResult> *future)
|
||||||
: ASTVisitor(doc->control()),
|
: ASTVisitor(doc->control()),
|
||||||
_future(future),
|
_future(future),
|
||||||
_doc(doc),
|
_doc(doc),
|
||||||
@@ -79,12 +79,14 @@ public:
|
|||||||
_snapshot.insert(_doc);
|
_snapshot.insert(_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(Symbol *symbol, Identifier *id, AST *ast)
|
QList<int> operator()(Symbol *symbol, Identifier *id, AST *ast)
|
||||||
{
|
{
|
||||||
|
_references.clear();
|
||||||
_declSymbol = symbol;
|
_declSymbol = symbol;
|
||||||
_id = id;
|
_id = id;
|
||||||
_exprDoc = Document::create("<references>");
|
_exprDoc = Document::create("<references>");
|
||||||
accept(ast);
|
accept(ast);
|
||||||
|
return _references;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -123,10 +125,13 @@ protected:
|
|||||||
if (col)
|
if (col)
|
||||||
--col; // adjust the column position.
|
--col; // adjust the column position.
|
||||||
|
|
||||||
int len = tk.f.length;
|
const int len = tk.f.length;
|
||||||
|
|
||||||
_future.reportResult(Core::Utils::FileSearchResult(QDir::toNativeSeparators(_doc->fileName()),
|
if (_future)
|
||||||
line, lineText, col, len));
|
_future->reportResult(Core::Utils::FileSearchResult(QDir::toNativeSeparators(_doc->fileName()),
|
||||||
|
line, lineText, col, len));
|
||||||
|
|
||||||
|
_references.append(tokenIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkCandidates(const QList<Symbol *> &candidates) const
|
bool checkCandidates(const QList<Symbol *> &candidates) const
|
||||||
@@ -351,7 +356,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFutureInterface<Core::Utils::FileSearchResult> &_future;
|
QFutureInterface<Core::Utils::FileSearchResult> *_future;
|
||||||
Identifier *_id; // ### remove me
|
Identifier *_id; // ### remove me
|
||||||
Symbol *_declSymbol;
|
Symbol *_declSymbol;
|
||||||
Document::Ptr _doc;
|
Document::Ptr _doc;
|
||||||
@@ -361,6 +366,7 @@ private:
|
|||||||
Semantic _sem;
|
Semantic _sem;
|
||||||
QList<PostfixExpressionAST *> _postfixExpressionStack;
|
QList<PostfixExpressionAST *> _postfixExpressionStack;
|
||||||
QList<QualifiedNameAST *> _qualifiedNameStack;
|
QList<QualifiedNameAST *> _qualifiedNameStack;
|
||||||
|
QList<int> _references;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
@@ -378,6 +384,28 @@ CppFindReferences::~CppFindReferences()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<int> CppFindReferences::references(Symbol *symbol,
|
||||||
|
Document::Ptr doc,
|
||||||
|
const Snapshot& snapshot) const
|
||||||
|
{
|
||||||
|
Identifier *id = 0;
|
||||||
|
if (Identifier *symbolId = symbol->identifier())
|
||||||
|
id = doc->control()->findIdentifier(symbolId->chars(), symbolId->size());
|
||||||
|
|
||||||
|
QList<int> references;
|
||||||
|
|
||||||
|
if (! id)
|
||||||
|
return references;
|
||||||
|
|
||||||
|
TranslationUnit *translationUnit = doc->translationUnit();
|
||||||
|
Q_ASSERT(translationUnit != 0);
|
||||||
|
|
||||||
|
Process process(doc, snapshot, /*future = */ 0);
|
||||||
|
references = process(symbol, id, translationUnit->ast());
|
||||||
|
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
|
static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
|
||||||
const QMap<QString, QString> wl,
|
const QMap<QString, QString> wl,
|
||||||
Snapshot snapshot,
|
Snapshot snapshot,
|
||||||
@@ -429,7 +457,7 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
|
|||||||
if (Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size())) {
|
if (Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size())) {
|
||||||
doc->check();
|
doc->check();
|
||||||
TranslationUnit *unit = doc->translationUnit();
|
TranslationUnit *unit = doc->translationUnit();
|
||||||
Process process(future, doc, snapshot);
|
Process process(doc, snapshot, &future);
|
||||||
process(symbol, id, unit->ast());
|
process(symbol, id, unit->ast());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,16 +35,12 @@
|
|||||||
#include <QtCore/QFuture>
|
#include <QtCore/QFuture>
|
||||||
#include <QtCore/QFutureWatcher>
|
#include <QtCore/QFutureWatcher>
|
||||||
#include <utils/filesearch.h>
|
#include <utils/filesearch.h>
|
||||||
|
#include <cplusplus/CppDocument.h>
|
||||||
|
|
||||||
namespace Find {
|
namespace Find {
|
||||||
class SearchResultWindow;
|
class SearchResultWindow;
|
||||||
} // end of namespace Find
|
} // end of namespace Find
|
||||||
|
|
||||||
namespace CPlusPlus {
|
|
||||||
class Snapshot;
|
|
||||||
class Symbol;
|
|
||||||
} // end of namespace CPlusPlus
|
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -58,6 +54,10 @@ public:
|
|||||||
CppFindReferences(CppModelManager *modelManager);
|
CppFindReferences(CppModelManager *modelManager);
|
||||||
virtual ~CppFindReferences();
|
virtual ~CppFindReferences();
|
||||||
|
|
||||||
|
QList<int> references(CPlusPlus::Symbol *symbol,
|
||||||
|
CPlusPlus::Document::Ptr doc,
|
||||||
|
const CPlusPlus::Snapshot& snapshot) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
|
@@ -739,6 +739,13 @@ void CppModelManager::removeEditorSupport(AbstractEditorSupport *editorSupport)
|
|||||||
m_addtionalEditorSupport.remove(editorSupport);
|
m_addtionalEditorSupport.remove(editorSupport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<int> CppModelManager::references(CPlusPlus::Symbol *symbol,
|
||||||
|
CPlusPlus::Document::Ptr doc,
|
||||||
|
const CPlusPlus::Snapshot &snapshot)
|
||||||
|
{
|
||||||
|
return m_findReferences->references(LookupContext::canonicalSymbol(symbol), doc, snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
void CppModelManager::findReferences(CPlusPlus::Symbol *symbol)
|
void CppModelManager::findReferences(CPlusPlus::Symbol *symbol)
|
||||||
{
|
{
|
||||||
if (symbol->identifier())
|
if (symbol->identifier())
|
||||||
|
@@ -102,6 +102,10 @@ public:
|
|||||||
virtual void addEditorSupport(AbstractEditorSupport *editorSupport);
|
virtual void addEditorSupport(AbstractEditorSupport *editorSupport);
|
||||||
virtual void removeEditorSupport(AbstractEditorSupport *editorSupport);
|
virtual void removeEditorSupport(AbstractEditorSupport *editorSupport);
|
||||||
|
|
||||||
|
virtual QList<int> references(CPlusPlus::Symbol *symbol,
|
||||||
|
CPlusPlus::Document::Ptr doc,
|
||||||
|
const CPlusPlus::Snapshot &snapshot);
|
||||||
|
|
||||||
virtual void findReferences(CPlusPlus::Symbol *symbol);
|
virtual void findReferences(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
void setHeaderSuffixes(const QStringList &suffixes)
|
void setHeaderSuffixes(const QStringList &suffixes)
|
||||||
|
@@ -95,6 +95,10 @@ public:
|
|||||||
virtual void addEditorSupport(AbstractEditorSupport *editorSupport) = 0;
|
virtual void addEditorSupport(AbstractEditorSupport *editorSupport) = 0;
|
||||||
virtual void removeEditorSupport(AbstractEditorSupport *editorSupport) = 0;
|
virtual void removeEditorSupport(AbstractEditorSupport *editorSupport) = 0;
|
||||||
|
|
||||||
|
virtual QList<int> references(CPlusPlus::Symbol *symbol,
|
||||||
|
CPlusPlus::Document::Ptr doc,
|
||||||
|
const CPlusPlus::Snapshot &snapshot) = 0;
|
||||||
|
|
||||||
virtual void findReferences(CPlusPlus::Symbol *symbol) = 0;
|
virtual void findReferences(CPlusPlus::Symbol *symbol) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user