diff options
author | Francois Ferrand <thetypz@gmail.com> | 2013-01-17 14:44:22 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-01-23 14:36:59 +0100 |
commit | f128a92485b98339fab0d8dff8846bcd5c8f996f (patch) | |
tree | abb07d325d5b1f6d3e2773bc7b09b2509f6743d6 /src | |
parent | 8c3794f9d104a39b7f91764b7725dad8726fbde0 (diff) | |
download | qt-creator-f128a92485b98339fab0d8dff8846bcd5c8f996f.tar.gz |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 6db81d92a8..04310fe302 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -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>()); + } } } |