From e622d70617b3d850d6995b2c5aff19832040313b Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Tue, 26 Jan 2010 14:03:37 +0100
Subject: [PATCH] There's no need to store the diagnostic messages in the
 editor.

Store the error message in the QTextCharFormat of the extra selection.
---
 src/plugins/qmljseditor/qmlhoverhandler.cpp |  8 +++-----
 src/plugins/qmljseditor/qmljseditor.cpp     | 20 +++++++++-----------
 src/plugins/qmljseditor/qmljseditor.h       |  4 ----
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/plugins/qmljseditor/qmlhoverhandler.cpp b/src/plugins/qmljseditor/qmlhoverhandler.cpp
index e26f9705845..f3d3c361258 100644
--- a/src/plugins/qmljseditor/qmlhoverhandler.cpp
+++ b/src/plugins/qmljseditor/qmlhoverhandler.cpp
@@ -158,16 +158,14 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
 
     QTextCursor tc(scriptEditor->document());
     tc.setPosition(pos);
-    const unsigned lineNumber = tc.block().blockNumber() + 1;
 
     // We only want to show F1 if the tooltip matches the help id
     bool showF1 = true;
 
-    foreach (const QmlJS::DiagnosticMessage &m, scriptEditor->diagnosticMessages()) {
-        if (m.loc.startLine == lineNumber) {
-            m_toolTip = m.message;
+    foreach (const QTextEdit::ExtraSelection &sel, scriptEditor->extraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection)) {
+        if (pos >= sel.cursor.selectionStart() && pos <= sel.cursor.selectionEnd()) {
             showF1 = false;
-            break;
+            m_toolTip = sel.format.toolTip();
         }
     }
 
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 969cff21e43..4c232ee5a8e 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -563,20 +563,16 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
 
     QList<QTextEdit::ExtraSelection> selections;
 
-    QTextCharFormat errorFormat;
-    errorFormat.setUnderlineColor(Qt::red);
-    errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
-
     QTextEdit::ExtraSelection sel;
 
-    m_diagnosticMessages = doc->diagnosticMessages();
+    const QList<DiagnosticMessage> diagnosticMessages = doc->diagnosticMessages();
 
-    foreach (const DiagnosticMessage &d, m_diagnosticMessages) {
-        int line = d.loc.startLine;
-        int column = d.loc.startColumn;
+    foreach (const DiagnosticMessage &d, diagnosticMessages) {
+        if (d.isWarning())
+            continue;
 
-        if (column == 0)
-            column = 1;
+        const int line = d.loc.startLine;
+        const int column = qMax(1U, d.loc.startColumn);
 
         QTextCursor c(document()->findBlockByNumber(line - 1));
         sel.cursor = c;
@@ -587,7 +583,9 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
         else
             sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
 
-        sel.format = errorFormat;
+        sel.format.setUnderlineColor(Qt::red);
+        sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
+        sel.format.setToolTip(d.message);
 
         selections.append(sel);
     }
diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h
index d6970c969a5..42ed0f91db5 100644
--- a/src/plugins/qmljseditor/qmljseditor.h
+++ b/src/plugins/qmljseditor/qmljseditor.h
@@ -125,9 +125,6 @@ public:
     QList<Declaration> declarations() const;
     QStringList keywords() const;
 
-    QList<QmlJS::DiagnosticMessage> diagnosticMessages() const
-    { return m_diagnosticMessages; }
-
     virtual void unCommentSelection();
 
     SemanticInfo semanticInfo() const { return m_semanticInfo; }
@@ -178,7 +175,6 @@ private:
     QList<Declaration> m_declarations; // ### remove me
     QMap<QString, QList<QmlJS::AST::SourceLocation> > m_ids; // ### remove me
     int m_idsRevision; // ### remove me
-    QList<QmlJS::DiagnosticMessage> m_diagnosticMessages; // ### remove me
     QmlModelManagerInterface *m_modelManager;
     QmlJS::TypeSystem *m_typeSystem;
     QTextCharFormat m_occurrencesFormat;
-- 
GitLab