Commit b2bb919e authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJSEditor: Add completion for JS keywords and Qml reserved words.

Task-number: QTCREATORBUG-919
Reviewed-by: Roberto Raggi
parent c21747a2
......@@ -309,3 +309,13 @@ bool Scanner::isKeyword(const QString &text) const
return false;
}
QStringList Scanner::keywords()
{
static QStringList words;
if (words.isEmpty()) {
for (const QString *word = begin(js_keywords); word != end(js_keywords); ++word)
words.append(*word);
}
return words;
}
......@@ -87,6 +87,7 @@ public:
int state() const;
bool isKeyword(const QString &text) const;
static QStringList keywords();
private:
int _state;
......
......@@ -692,6 +692,25 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
item.icon = symbolIcon;
m_completions.append(item);
}
// add js keywords
foreach (const QString &word, Scanner::keywords()) {
TextEditor::CompletionItem item(this);
item.text = word;
m_completions.append(item);
}
// add qml extra words
if (document->qmlProgram()) {
static QStringList qmlWords;
if (qmlWords.isEmpty())
qmlWords << "property" << "readonly" << "signal";
foreach (const QString &word, qmlWords) {
TextEditor::CompletionItem item(this);
item.text = word;
m_completions.append(item);
}
}
}
else if (completionOperator == QLatin1Char('.') || completionOperator == QLatin1Char('(')) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment