forked from qt-creator/qt-creator
Highlight unused symbols.
This commit is contained in:
@@ -908,7 +908,6 @@ void CPPEditor::renameSymbolUnderCursor()
|
|||||||
QTextCursor c = textCursor();
|
QTextCursor c = textCursor();
|
||||||
m_currentRenameSelection = -1;
|
m_currentRenameSelection = -1;
|
||||||
|
|
||||||
m_renameSelections = extraSelections(CodeSemanticsSelection);
|
|
||||||
for (int i = 0; i < m_renameSelections.size(); ++i) {
|
for (int i = 0; i < m_renameSelections.size(); ++i) {
|
||||||
QTextEdit::ExtraSelection s = m_renameSelections.at(i);
|
QTextEdit::ExtraSelection s = m_renameSelections.at(i);
|
||||||
if (c.position() >= s.cursor.anchor()
|
if (c.position() >= s.cursor.anchor()
|
||||||
@@ -980,10 +979,9 @@ void CPPEditor::highlightUses(const QList<SemanticInfo::Use> &uses,
|
|||||||
QList<QTextEdit::ExtraSelection> *selections)
|
QList<QTextEdit::ExtraSelection> *selections)
|
||||||
{
|
{
|
||||||
bool isUnused = false;
|
bool isUnused = false;
|
||||||
if (uses.size() == 1) {
|
|
||||||
|
if (uses.size() == 1)
|
||||||
isUnused = true;
|
isUnused = true;
|
||||||
return; // ###
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const SemanticInfo::Use &use, uses) {
|
foreach (const SemanticInfo::Use &use, uses) {
|
||||||
QTextEdit::ExtraSelection sel;
|
QTextEdit::ExtraSelection sel;
|
||||||
@@ -1882,7 +1880,6 @@ void CPPEditor::setFontSettings(const TextEditor::FontSettings &fs)
|
|||||||
|
|
||||||
// only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link
|
// only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link
|
||||||
m_occurrencesFormat.clearForeground();
|
m_occurrencesFormat.clearForeground();
|
||||||
m_occurrencesUnusedFormat.clearForeground();
|
|
||||||
m_occurrenceRenameFormat.clearForeground();
|
m_occurrenceRenameFormat.clearForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1944,7 +1941,9 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
convertPosition(position(), &line, &column);
|
convertPosition(position(), &line, &column);
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> selections;
|
QList<QTextEdit::ExtraSelection> allSelections;
|
||||||
|
|
||||||
|
m_renameSelections.clear();
|
||||||
|
|
||||||
SemanticInfo::LocalUseIterator it(semanticInfo.localUses);
|
SemanticInfo::LocalUseIterator it(semanticInfo.localUses);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -1961,11 +1960,18 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uses.size() == 1 || good)
|
if (uses.size() == 1) {
|
||||||
|
// it's an unused declaration
|
||||||
|
highlightUses(uses, &allSelections);
|
||||||
|
} else if (good) {
|
||||||
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
highlightUses(uses, &selections);
|
highlightUses(uses, &selections);
|
||||||
|
m_renameSelections += selections;
|
||||||
|
allSelections += selections;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setExtraSelections(CodeSemanticsSelection, selections);
|
setExtraSelections(CodeSemanticsSelection, allSelections);
|
||||||
}
|
}
|
||||||
|
|
||||||
SemanticHighlighter::Source CPPEditor::currentSource()
|
SemanticHighlighter::Source CPPEditor::currentSource()
|
||||||
|
|||||||
Reference in New Issue
Block a user