forked from qt-creator/qt-creator
QmlJS: improve static initializings
Change-Id: Ifa37c912d0e43bcda896cb0ea851f97566c88d78 Reviewed-by: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
@@ -30,33 +30,33 @@
|
|||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
QString js_keywords[] = {
|
static const QString js_keywords[] = {
|
||||||
QLatin1String("break"),
|
QLatin1String("break"),
|
||||||
QString::fromLatin1("case"),
|
QLatin1String("case"),
|
||||||
QString::fromLatin1("catch"),
|
QLatin1String("catch"),
|
||||||
QString::fromLatin1("continue"),
|
QLatin1String("continue"),
|
||||||
QString::fromLatin1("debugger"),
|
QLatin1String("debugger"),
|
||||||
QString::fromLatin1("default"),
|
QLatin1String("default"),
|
||||||
QString::fromLatin1("delete"),
|
QLatin1String("delete"),
|
||||||
QString::fromLatin1("do"),
|
QLatin1String("do"),
|
||||||
QString::fromLatin1("else"),
|
QLatin1String("else"),
|
||||||
QString::fromLatin1("finally"),
|
QLatin1String("finally"),
|
||||||
QString::fromLatin1("for"),
|
QLatin1String("for"),
|
||||||
QString::fromLatin1("function"),
|
QLatin1String("function"),
|
||||||
QString::fromLatin1("if"),
|
QLatin1String("if"),
|
||||||
QString::fromLatin1("in"),
|
QLatin1String("in"),
|
||||||
QString::fromLatin1("instanceof"),
|
QLatin1String("instanceof"),
|
||||||
QString::fromLatin1("new"),
|
QLatin1String("new"),
|
||||||
QString::fromLatin1("return"),
|
QLatin1String("return"),
|
||||||
QString::fromLatin1("switch"),
|
QLatin1String("switch"),
|
||||||
QString::fromLatin1("this"),
|
QLatin1String("this"),
|
||||||
QString::fromLatin1("throw"),
|
QLatin1String("throw"),
|
||||||
QString::fromLatin1("try"),
|
QLatin1String("try"),
|
||||||
QString::fromLatin1("typeof"),
|
QLatin1String("typeof"),
|
||||||
QString::fromLatin1("var"),
|
QLatin1String("var"),
|
||||||
QString::fromLatin1("void"),
|
QLatin1String("void"),
|
||||||
QString::fromLatin1("while"),
|
QLatin1String("while"),
|
||||||
QString::fromLatin1("with")
|
QLatin1String("with")
|
||||||
};
|
};
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
@@ -417,10 +417,10 @@ bool Scanner::isKeyword(const QString &text) const
|
|||||||
|
|
||||||
QStringList Scanner::keywords()
|
QStringList Scanner::keywords()
|
||||||
{
|
{
|
||||||
static QStringList words;
|
static QStringList words = [&]() {
|
||||||
if (words.isEmpty()) {
|
|
||||||
for (const QString *word = begin(js_keywords); word != end(js_keywords); ++word)
|
for (const QString *word = begin(js_keywords); word != end(js_keywords); ++word)
|
||||||
words.append(*word);
|
words.append(*word);
|
||||||
}
|
return words;
|
||||||
|
}();
|
||||||
return words;
|
return words;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -853,17 +853,15 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface *
|
|||||||
|
|
||||||
// add qml extra words
|
// add qml extra words
|
||||||
if (doQmlKeywordCompletion && isQmlFile) {
|
if (doQmlKeywordCompletion && isQmlFile) {
|
||||||
static QStringList qmlWords;
|
static QStringList qmlWords{
|
||||||
static QStringList qmlWordsAlsoInJs;
|
QLatin1String("property"),
|
||||||
|
//QLatin1String("readonly")
|
||||||
if (qmlWords.isEmpty()) {
|
QLatin1String("signal"),
|
||||||
qmlWords << QLatin1String("property")
|
QLatin1String("import")
|
||||||
//<< QLatin1String("readonly")
|
};
|
||||||
<< QLatin1String("signal")
|
static QStringList qmlWordsAlsoInJs{
|
||||||
<< QLatin1String("import");
|
QLatin1String("default"), QLatin1String("function")
|
||||||
}
|
};
|
||||||
if (qmlWordsAlsoInJs.isEmpty())
|
|
||||||
qmlWordsAlsoInJs << QLatin1String("default") << QLatin1String("function");
|
|
||||||
|
|
||||||
addCompletions(&m_completions, qmlWords, m_interface->keywordIcon(), KeywordOrder);
|
addCompletions(&m_completions, qmlWords, m_interface->keywordIcon(), KeywordOrder);
|
||||||
if (!doJsKeywordCompletion)
|
if (!doJsKeywordCompletion)
|
||||||
|
|||||||
@@ -42,16 +42,10 @@ QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent)
|
|||||||
m_inMultilineComment(false)
|
m_inMultilineComment(false)
|
||||||
{
|
{
|
||||||
m_currentBlockParentheses.reserve(20);
|
m_currentBlockParentheses.reserve(20);
|
||||||
static QVector<TextStyle> categories;
|
static const QVector<TextStyle> categories{
|
||||||
if (categories.isEmpty()) {
|
C_NUMBER, C_STRING, C_TYPE,
|
||||||
categories << C_NUMBER
|
C_KEYWORD, C_FIELD, C_COMMENT,
|
||||||
<< C_STRING
|
C_VISUAL_WHITESPACE};
|
||||||
<< C_TYPE
|
|
||||||
<< C_KEYWORD
|
|
||||||
<< C_FIELD
|
|
||||||
<< C_COMMENT
|
|
||||||
<< C_VISUAL_WHITESPACE;
|
|
||||||
}
|
|
||||||
setTextFormatCategories(categories);
|
setTextFormatCategories(categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user