Highlight references to macro under cursor.

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

Change-Id: I5403527cc8b423e7051c3ce470e2f40ad65e65d5
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Francois Ferrand
2013-01-17 14:44:22 +01:00
committed by Erik Verbruggen
parent 8c3794f9d1
commit f128a92485

View File

@@ -833,6 +833,41 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf
if (! info.doc) if (! info.doc)
return; return;
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;
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); CanonicalSymbol cs(this, info);
QString expression; QString expression;
if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) { if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) {
@@ -848,6 +883,7 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf
setExtraSelections(CodeSemanticsSelection, QList<QTextEdit::ExtraSelection>()); setExtraSelections(CodeSemanticsSelection, QList<QTextEdit::ExtraSelection>());
} }
} }
}
void CPPEditorWidget::renameSymbolUnderCursor() void CPPEditorWidget::renameSymbolUnderCursor()
{ {