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>
This commit is contained in:
Marco Benelli
2018-05-22 17:07:27 +02:00
parent 4d082b9500
commit d14e89f899
3 changed files with 31 additions and 2 deletions

View File

@@ -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;
}