forked from qt-creator/qt-creator
Created methods for semantic selection creation.
This commit is contained in:
@@ -1839,6 +1839,64 @@ void CPPEditor::semanticRehighlight()
|
|||||||
m_semanticHighlighter->rehighlight(currentSource());
|
m_semanticHighlighter->rehighlight(currentSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QList<QTextEdit::ExtraSelection> createSelections(QTextDocument *document,
|
||||||
|
const QList<CPlusPlus::Document::DiagnosticMessage> &msgs,
|
||||||
|
const QTextCharFormat &format)
|
||||||
|
{
|
||||||
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
|
|
||||||
|
foreach (const Document::DiagnosticMessage &m, msgs) {
|
||||||
|
QTextCursor cursor(document);
|
||||||
|
cursor.setPosition(document->findBlockByNumber(m.line() - 1).position() + m.column() - 1);
|
||||||
|
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length());
|
||||||
|
|
||||||
|
QTextEdit::ExtraSelection sel;
|
||||||
|
sel.cursor = cursor;
|
||||||
|
sel.format = format;
|
||||||
|
sel.format.setToolTip(m.text());
|
||||||
|
selections.append(sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return selections;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QList<QTextEdit::ExtraSelection> createSelections(QTextDocument *document,
|
||||||
|
const QList<SemanticInfo::Use> &msgs,
|
||||||
|
const QTextCharFormat &format)
|
||||||
|
{
|
||||||
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
|
|
||||||
|
QTextBlock currentBlock = document->firstBlock();
|
||||||
|
unsigned currentLine = 1;
|
||||||
|
|
||||||
|
foreach (const SemanticInfo::Use &use, msgs) {
|
||||||
|
QTextCursor cursor(document);
|
||||||
|
|
||||||
|
if (currentLine != use.line) {
|
||||||
|
int delta = use.line - currentLine;
|
||||||
|
|
||||||
|
if (delta >= 0) {
|
||||||
|
while (delta--)
|
||||||
|
currentBlock = currentBlock.next();
|
||||||
|
} else {
|
||||||
|
currentBlock = document->findBlockByNumber(use.line - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLine = use.line;
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.setPosition(currentBlock.position() + use.column - 1);
|
||||||
|
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, use.length);
|
||||||
|
|
||||||
|
QTextEdit::ExtraSelection sel;
|
||||||
|
sel.cursor = cursor;
|
||||||
|
sel.format = format;
|
||||||
|
selections.append(sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return selections;
|
||||||
|
}
|
||||||
|
|
||||||
void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
||||||
{
|
{
|
||||||
if (semanticInfo.revision != editorRevision()) {
|
if (semanticInfo.revision != editorRevision()) {
|
||||||
@@ -1881,83 +1939,19 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_lastSemanticInfo.forced || previousSemanticInfo.revision != semanticInfo.revision) {
|
if (m_lastSemanticInfo.forced || previousSemanticInfo.revision != semanticInfo.revision) {
|
||||||
QList<QTextEdit::ExtraSelection> undefinedSymbolSelections;
|
QTextCharFormat diagnosticMessageFormat;
|
||||||
foreach (const Document::DiagnosticMessage &m, semanticInfo.diagnosticMessages) {
|
diagnosticMessageFormat.setUnderlineColor(Qt::darkYellow); // ### hardcoded
|
||||||
QTextCursor cursor(document());
|
diagnosticMessageFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); // ### hardcoded
|
||||||
cursor.setPosition(document()->findBlockByNumber(m.line() - 1).position() + m.column() - 1);
|
setExtraSelections(UndefinedSymbolSelection, createSelections(document(),
|
||||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length());
|
semanticInfo.diagnosticMessages,
|
||||||
|
diagnosticMessageFormat));
|
||||||
|
|
||||||
QTextEdit::ExtraSelection sel;
|
setExtraSelections(TypeSelection, createSelections(document(),
|
||||||
sel.cursor = cursor;
|
semanticInfo.typeUsages,
|
||||||
sel.format.setUnderlineColor(Qt::darkYellow); // ### hardcoded
|
m_typeFormat));
|
||||||
sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline); // ### hardcoded
|
setExtraSelections(ObjCSelection, createSelections(document(),
|
||||||
sel.format.setToolTip(m.text());
|
semanticInfo.objcKeywords,
|
||||||
undefinedSymbolSelections.append(sel);
|
m_keywordFormat));
|
||||||
}
|
|
||||||
|
|
||||||
setExtraSelections(UndefinedSymbolSelection, undefinedSymbolSelections);
|
|
||||||
|
|
||||||
QTextBlock currentBlock = document()->firstBlock();
|
|
||||||
unsigned currentLine = 1;
|
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> typeSelections;
|
|
||||||
|
|
||||||
foreach (const SemanticInfo::Use &use, semanticInfo.typeUsages) {
|
|
||||||
QTextCursor cursor(document());
|
|
||||||
|
|
||||||
if (currentLine != use.line) {
|
|
||||||
int delta = use.line - currentLine;
|
|
||||||
|
|
||||||
if (delta >= 0) {
|
|
||||||
while (delta--)
|
|
||||||
currentBlock = currentBlock.next();
|
|
||||||
} else {
|
|
||||||
currentBlock = document()->findBlockByNumber(use.line - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLine = use.line;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.setPosition(currentBlock.position() + use.column - 1);
|
|
||||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, use.length);
|
|
||||||
|
|
||||||
QTextEdit::ExtraSelection sel;
|
|
||||||
sel.cursor = cursor;
|
|
||||||
sel.format = m_typeFormat;
|
|
||||||
typeSelections.append(sel);
|
|
||||||
}
|
|
||||||
|
|
||||||
setExtraSelections(TypeSelection, typeSelections);
|
|
||||||
|
|
||||||
// ### extract common parts from the previous loop and the next one
|
|
||||||
QList<QTextEdit::ExtraSelection> objcKeywords;
|
|
||||||
if (isObjCEnabled()) {
|
|
||||||
foreach (const SemanticInfo::Use &use, semanticInfo.objcKeywords) {
|
|
||||||
QTextCursor cursor(document());
|
|
||||||
|
|
||||||
if (currentLine != use.line) {
|
|
||||||
int delta = use.line - currentLine;
|
|
||||||
|
|
||||||
if (delta >= 0) {
|
|
||||||
while (delta--)
|
|
||||||
currentBlock = currentBlock.next();
|
|
||||||
} else {
|
|
||||||
currentBlock = document()->findBlockByNumber(use.line - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLine = use.line;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.setPosition(currentBlock.position() + use.column - 1);
|
|
||||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, use.length);
|
|
||||||
|
|
||||||
QTextEdit::ExtraSelection sel;
|
|
||||||
sel.cursor = cursor;
|
|
||||||
sel.format = m_keywordFormat;
|
|
||||||
objcKeywords.append(sel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setExtraSelections(ObjCSelection, objcKeywords);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setExtraSelections(UnusedSymbolSelection, unusedSelections);
|
setExtraSelections(UnusedSymbolSelection, unusedSelections);
|
||||||
|
|||||||
Reference in New Issue
Block a user