forked from qt-creator/qt-creator
ClangCodeModel: Relax completion result filtering
... in connect() calls.
The logic was: If we are in a place where a signal is expected and there
are signals among the completion results, then we should consider only
signals.
However, in e.g. a member function of a QObject subclass, there are
always signals in scope, even when we expect a class name. So we need to
allow class names as well.
Amends a79b0c6558
.
Fixes: QTCREATORBUG-25153
Change-Id: Id3bbaaf4f8eefefe36cfc91e5959d3ef5ad28071
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -139,15 +139,17 @@ QList<AssistProposalItemInterface *> ClangCompletionAssistProcessor::toAssistPro
|
||||
considerOnlySignals = CppTools::CppModelManager::instance()
|
||||
->positionRequiresSignal(m_interface->filePath().toString(), m_content, m_position);
|
||||
}
|
||||
|
||||
for (const CodeCompletion &codeCompletion : completions) {
|
||||
if (considerOnlySignals && codeCompletion.completionKind
|
||||
!= CodeCompletion::SignalCompletionKind) {
|
||||
continue;
|
||||
}
|
||||
if (codeCompletion.text.isEmpty())
|
||||
continue; // It's an OverloadCandidate which has text but no typedText.
|
||||
|
||||
if (considerOnlySignals
|
||||
&& codeCompletion.completionKind != CodeCompletion::ClassCompletionKind
|
||||
&& codeCompletion.completionKind != CodeCompletion::NamespaceCompletionKind
|
||||
&& codeCompletion.completionKind != CodeCompletion::SignalCompletionKind) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't offer symbols that are not accessible here.
|
||||
if (codeCompletion.availability == CodeCompletion::NotAvailable
|
||||
|| codeCompletion.availability == CodeCompletion::NotAccessible) {
|
||||
|
@@ -765,27 +765,29 @@ void ClangCodeCompletionTest::testSignalCompletion_data()
|
||||
QTest::addColumn<QByteArray>("customContents");
|
||||
QTest::addColumn<QByteArrayList>("hits");
|
||||
|
||||
// libclang mis-reports CXCursor_ClassDecl instead of CXCursor_Constructor, so the lists
|
||||
// below include the class name.
|
||||
QTest::addRow("positive: connect() on QObject class")
|
||||
<< QByteArray("int main() { QObject::connect(dummy, QObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "QObject"};
|
||||
QTest::addRow("positive: connect() on QObject object")
|
||||
<< QByteArray("int main() { QObject o; o.connect(dummy, QObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "QObject"};
|
||||
QTest::addRow("positive: connect() on QObject pointer")
|
||||
<< QByteArray("int main() { QObject *o; o->connect(dummy, QObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "QObject"};
|
||||
QTest::addRow("positive: connect() on QObject rvalue")
|
||||
<< QByteArray("int main() { QObject().connect(dummy, QObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "QObject"};
|
||||
QTest::addRow("positive: connect() on QObject pointer rvalue")
|
||||
<< QByteArray("int main() { (new QObject)->connect(dummy, QObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "QObject"};
|
||||
QTest::addRow("positive: disconnect() on QObject")
|
||||
<< QByteArray("int main() { QObject::disconnect(dummy, QObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "QObject"};
|
||||
QTest::addRow("positive: connect() in member function of derived class")
|
||||
<< QByteArray("void DerivedFromQObject::alsoNotASignal() { connect(this, DerivedFromQObject::")
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "myOwnSignal"};
|
||||
<< QByteArrayList{"aSignal", "anotherSignal", "myOwnSignal", "QObject", "DerivedFromQObject"};
|
||||
|
||||
const QByteArrayList allQObjectFunctions{"aSignal", "anotherSignal", "notASignal", "connect",
|
||||
"disconnect", "QObject", "~QObject", "operator="};
|
||||
|
Reference in New Issue
Block a user