From 1f37eaa26585263f528d40aeaa6589f17ebe263d Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 26 Feb 2020 08:50:43 +0100 Subject: [PATCH] Editor: Fix crash in codeassist We have to report back to the code assistant even if we have no results. Otherwise the processors aren't correctly reset and may be called after deletion. Change-Id: Id7af2e0ee9f631efc00beb2a84bfe1824e138d24 Reviewed-by: Christian Stenger --- .../clangcodemodel/clangcompletionassistprocessor.cpp | 5 ++++- .../languageclient/languageclientcompletionassist.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index 09f5ee95075..592f7c8795c 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -215,8 +215,11 @@ void ClangCompletionAssistProcessor::handleAvailableCompletions(const CodeComple return; } - if (!m_fallbackToNormalCompletion) + if (!m_fallbackToNormalCompletion) { + // We must report back to the code assistant under all circumstances + setAsyncProposalAvailable(nullptr); return; + } // else: Proceed with a normal completion in case: // 1) it was not a function call, but e.g. a function declaration like "void f(" // 2) '{' meant not a constructor call. diff --git a/src/plugins/languageclient/languageclientcompletionassist.cpp b/src/plugins/languageclient/languageclientcompletionassist.cpp index ae2eca2ff63..54b9740809c 100644 --- a/src/plugins/languageclient/languageclientcompletionassist.cpp +++ b/src/plugins/languageclient/languageclientcompletionassist.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -361,6 +362,9 @@ void LanguageClientCompletionAssistProcessor::cancel() void LanguageClientCompletionAssistProcessor::handleCompletionResponse( const CompletionRequest::Response &response) { + LanguageClientCompletionProposal *proposal = nullptr; + // We must report back to the code assistant under all circumstances + Utils::ExecuteOnDestruction eod([this, proposal]() { setAsyncProposalAvailable(proposal); }); qCDebug(LOGLSPCOMPLETION) << QTime::currentTime() << " : got completions"; m_currentRequest = MessageId(); QTC_ASSERT(m_client, return); @@ -383,12 +387,11 @@ void LanguageClientCompletionAssistProcessor::handleCompletionResponse( model->loadContent(Utils::transform(items, [](const CompletionItem &item){ return static_cast(new LanguageClientCompletionItem(item)); })); - auto proposal = new LanguageClientCompletionProposal(m_pos, model); + proposal = new LanguageClientCompletionProposal(m_pos, model); proposal->m_document = m_document; proposal->m_pos = m_pos; proposal->setFragile(true); proposal->setSupportsPrefix(false); - setAsyncProposalAvailable(proposal); qCDebug(LOGLSPCOMPLETION) << QTime::currentTime() << " : " << items.count() << " completions handled"; }