From 922c607b4f76bd1c8ec06c98eea0f97aeb3cac58 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Fri, 29 Jan 2010 11:53:41 +0100
Subject: [PATCH] Highlight QML context types.

---
 src/libs/qmljs/qmljshighlighter.cpp | 51 ++++++++++++++++++++++++++++-
 src/libs/qmljs/qmljshighlighter.h   |  1 +
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/libs/qmljs/qmljshighlighter.cpp b/src/libs/qmljs/qmljshighlighter.cpp
index cf92815965b..ff5f665e238 100644
--- a/src/libs/qmljs/qmljshighlighter.cpp
+++ b/src/libs/qmljs/qmljshighlighter.cpp
@@ -90,6 +90,14 @@ void QScriptHighlighter::highlightBlock(const QString &text)
                 setFormat(token.offset, token.length, m_formats[KeywordFormat]);
                 break;
 
+            case Token::String:
+                setFormat(token.offset, token.length, m_formats[StringFormat]);
+                break;
+
+            case Token::Comment:
+                setFormat(token.offset, token.length, m_formats[CommentFormat]);
+                break;
+
             case Token::LeftParenthesis:
                 onOpeningParenthesis('(', token.offset);
                 break;
@@ -115,7 +123,9 @@ void QScriptHighlighter::highlightBlock(const QString &text)
                 break;
 
             case Token::Identifier: {
-                if (m_duiEnabled && maybeQmlKeyword(text.midRef(token.offset, token.length))) {
+                const QStringRef spell = text.midRef(token.offset, token.length);
+
+                if (m_duiEnabled && maybeQmlKeyword(spell)) {
                     // check the previous token
                     if (index == 0 || tokens.at(index - 1).isNot(Token::Dot)) {
                         if (index + 1 == tokens.size() || tokens.at(index + 1).isNot(Token::Colon)) {
@@ -123,6 +133,13 @@ void QScriptHighlighter::highlightBlock(const QString &text)
                             break;
                         }
                     }
+                } else if (m_duiEnabled && index > 0 && maybeQmlBuiltinType(spell)) {
+                    const Token &previousToken = tokens.at(index - 1);
+                    if (previousToken.is(Token::Identifier) && text.at(previousToken.offset) == QLatin1Char('p')
+                        && text.midRef(previousToken.offset, previousToken.length) == QLatin1String("property")) {
+                        setFormat(token.offset, token.length, m_formats[KeywordFormat]);
+                        break;
+                    }
                 }
 
                 if (index + 1 < tokens.size()) {
@@ -247,3 +264,35 @@ bool QScriptHighlighter::maybeQmlKeyword(const QStringRef &text) const
         return false;
     }
 }
+
+bool QScriptHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
+{
+    if (text.isEmpty())
+        return false;
+
+    const QChar ch = text.at(0);
+
+    if (ch == QLatin1Char('i') && text == QLatin1String("int")) {
+        return true;
+    } else if (ch == QLatin1Char('b') && text == QLatin1String("bool")) {
+        return true;
+    } else if (ch == QLatin1Char('d') && text == QLatin1String("double")) {
+        return true;
+    } else if (ch == QLatin1Char('r') && text == QLatin1String("real")) {
+        return true;
+    } else if (ch == QLatin1Char('s') && text == QLatin1String("string")) {
+        return true;
+    } else if (ch == QLatin1Char('u') && text == QLatin1String("url")) {
+        return true;
+    } else if (ch == QLatin1Char('c') && text == QLatin1String("color")) {
+        return true;
+    } else if (ch == QLatin1Char('d') && text == QLatin1String("date")) {
+        return true;
+    } else if (ch == QLatin1Char('v') && text == QLatin1String("var")) {
+        return true;
+    } else if (ch == QLatin1Char('v') && text == QLatin1String("variant")) {
+        return true;
+    } else {
+        return false;
+    }
+}
diff --git a/src/libs/qmljs/qmljshighlighter.h b/src/libs/qmljs/qmljshighlighter.h
index e2e3e65ee1c..d5bf0347e24 100644
--- a/src/libs/qmljs/qmljshighlighter.h
+++ b/src/libs/qmljs/qmljshighlighter.h
@@ -67,6 +67,7 @@ protected:
     virtual void onClosingParenthesis(QChar parenthesis, int pos);
 
     bool maybeQmlKeyword(const QStringRef &text) const;
+    bool maybeQmlBuiltinType(const QStringRef &text) const;
 
 protected:
     QmlJSScanner m_scanner;
-- 
GitLab