forked from qt-creator/qt-creator
CppTools: Fix global completion after '&'
Regression introduced by
commit 9fb5b0be15
CppTools: Add basic completion support for qt5 style signals/slots
Change-Id: I0a8e5ef31c1394512a51a26ed08b0f445add5acd
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -162,6 +162,16 @@ private:
|
|||||||
IEditor *m_editor;
|
IEditor *m_editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool isProbablyGlobalCompletion(const QStringList &list)
|
||||||
|
{
|
||||||
|
const int numberOfPrimitivesAndBasicKeywords = (T_LAST_PRIMITIVE - T_FIRST_PRIMITIVE)
|
||||||
|
+ (T_FIRST_OBJC_AT_KEYWORD - T_FIRST_KEYWORD);
|
||||||
|
|
||||||
|
return list.size() >= numberOfPrimitivesAndBasicKeywords
|
||||||
|
&& list.contains(QLatin1String("if"))
|
||||||
|
&& list.contains(QLatin1String("bool"));
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
void CppToolsPlugin::test_completion_basic_1()
|
void CppToolsPlugin::test_completion_basic_1()
|
||||||
@@ -327,6 +337,31 @@ void CppToolsPlugin::test_completion()
|
|||||||
QCOMPARE(actualCompletions, expectedCompletions);
|
QCOMPARE(actualCompletions, expectedCompletions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppToolsPlugin::test_global_completion_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QByteArray>("code");
|
||||||
|
QTest::addColumn<QByteArray>("prefix");
|
||||||
|
|
||||||
|
// Check that special completion after '&' for Qt5 signal/slots does not
|
||||||
|
// interfere global completion after '&'
|
||||||
|
QTest::newRow("global completion after & in return expression")
|
||||||
|
<< _("void f() { foo(myObject, @); }\n")
|
||||||
|
<< _("&");
|
||||||
|
QTest::newRow("global completion after & in function argument")
|
||||||
|
<< _("int f() { return @; }\n")
|
||||||
|
<< _("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppToolsPlugin::test_global_completion()
|
||||||
|
{
|
||||||
|
QFETCH(QByteArray, code);
|
||||||
|
QFETCH(QByteArray, prefix);
|
||||||
|
|
||||||
|
CompletionTestCase test(code, prefix);
|
||||||
|
QVERIFY(test.succeededSoFar());
|
||||||
|
QVERIFY(isProbablyGlobalCompletion(test.getCompletions()));
|
||||||
|
}
|
||||||
|
|
||||||
static void enumTestCase(const QByteArray &tag, const QByteArray &source,
|
static void enumTestCase(const QByteArray &tag, const QByteArray &source,
|
||||||
const QByteArray &prefix = QByteArray())
|
const QByteArray &prefix = QByteArray())
|
||||||
{
|
{
|
||||||
@@ -2337,14 +2372,6 @@ void CppToolsPlugin::test_completion_data()
|
|||||||
<< QLatin1String("hiddenFunction")
|
<< QLatin1String("hiddenFunction")
|
||||||
<< QLatin1String("hiddenSignal"));
|
<< QLatin1String("hiddenSignal"));
|
||||||
|
|
||||||
QTest::newRow("Qt5 signals: no class name completion if not after 'connect(' 1")
|
|
||||||
<< commonSignalSlotCompletionTestCode
|
|
||||||
<< _("foo(myObject, &") << (QStringList());
|
|
||||||
|
|
||||||
QTest::newRow("Qt5 signals/slots: no class name completion if not after 'connect(' 2")
|
|
||||||
<< commonSignalSlotCompletionTestCode
|
|
||||||
<< _("&") << (QStringList());
|
|
||||||
|
|
||||||
QTest::newRow("Qt5 signals: fallback to scope completion")
|
QTest::newRow("Qt5 signals: fallback to scope completion")
|
||||||
<< commonSignalSlotCompletionTestCode
|
<< commonSignalSlotCompletionTestCode
|
||||||
<< _("connect(myObject, &N::") << (QStringList()
|
<< _("connect(myObject, &N::") << (QStringList()
|
||||||
|
@@ -1128,8 +1128,14 @@ int InternalCppCompletionAssistProcessor::startCompletionHelper()
|
|||||||
// "connect(sender, &" or
|
// "connect(sender, &" or
|
||||||
// "connect(otherSender, &Foo::signal1, receiver, &"
|
// "connect(otherSender, &Foo::signal1, receiver, &"
|
||||||
const int beforeExpression = startOfExpression - 1;
|
const int beforeExpression = startOfExpression - 1;
|
||||||
if (canCompleteClassNameAt2ndOr4thConnectArgument(m_interface.data(), beforeExpression))
|
if (canCompleteClassNameAt2ndOr4thConnectArgument(m_interface.data(),
|
||||||
|
beforeExpression)) {
|
||||||
m_model->m_completionOperator = CompleteQt5SignalOrSlotClassNameTrigger;
|
m_model->m_completionOperator = CompleteQt5SignalOrSlotClassNameTrigger;
|
||||||
|
} else { // Ensure global completion
|
||||||
|
startOfExpression = endOfExpression = m_startPosition;
|
||||||
|
expression.clear();
|
||||||
|
m_model->m_completionOperator = T_EOF_SYMBOL;
|
||||||
|
}
|
||||||
} else if (m_model->m_completionOperator == T_COLON_COLON) {
|
} else if (m_model->m_completionOperator == T_COLON_COLON) {
|
||||||
// We expect 'expression' to be "Foo" in
|
// We expect 'expression' to be "Foo" in
|
||||||
// "connect(sender, &Foo::" or
|
// "connect(sender, &Foo::" or
|
||||||
|
@@ -112,6 +112,9 @@ private slots:
|
|||||||
void test_completion_data();
|
void test_completion_data();
|
||||||
void test_completion();
|
void test_completion();
|
||||||
|
|
||||||
|
void test_global_completion_data();
|
||||||
|
void test_global_completion();
|
||||||
|
|
||||||
void test_completion_member_access_operator_data();
|
void test_completion_member_access_operator_data();
|
||||||
void test_completion_member_access_operator();
|
void test_completion_member_access_operator();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user