diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2021-01-26 14:24:06 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2021-01-26 15:55:41 +0000 |
commit | d9e5d079be666d1f006d9944f47298fa98d0e7ff (patch) | |
tree | 1f61438125f4644690ddb9ed015235b1baeb463b /src | |
parent | acfb2e4f2f19af3f58ab082a08ee76a0106dc990 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp | 12 | ||||
-rw-r--r-- | src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp | 16 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index 98f5083174..3902119e8c 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -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) { diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp index e32e22d8e1..c77dbfc08e 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp @@ -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="}; |