From c3578f307db440ffb8c9fc115757c0dcd4ef2c92 Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Tue, 23 Feb 2010 16:11:58 +0100 Subject: [PATCH] Fix parsing errors not showing for the QmlJS editor. Done-with: Erik Verbruggen --- src/plugins/qmljseditor/qmljseditor.cpp | 76 +++++++++++++------------ 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 4f6b32ca103..eb1b955dc2d 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -672,6 +672,42 @@ void QmlJSTextEditor::updateDocumentNow() m_modelManager->updateSourceFiles(QStringList() << fileName); } +static void appendExtraSelectionsForMessages( + QList<QTextEdit::ExtraSelection> *selections, + const QList<DiagnosticMessage> &messages, + const QTextDocument *document) +{ + foreach (const DiagnosticMessage &d, messages) { + const int line = d.loc.startLine; + const int column = qMax(1U, d.loc.startColumn); + + QTextEdit::ExtraSelection sel; + QTextCursor c(document->findBlockByNumber(line - 1)); + sel.cursor = c; + + sel.cursor.setPosition(c.position() + column - 1); + + if (d.loc.length == 0) { + if (sel.cursor.atBlockEnd()) + sel.cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); + else + sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + } else { + sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length); + } + + if (d.isWarning()) + sel.format.setUnderlineColor(Qt::darkYellow); + else + sel.format.setUnderlineColor(Qt::red); + + sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline); + sel.format.setToolTip(d.message); + + selections->append(sel); + } +} + void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc) { if (file()->fileName() != doc->fileName()) { @@ -688,6 +724,10 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc) const SemanticHighlighter::Source source = currentSource(/*force = */ true); m_semanticHighlighter->rehighlight(source); + } else { + QList<QTextEdit::ExtraSelection> selections; + appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document()); + setExtraSelections(CodeWarningsSelection, selections); } } @@ -1123,42 +1163,6 @@ QString QmlJSTextEditor::insertParagraphSeparator(const QTextCursor &) const return QLatin1String("}\n"); } -static void appendExtraSelectionsForMessages( - QList<QTextEdit::ExtraSelection> *selections, - const QList<DiagnosticMessage> &messages, - const QTextDocument *document) -{ - foreach (const DiagnosticMessage &d, messages) { - const int line = d.loc.startLine; - const int column = qMax(1U, d.loc.startColumn); - - QTextEdit::ExtraSelection sel; - QTextCursor c(document->findBlockByNumber(line - 1)); - sel.cursor = c; - - sel.cursor.setPosition(c.position() + column - 1); - - if (d.loc.length == 0) { - if (sel.cursor.atBlockEnd()) - sel.cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); - else - sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); - } else { - sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length); - } - - if (d.isWarning()) - sel.format.setUnderlineColor(Qt::darkYellow); - else - sel.format.setUnderlineColor(Qt::red); - - sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline); - sel.format.setToolTip(d.message); - - selections->append(sel); - } -} - void QmlJSTextEditor::semanticRehighlight() { m_semanticHighlighter->rehighlight(currentSource()); -- GitLab