summaryrefslogtreecommitdiff
path: root/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-08-28 12:17:33 +0200
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-08-30 13:36:52 +0000
commit8b6a16c95b6c49e0737519df20c0826d542d8c17 (patch)
tree86d1a6df91493eb782993502168e9b1faa12e365 /src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
parenta6719ed0ffcab1daa2995b0ebadc0f846e52ea0f (diff)
downloadqt-creator-8b6a16c95b6c49e0737519df20c0826d542d8c17.tar.gz
Clang: Fix completion after '{'
Follow-up fix for 8d0391a4f9. Do not complete after '{' coming not after an identifier. Take constructor completions only for '{' and function completions only for '('. Filter constructor completions by class/struct type. Task-number: QTCREATORBUG-21004 Change-Id: I7ae2d6bee23cf907648c42b93eb12742942833f6 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp')
-rw-r--r--src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
index 1dd1a98671..4c1f846aa8 100644
--- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
+++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
@@ -190,8 +190,22 @@ IAssistProposal *ClangCompletionAssistProcessor::perform(const AssistInterface *
static CodeCompletions filterFunctionSignatures(const CodeCompletions &completions)
{
return ::Utils::filtered(completions, [](const CodeCompletion &completion) {
- return completion.completionKind == CodeCompletion::FunctionOverloadCompletionKind
- || completion.completionKind == CodeCompletion::ConstructorCompletionKind;
+ return completion.completionKind == CodeCompletion::FunctionOverloadCompletionKind;
+ });
+}
+
+static CodeCompletions filterConstructorSignatures(Utf8String textBefore,
+ const CodeCompletions &completions)
+{
+ const int prevStatementEnd = textBefore.lastIndexOf(";");
+ if (prevStatementEnd != -1)
+ textBefore = textBefore.mid(prevStatementEnd + 1);
+
+ return ::Utils::filtered(completions, [&textBefore](const CodeCompletion &completion) {
+ if (completion.completionKind != CodeCompletion::ConstructorCompletionKind)
+ return false;
+ const Utf8String type = completion.chunks.at(0).text;
+ return textBefore.indexOf(type) != -1;
});
}
@@ -201,7 +215,18 @@ void ClangCompletionAssistProcessor::handleAvailableCompletions(
QTC_CHECK(m_completions.isEmpty());
if (m_sentRequestType == FunctionHintCompletion){
- const CodeCompletions functionSignatures = filterFunctionSignatures(completions);
+ CodeCompletions functionSignatures;
+ if (m_completionOperator == T_LPAREN) {
+ functionSignatures = filterFunctionSignatures(completions);
+ } else {
+ const QTextBlock block = m_interface->textDocument()->findBlock(
+ m_interface->position());
+ const QString textBefore = block.text().left(
+ m_interface->position() - block.position());
+
+ functionSignatures = filterConstructorSignatures(textBefore, completions);
+ }
+
if (!functionSignatures.isEmpty()) {
setAsyncProposalAvailable(createFunctionHintProposal(functionSignatures));
return;