forked from qt-creator/qt-creator
QmlJS: Improve completion for object bindings with 'on'.
Done-with: Erik Verbruggen
This commit is contained in:
@@ -17,6 +17,7 @@ using namespace QmlJS;
|
|||||||
CompletionContextFinder::CompletionContextFinder(const QTextCursor &cursor)
|
CompletionContextFinder::CompletionContextFinder(const QTextCursor &cursor)
|
||||||
: m_cursor(cursor)
|
: m_cursor(cursor)
|
||||||
, m_colonCount(-1)
|
, m_colonCount(-1)
|
||||||
|
, m_behaviorBinding(false)
|
||||||
{
|
{
|
||||||
QTextBlock lastBlock = cursor.block();
|
QTextBlock lastBlock = cursor.block();
|
||||||
if (lastBlock.next().isValid())
|
if (lastBlock.next().isValid())
|
||||||
@@ -90,6 +91,7 @@ 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;
|
||||||
while (!delimiterFound) {
|
while (!delimiterFound) {
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
if (!readLine())
|
if (!readLine())
|
||||||
@@ -113,11 +115,17 @@ void CompletionContextFinder::checkBinding()
|
|||||||
++colonCount;
|
++colonCount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Token::Identifier:
|
||||||
|
if (firstToken && yyLine->midRef(token.begin(), token.length) == QLatin1String("on"))
|
||||||
|
m_behaviorBinding = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
--i;
|
--i;
|
||||||
|
firstToken = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
YY_RESTORE();
|
YY_RESTORE();
|
||||||
@@ -145,6 +153,15 @@ bool CompletionContextFinder::isInRhsOfBinding() const
|
|||||||
return isInQmlContext() && m_colonCount == 1;
|
return isInQmlContext() && m_colonCount == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\return true if the cursor after "Type on" in the left hand side
|
||||||
|
of a binding, false otherwise.
|
||||||
|
*/
|
||||||
|
bool CompletionContextFinder::isAfterOnInLhsOfBinding() const
|
||||||
|
{
|
||||||
|
return isInLhsOfBinding() && m_behaviorBinding;
|
||||||
|
}
|
||||||
|
|
||||||
int CompletionContextFinder::findOpeningBrace(int startTokenIndex)
|
int CompletionContextFinder::findOpeningBrace(int startTokenIndex)
|
||||||
{
|
{
|
||||||
YY_SAVE();
|
YY_SAVE();
|
||||||
@@ -211,8 +228,3 @@ int CompletionContextFinder::findOpeningBrace(int startTokenIndex)
|
|||||||
YY_RESTORE();
|
YY_RESTORE();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompletionContextFinder::inQmlBindingRhs()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public:
|
|||||||
bool isInLhsOfBinding() const;
|
bool isInLhsOfBinding() const;
|
||||||
bool isInRhsOfBinding() const;
|
bool isInRhsOfBinding() const;
|
||||||
|
|
||||||
|
bool isAfterOnInLhsOfBinding() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int findOpeningBrace(int startTokenIndex);
|
int findOpeningBrace(int startTokenIndex);
|
||||||
void getQmlObjectTypeName(int startTokenIndex);
|
void getQmlObjectTypeName(int startTokenIndex);
|
||||||
@@ -33,6 +35,7 @@ private:
|
|||||||
|
|
||||||
int m_startTokenIndex;
|
int m_startTokenIndex;
|
||||||
int m_colonCount;
|
int m_colonCount;
|
||||||
|
bool m_behaviorBinding;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlJS
|
} // namespace QmlJS
|
||||||
|
|||||||
@@ -650,8 +650,6 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
|
|
||||||
bool doGlobalCompletion = true;
|
bool doGlobalCompletion = true;
|
||||||
if (contextFinder.isInLhsOfBinding() && qmlScopeType) {
|
if (contextFinder.isInLhsOfBinding() && qmlScopeType) {
|
||||||
qDebug() << "LHS of binding!";
|
|
||||||
|
|
||||||
doGlobalCompletion = false;
|
doGlobalCompletion = false;
|
||||||
EnumerateProperties enumerateProperties(&context);
|
EnumerateProperties enumerateProperties(&context);
|
||||||
enumerateProperties.setGlobalCompletion(true);
|
enumerateProperties.setGlobalCompletion(true);
|
||||||
@@ -662,7 +660,9 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
|
|
||||||
TextEditor::CompletionItem item(this);
|
TextEditor::CompletionItem item(this);
|
||||||
item.text = it.key();
|
item.text = it.key();
|
||||||
item.data = QString(it.key() + QLatin1String(": "));
|
item.data = it.key();
|
||||||
|
if (!contextFinder.isAfterOnInLhsOfBinding())
|
||||||
|
item.data = QString(item.data.toString() + QLatin1String(": "));
|
||||||
item.icon = symbolIcon;
|
item.icon = symbolIcon;
|
||||||
m_completions.append(item);
|
m_completions.append(item);
|
||||||
}
|
}
|
||||||
@@ -673,12 +673,6 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
|
|
||||||
TextEditor::CompletionItem item(this);
|
TextEditor::CompletionItem item(this);
|
||||||
item.text = it.key();
|
item.text = it.key();
|
||||||
QString data = it.key();
|
|
||||||
data.append(QLatin1String(" {\n"));
|
|
||||||
data.append(QChar::ObjectReplacementCharacter);
|
|
||||||
data.append(QChar::ObjectReplacementCharacter);
|
|
||||||
data.append(QLatin1String("\n}"));
|
|
||||||
item.data = data;
|
|
||||||
item.icon = symbolIcon;
|
item.icon = symbolIcon;
|
||||||
m_completions.append(item);
|
m_completions.append(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user