From 51de4ed21a74cfc1814d7e925ed8b33f942ccfef Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 15 Mar 2012 10:52:55 +0100 Subject: [PATCH] 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 --- src/plugins/cpptools/cpphighlightingsupport.h | 2 + .../cpptools/cpphighlightingsupportinternal.h | 3 + src/plugins/cpptools/cppmodelmanager.cpp | 79 ++++++++++--------- src/plugins/cpptools/cppmodelmanager.h | 5 +- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/plugins/cpptools/cpphighlightingsupport.h b/src/plugins/cpptools/cpphighlightingsupport.h index 6b805420373..4319ff9c4e4 100644 --- a/src/plugins/cpptools/cpphighlightingsupport.h +++ b/src/plugins/cpptools/cpphighlightingsupport.h @@ -72,6 +72,8 @@ public: virtual ~CppHighlightingSupportFactory() = 0; virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0; + + virtual bool hightlighterHandlesDiagnostics() const = 0; }; } // namespace CppTools diff --git a/src/plugins/cpptools/cpphighlightingsupportinternal.h b/src/plugins/cpptools/cpphighlightingsupportinternal.h index 52ab1f81184..16c81e983a9 100644 --- a/src/plugins/cpptools/cpphighlightingsupportinternal.h +++ b/src/plugins/cpptools/cpphighlightingsupportinternal.h @@ -62,6 +62,9 @@ public: virtual ~CppHighlightingSupportInternalFactory(); virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor); + + virtual bool hightlighterHandlesDiagnostics() const + { return false; } }; } // namespace Internal diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index bd2998d5884..773e43688ee 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -1099,8 +1099,6 @@ void CppModelManager::updateEditor(Document::Ptr doc) blockRanges.append(TextEditor::BaseTextEditorWidget::BlockRange(block.begin(), block.end())); } - QList selections; - // set up the format for the errors QTextCharFormat errorFormat; errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); @@ -1111,47 +1109,51 @@ void CppModelManager::updateEditor(Document::Ptr doc) warningFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); warningFormat.setUnderlineColor(Qt::darkYellow); - QSet lines; - QList messages = doc->diagnosticMessages(); - messages += extraDiagnostics(doc->fileName()); - foreach (const Document::DiagnosticMessage &m, messages) { - if (m.fileName() != fileName) - continue; - else if (lines.contains(m.line())) - continue; - - lines.insert(m.line()); - - QTextEdit::ExtraSelection sel; - if (m.isWarning()) - sel.format = warningFormat; - else - sel.format = errorFormat; - - QTextCursor c(ed->document()->findBlockByNumber(m.line() - 1)); - const QString text = c.block().text(); - for (int i = 0; i < text.size(); ++i) { - if (! text.at(i).isSpace()) { - c.setPosition(c.position() + i); - break; - } - } - c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); - sel.cursor = c; - sel.format.setToolTip(m.text()); - selections.append(sel); - } - QList todo; - foreach (const Editor &e, 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 lines; + QList messages = doc->diagnosticMessages(); + messages += extraDiagnostics(doc->fileName()); + foreach (const Document::DiagnosticMessage &m, messages) { + if (m.fileName() != fileName) + continue; + else if (lines.contains(m.line())) + continue; + + lines.insert(m.line()); + + QTextEdit::ExtraSelection sel; + if (m.isWarning()) + sel.format = warningFormat; + else + sel.format = errorFormat; + + QTextCursor c(ed->document()->findBlockByNumber(m.line() - 1)); + const QString text = c.block().text(); + for (int i = 0; i < text.size(); ++i) { + if (! text.at(i).isSpace()) { + c.setPosition(c.position() + i); + break; + } + } + c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + sel.cursor = c; + sel.format.setToolTip(m.text()); + e.selections.append(sel); + } + } + + e.revision = ed->document()->revision(); e.textEditor = textEditor; - e.selections = selections; e.ifdefedOutBlocks = blockRanges; todo.append(e); m_todo = todo; @@ -1180,8 +1182,9 @@ void CppModelManager::updateEditorSelections() else if (editor->document()->revision() != ed.revision) continue; // outdated - editor->setExtraSelections(TextEditor::BaseTextEditorWidget::CodeWarningsSelection, - ed.selections); + if (ed.updateSelections) + editor->setExtraSelections(TextEditor::BaseTextEditorWidget::CodeWarningsSelection, + ed.selections); editor->setIfdefedOutBlocks(ed.ifdefedOutBlocks); } diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 75cb35ca5b5..d1380556b9f 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -225,8 +225,11 @@ private: struct Editor { Editor() - : revision(-1) {} + : revision(-1) + , updateSelections(true) + {} int revision; + bool updateSelections; QPointer textEditor; QList selections; QList ifdefedOutBlocks;