Add flag for semantic highlighter to set diagnostics.

If the semantic highlighter does not take care of setting showing the wiggly
lines for diagnostics in the editor, the model manager will do.

Change-Id: Ie69fb798dd53d60ddca1668b8f586266a0daca4b
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Erik Verbruggen
2012-03-15 10:52:55 +01:00
parent 8af873de94
commit 51de4ed21a
4 changed files with 50 additions and 39 deletions

View File

@@ -72,6 +72,8 @@ public:
virtual ~CppHighlightingSupportFactory() = 0; virtual ~CppHighlightingSupportFactory() = 0;
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0; virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0;
virtual bool hightlighterHandlesDiagnostics() const = 0;
}; };
} // namespace CppTools } // namespace CppTools

View File

@@ -62,6 +62,9 @@ public:
virtual ~CppHighlightingSupportInternalFactory(); virtual ~CppHighlightingSupportInternalFactory();
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor); virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor);
virtual bool hightlighterHandlesDiagnostics() const
{ return false; }
}; };
} // namespace Internal } // namespace Internal

View File

@@ -1099,8 +1099,6 @@ void CppModelManager::updateEditor(Document::Ptr doc)
blockRanges.append(TextEditor::BaseTextEditorWidget::BlockRange(block.begin(), block.end())); blockRanges.append(TextEditor::BaseTextEditorWidget::BlockRange(block.begin(), block.end()));
} }
QList<QTextEdit::ExtraSelection> selections;
// set up the format for the errors // set up the format for the errors
QTextCharFormat errorFormat; QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
@@ -1111,6 +1109,16 @@ void CppModelManager::updateEditor(Document::Ptr doc)
warningFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); warningFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
warningFormat.setUnderlineColor(Qt::darkYellow); warningFormat.setUnderlineColor(Qt::darkYellow);
QList<Editor> todo;
foreach (const Editor &e, m_todo) {
if (e.textEditor != textEditor)
todo.append(e);
}
Editor e;
if (m_highlightingFactory->hightlighterHandlesDiagnostics()) {
e.updateSelections = false;
} else {
QSet<int> lines; QSet<int> lines;
QList<Document::DiagnosticMessage> messages = doc->diagnosticMessages(); QList<Document::DiagnosticMessage> messages = doc->diagnosticMessages();
messages += extraDiagnostics(doc->fileName()); messages += extraDiagnostics(doc->fileName());
@@ -1139,19 +1147,13 @@ void CppModelManager::updateEditor(Document::Ptr doc)
c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
sel.cursor = c; sel.cursor = c;
sel.format.setToolTip(m.text()); sel.format.setToolTip(m.text());
selections.append(sel); e.selections.append(sel);
}
} }
QList<Editor> todo;
foreach (const Editor &e, todo) {
if (e.textEditor != textEditor)
todo.append(e);
}
Editor e;
e.revision = ed->document()->revision(); e.revision = ed->document()->revision();
e.textEditor = textEditor; e.textEditor = textEditor;
e.selections = selections;
e.ifdefedOutBlocks = blockRanges; e.ifdefedOutBlocks = blockRanges;
todo.append(e); todo.append(e);
m_todo = todo; m_todo = todo;
@@ -1180,6 +1182,7 @@ void CppModelManager::updateEditorSelections()
else if (editor->document()->revision() != ed.revision) else if (editor->document()->revision() != ed.revision)
continue; // outdated continue; // outdated
if (ed.updateSelections)
editor->setExtraSelections(TextEditor::BaseTextEditorWidget::CodeWarningsSelection, editor->setExtraSelections(TextEditor::BaseTextEditorWidget::CodeWarningsSelection,
ed.selections); ed.selections);

View File

@@ -225,8 +225,11 @@ private:
struct Editor { struct Editor {
Editor() Editor()
: revision(-1) {} : revision(-1)
, updateSelections(true)
{}
int revision; int revision;
bool updateSelections;
QPointer<TextEditor::ITextEditor> textEditor; QPointer<TextEditor::ITextEditor> textEditor;
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
QList<TextEditor::BaseTextEditorWidget::BlockRange> ifdefedOutBlocks; QList<TextEditor::BaseTextEditorWidget::BlockRange> ifdefedOutBlocks;