diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2016-06-23 12:20:28 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2016-06-24 07:29:27 +0000 |
commit | a1749f9a14f8d19f9d1c95c499cd242b3c6bd806 (patch) | |
tree | 79d6a1d801444a6c0055842892edb00f4c544594 | |
parent | cc804d542d93719ad67f817fb4bba70e5deb7246 (diff) | |
download | qt-creator-a1749f9a14f8d19f9d1c95c499cd242b3c6bd806.tar.gz |
Clang: Fix dot-arrow-correction for zero results
If there are no completion items, do not add snippets since these will
otherwise pop-up at undesired positions, e.g. when:
1) Typing float/doubles: 0.
2) Typing file suffix in include directives: #include "stdio.
Task-number: QTCREATORBUG-16188
Change-Id: Ie1c29826dc62dc447b2ff57b0c5537eb9d9511ef
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
5 files changed, 22 insertions, 6 deletions
diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index d19c12035d..5955d351f0 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -613,7 +613,7 @@ void ClangCompletionAssistProcessor::handleAvailableCompletions( QTC_CHECK(m_completions.isEmpty()); m_completions = toAssistProposalItems(completions); - if (m_addSnippets) + if (m_addSnippets && !m_completions.isEmpty()) addSnippets(); setAsyncProposalAvailable(createProposal(neededCorrection)); diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp index 54f35b9dca..2714c254b9 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp @@ -932,18 +932,28 @@ void ClangCodeCompletionTest::testCompleteConstructorAndFallbackToGlobalCompleti QVERIFY(!hasSnippet(t.proposal, "class")); } +// Explicitly Inserting The Dot +// ---------------------------- +// Inserting the dot for is important since it will send the editor +// content to the backend and thus generate an unsaved file on the backend +// side. The unsaved file enables us to do the dot to arrow correction. + void ClangCodeCompletionTest::testCompleteWithDotToArrowCorrection() { - // Inserting the dot for this test is important since it will send the editor - // content to the backend and thus generate an unsaved file on the backend - // side. The unsaved file enables us to do the dot to arrow correction. - ProjectLessCompletionTest t("dotToArrowCorrection.cpp", - QStringLiteral(".")); + QStringLiteral(".")); // See above "Explicitly Inserting The Dot" QVERIFY(hasItem(t.proposal, "member")); } +void ClangCodeCompletionTest::testDontCompleteWithDotToArrowCorrectionForFloats() +{ + ProjectLessCompletionTest t("noDotToArrowCorrectionForFloats.cpp", + QStringLiteral(".")); // See above "Explicitly Inserting The Dot" + + QCOMPARE(t.proposal->size(), 0); +} + void ClangCodeCompletionTest::testCompleteProjectDependingCode() { const TestDocument testDocument("completionWithProject.cpp"); diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.h b/src/plugins/clangcodemodel/test/clangcodecompletion_test.h index 54dba98c4e..f2d12234be 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.h +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.h @@ -49,6 +49,7 @@ private slots: void testCompleteConstructorAndFallbackToGlobalCompletion(); void testCompleteWithDotToArrowCorrection(); + void testDontCompleteWithDotToArrowCorrectionForFloats(); void testCompleteProjectDependingCode(); void testCompleteProjectDependingCodeAfterChangingProject(); diff --git a/src/plugins/clangcodemodel/test/data/clangtestdata.qrc b/src/plugins/clangcodemodel/test/data/clangtestdata.qrc index c013ccd7f4..ad5ccb4768 100644 --- a/src/plugins/clangcodemodel/test/data/clangtestdata.qrc +++ b/src/plugins/clangcodemodel/test/data/clangtestdata.qrc @@ -22,5 +22,6 @@ <file>objc_messages_3.mm</file> <file>preprocessorKeywordsCompletion.cpp</file> <file>dotToArrowCorrection.cpp</file> + <file>noDotToArrowCorrectionForFloats.cpp</file> </qresource> </RCC> diff --git a/src/plugins/clangcodemodel/test/data/noDotToArrowCorrectionForFloats.cpp b/src/plugins/clangcodemodel/test/data/noDotToArrowCorrectionForFloats.cpp new file mode 100644 index 0000000000..7b29c3e171 --- /dev/null +++ b/src/plugins/clangcodemodel/test/data/noDotToArrowCorrectionForFloats.cpp @@ -0,0 +1,4 @@ +void f() +{ + 0 /* COMPLETE HERE */ +} |