forked from qt-creator/qt-creator
QmlJSEditor: Add completion for JS keywords and Qml reserved words.
Task-number: QTCREATORBUG-919 Reviewed-by: Roberto Raggi
This commit is contained in:
@@ -309,3 +309,13 @@ bool Scanner::isKeyword(const QString &text) const
|
|||||||
|
|
||||||
return false;
|
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;
|
int state() const;
|
||||||
|
|
||||||
bool isKeyword(const QString &text) const;
|
bool isKeyword(const QString &text) const;
|
||||||
|
static QStringList keywords();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _state;
|
int _state;
|
||||||
|
|||||||
@@ -692,6 +692,25 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
item.icon = symbolIcon;
|
item.icon = symbolIcon;
|
||||||
m_completions.append(item);
|
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('(')) {
|
else if (completionOperator == QLatin1Char('.') || completionOperator == QLatin1Char('(')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user