summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Benelli <marco.benelli@qt.io>2018-05-22 17:07:27 +0200
committerMarco Benelli <marco.benelli@qt.io>2018-05-23 08:04:26 +0000
commitd14e89f899f188eed66a46b3623d6c299d533af5 (patch)
tree49f28e6890410d1f8b5a056b71c71a0f9228559a
parent4d082b9500db8da4540c3d00649b051c1dc127f6 (diff)
downloadqt-creator-d14e89f899f188eed66a46b3623d6c299d533af5.tar.gz
QmlJS: improve support for enum declarations
Add indentation and little highlighting for enums. It just highlights the 'enum' keyword and the name of the enum, not its values. Task-number: QTCREATORBUG-19226 Change-Id: I36e46a27b0e32c4aecc8e91875c3d22df1814d93 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp8
-rw-r--r--src/libs/qmljs/qmljscodeformatter.h4
-rw-r--r--src/plugins/qmljseditor/qmljshighlighter.cpp21
3 files changed, 31 insertions, 2 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index 8c34cdc4ac..41b910703f 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -177,6 +177,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case Property: enter(property_start); break;
case Function: enter(function_start); break;
case Signal: enter(signal_start); break;
+ case Enum: enter(enum_start); break;
case On:
case As:
case List:
@@ -215,6 +216,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
default: leave(true); continue;
} break;
+ case enum_start:
+ switch (kind) {
+ case LeftBrace: enter(objectliteral_open); break;
+ } break;
+
case signal_start:
switch (kind) {
case Colon: enter(binding_assignment); break; // oops, was a binding
@@ -931,6 +937,8 @@ CodeFormatter::TokenKind CodeFormatter::extendedTokenKind(const QmlJS::Token &to
return On;
if (text == QLatin1String("list"))
return List;
+ if (text == QLatin1String("enum"))
+ return Enum;
} else if (kind == Keyword) {
const char char1 = text.at(0).toLatin1();
const char char2 = text.at(1).toLatin1();
diff --git a/src/libs/qmljs/qmljscodeformatter.h b/src/libs/qmljs/qmljscodeformatter.h
index 990ec080ce..55fe2d2d86 100644
--- a/src/libs/qmljs/qmljscodeformatter.h
+++ b/src/libs/qmljs/qmljscodeformatter.h
@@ -109,6 +109,8 @@ public: // must be public to make Q_GADGET introspection work
property_name, // after the type
property_maybe_initializer, // after the identifier
+ enum_start, // after 'enum'
+
signal_start, // after 'signal'
signal_maybe_arglist, // after identifier
signal_arglist_open, // after '('
@@ -197,6 +199,7 @@ protected:
Comma,
Dot,
Delimiter,
+ RegExp,
EndOfExistingTokenKinds,
@@ -209,6 +212,7 @@ protected:
Delete,
Do,
Else,
+ Enum,
Finally,
For,
Function,
diff --git a/src/plugins/qmljseditor/qmljshighlighter.cpp b/src/plugins/qmljseditor/qmljshighlighter.cpp
index 06d65a3971..5777c6c3e2 100644
--- a/src/plugins/qmljseditor/qmljshighlighter.cpp
+++ b/src/plugins/qmljseditor/qmljshighlighter.cpp
@@ -131,13 +131,28 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
break;
}
}
+ if (text.midRef(token.offset, token.length) == QLatin1String("enum")) {
+ setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
+ break;
+ }
} else if (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")) {
+ if (previousToken.is(Token::Identifier)
+ && text.at(previousToken.offset) == QLatin1Char('p')
+ && text.midRef(previousToken.offset, previousToken.length)
+ == QLatin1String("property")) {
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
break;
}
+ } else if (index == 1) {
+ const Token &previousToken = tokens.at(0);
+ if (previousToken.is(Token::Identifier)
+ && text.at(previousToken.offset) == QLatin1Char('e')
+ && text.midRef(previousToken.offset, previousToken.length)
+ == QLatin1String("enum")) {
+ setFormat(token.offset, token.length, formatForCategory(C_ENUMERATION));
+ break;
+ }
}
} break;
@@ -206,6 +221,8 @@ bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
return true;
else if (ch == QLatin1Char('o') && text == QLatin1String("on"))
return true;
+ else if (ch == QLatin1Char('e') && text == QLatin1String("enum"))
+ return true;
else
return false;
}