forked from qt-creator/qt-creator
QmlJS: Complete '{' instad of ':' at the end of 'A on b' bindings.
Task-number: QTCREATORBUG-2642 Reviewed-by: Erik Verbruggen
This commit is contained in:
@@ -132,7 +132,6 @@ void CompletionContextFinder::checkBinding()
|
|||||||
int i = m_startTokenIndex;
|
int i = m_startTokenIndex;
|
||||||
int colonCount = 0;
|
int colonCount = 0;
|
||||||
bool delimiterFound = false;
|
bool delimiterFound = false;
|
||||||
bool firstToken = true;
|
|
||||||
bool identifierExpected = false;
|
bool identifierExpected = false;
|
||||||
bool dotExpected = false;
|
bool dotExpected = false;
|
||||||
while (!delimiterFound) {
|
while (!delimiterFound) {
|
||||||
@@ -158,19 +157,19 @@ void CompletionContextFinder::checkBinding()
|
|||||||
++colonCount;
|
++colonCount;
|
||||||
identifierExpected = true;
|
identifierExpected = true;
|
||||||
dotExpected = false;
|
dotExpected = false;
|
||||||
|
m_behaviorBinding = false;
|
||||||
m_bindingPropertyName.clear();
|
m_bindingPropertyName.clear();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Token::Identifier: {
|
case Token::Identifier: {
|
||||||
QStringRef tokenString = yyLine->midRef(token.begin(), token.length);
|
QStringRef tokenString = yyLine->midRef(token.begin(), token.length);
|
||||||
if (firstToken && tokenString == QLatin1String("on")) {
|
dotExpected = false;
|
||||||
m_behaviorBinding = true;
|
if (identifierExpected) {
|
||||||
} else if (identifierExpected) {
|
|
||||||
m_bindingPropertyName.prepend(tokenString.toString());
|
m_bindingPropertyName.prepend(tokenString.toString());
|
||||||
identifierExpected = false;
|
identifierExpected = false;
|
||||||
dotExpected = true;
|
dotExpected = true;
|
||||||
} else {
|
} else if (tokenString == QLatin1String("on")) {
|
||||||
dotExpected = false;
|
m_behaviorBinding = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -190,7 +189,6 @@ void CompletionContextFinder::checkBinding()
|
|||||||
}
|
}
|
||||||
|
|
||||||
--i;
|
--i;
|
||||||
firstToken = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YY_RESTORE();
|
YY_RESTORE();
|
||||||
|
|||||||
@@ -678,7 +678,7 @@ void CodeCompletion::addCompletions(const QStringList &newCompletions,
|
|||||||
|
|
||||||
void CodeCompletion::addCompletionsPropertyLhs(
|
void CodeCompletion::addCompletionsPropertyLhs(
|
||||||
const QHash<QString, const Interpreter::Value *> &newCompletions,
|
const QHash<QString, const Interpreter::Value *> &newCompletions,
|
||||||
const QIcon &icon, int order)
|
const QIcon &icon, int order, bool afterOn)
|
||||||
{
|
{
|
||||||
QHashIterator<QString, const Interpreter::Value *> it(newCompletions);
|
QHashIterator<QString, const Interpreter::Value *> it(newCompletions);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -686,15 +686,19 @@ void CodeCompletion::addCompletionsPropertyLhs(
|
|||||||
|
|
||||||
TextEditor::CompletionItem item(this);
|
TextEditor::CompletionItem item(this);
|
||||||
item.text = it.key();
|
item.text = it.key();
|
||||||
|
|
||||||
|
QLatin1String postfix(": ");
|
||||||
|
if (afterOn)
|
||||||
|
postfix = QLatin1String(" {");
|
||||||
if (const Interpreter::QmlObjectValue *qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(it.value())) {
|
if (const Interpreter::QmlObjectValue *qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(it.value())) {
|
||||||
// to distinguish "anchors." from "gradient:" we check if the right hand side
|
// to distinguish "anchors." from "gradient:" we check if the right hand side
|
||||||
// type is instantiatable or is the prototype of an instantiatable object
|
// type is instantiatable or is the prototype of an instantiatable object
|
||||||
if (qmlValue->hasChildInPackage())
|
if (qmlValue->hasChildInPackage())
|
||||||
item.text.append(QLatin1String(": "));
|
item.text.append(postfix);
|
||||||
else
|
else
|
||||||
item.text.append(QLatin1Char('.'));
|
item.text.append(QLatin1Char('.'));
|
||||||
} else {
|
} else {
|
||||||
item.text.append(QLatin1String(": "));
|
item.text.append(postfix);
|
||||||
}
|
}
|
||||||
item.icon = icon;
|
item.icon = icon;
|
||||||
item.order = order;
|
item.order = order;
|
||||||
@@ -817,7 +821,7 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
idPropertyCompletion.order = PropertyOrder;
|
idPropertyCompletion.order = PropertyOrder;
|
||||||
m_completions.append(idPropertyCompletion);
|
m_completions.append(idPropertyCompletion);
|
||||||
|
|
||||||
addCompletionsPropertyLhs(enumerateProperties(qmlScopeType), symbolIcon, PropertyOrder);
|
addCompletionsPropertyLhs(enumerateProperties(qmlScopeType), symbolIcon, PropertyOrder, contextFinder.isAfterOnInLhsOfBinding());
|
||||||
if (const Interpreter::ObjectValue *qmlTypes = context->scopeChain().qmlTypes)
|
if (const Interpreter::ObjectValue *qmlTypes = context->scopeChain().qmlTypes)
|
||||||
addCompletions(enumerateProperties(qmlTypes), symbolIcon, TypeOrder);
|
addCompletions(enumerateProperties(qmlTypes), symbolIcon, TypeOrder);
|
||||||
|
|
||||||
@@ -895,7 +899,7 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
if (value && completionOperator == QLatin1Char('.')) { // member completion
|
if (value && completionOperator == QLatin1Char('.')) { // member completion
|
||||||
EnumerateProperties enumerateProperties(context);
|
EnumerateProperties enumerateProperties(context);
|
||||||
if (contextFinder.isInLhsOfBinding() && qmlScopeType && expressionUnderCursor.text().at(0).isLower())
|
if (contextFinder.isInLhsOfBinding() && qmlScopeType && expressionUnderCursor.text().at(0).isLower())
|
||||||
addCompletionsPropertyLhs(enumerateProperties(value), symbolIcon, PropertyOrder);
|
addCompletionsPropertyLhs(enumerateProperties(value), symbolIcon, PropertyOrder, contextFinder.isAfterOnInLhsOfBinding());
|
||||||
else
|
else
|
||||||
addCompletions(enumerateProperties(value), symbolIcon, SymbolOrder);
|
addCompletions(enumerateProperties(value), symbolIcon, SymbolOrder);
|
||||||
} else if (value && completionOperator == QLatin1Char('(') && m_startPosition == editor->position()) {
|
} else if (value && completionOperator == QLatin1Char('(') && m_startPosition == editor->position()) {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ private:
|
|||||||
const QIcon &icon, int relevance);
|
const QIcon &icon, int relevance);
|
||||||
void addCompletionsPropertyLhs(
|
void addCompletionsPropertyLhs(
|
||||||
const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
|
const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
|
||||||
const QIcon &icon, int relevance);
|
const QIcon &icon, int relevance, bool afterOn);
|
||||||
|
|
||||||
QmlJS::ModelManagerInterface *m_modelManager;
|
QmlJS::ModelManagerInterface *m_modelManager;
|
||||||
TextEditor::ITextEditable *m_editor;
|
TextEditor::ITextEditable *m_editor;
|
||||||
|
|||||||
Reference in New Issue
Block a user