Commit f128a924 authored by Francois Ferrand's avatar Francois Ferrand Committed by Erik Verbruggen

Highlight references to macro under cursor.

Uses to be done only for symbols, implement for macros as well.

Change-Id: I5403527cc8b423e7051c3ce470e2f40ad65e65d5
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 8c3794f9
......@@ -833,19 +833,55 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf
if (! info.doc)
return;
CanonicalSymbol cs(this, info);
QString expression;
if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) {
m_references.cancel();
m_referencesRevision = info.revision;
m_referencesCursorPosition = position();
m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, info.doc, info.snapshot);
m_referencesWatcher.setFuture(m_references);
} else {
const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection);
if (const Macro *macro = findCanonicalMacro(textCursor(), info.doc)) {
QList<QTextEdit::ExtraSelection> selections;
//Macro definition
if (macro->fileName() == info.doc->fileName()) {
QTextCursor cursor(document());
cursor.setPosition(macro->offset());
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, macro->name().length());
QTextEdit::ExtraSelection sel;
sel.format = m_occurrencesFormat;
sel.cursor = cursor;
selections.append(sel);
}
//Other macro uses
foreach (Document::MacroUse use, info.doc->macroUses()) {
if (use.macro().line() != macro->line()
|| use.macro().offset() != macro->offset()
|| use.macro().length() != macro->length()
|| use.macro().fileName() != macro->fileName())
continue;
if (! selections.isEmpty())
setExtraSelections(CodeSemanticsSelection, QList<QTextEdit::ExtraSelection>());
QTextCursor cursor(document());
cursor.setPosition(use.begin());
cursor.setPosition(use.end(), QTextCursor::KeepAnchor);
QTextEdit::ExtraSelection sel;
sel.format = m_occurrencesFormat;
sel.cursor = cursor;
selections.append(sel);
}
setExtraSelections(CodeSemanticsSelection, selections);
} else {
CanonicalSymbol cs(this, info);
QString expression;
if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) {
m_references.cancel();
m_referencesRevision = info.revision;
m_referencesCursorPosition = position();
m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, info.doc, info.snapshot);
m_referencesWatcher.setFuture(m_references);
} else {
const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection);
if (! selections.isEmpty())
setExtraSelections(CodeSemanticsSelection, QList<QTextEdit::ExtraSelection>());
}
}
}
......
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