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 <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-02-26 08:50:43 +01:00
parent 4cd4316a16
commit 1f37eaa265
2 changed files with 9 additions and 3 deletions

View File

@@ -215,8 +215,11 @@ void ClangCompletionAssistProcessor::handleAvailableCompletions(const CodeComple
return; return;
} }
if (!m_fallbackToNormalCompletion) if (!m_fallbackToNormalCompletion) {
// We must report back to the code assistant under all circumstances
setAsyncProposalAvailable(nullptr);
return; return;
}
// else: Proceed with a normal completion in case: // else: Proceed with a normal completion in case:
// 1) it was not a function call, but e.g. a function declaration like "void f(" // 1) it was not a function call, but e.g. a function declaration like "void f("
// 2) '{' meant not a constructor call. // 2) '{' meant not a constructor call.

View File

@@ -35,6 +35,7 @@
#include <texteditor/codeassist/genericproposal.h> #include <texteditor/codeassist/genericproposal.h>
#include <texteditor/codeassist/genericproposalmodel.h> #include <texteditor/codeassist/genericproposalmodel.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/executeondestruction.h>
#include <utils/textutils.h> #include <utils/textutils.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
@@ -361,6 +362,9 @@ void LanguageClientCompletionAssistProcessor::cancel()
void LanguageClientCompletionAssistProcessor::handleCompletionResponse( void LanguageClientCompletionAssistProcessor::handleCompletionResponse(
const CompletionRequest::Response &response) 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"; qCDebug(LOGLSPCOMPLETION) << QTime::currentTime() << " : got completions";
m_currentRequest = MessageId(); m_currentRequest = MessageId();
QTC_ASSERT(m_client, return); QTC_ASSERT(m_client, return);
@@ -383,12 +387,11 @@ void LanguageClientCompletionAssistProcessor::handleCompletionResponse(
model->loadContent(Utils::transform(items, [](const CompletionItem &item){ model->loadContent(Utils::transform(items, [](const CompletionItem &item){
return static_cast<AssistProposalItemInterface *>(new LanguageClientCompletionItem(item)); return static_cast<AssistProposalItemInterface *>(new LanguageClientCompletionItem(item));
})); }));
auto proposal = new LanguageClientCompletionProposal(m_pos, model); proposal = new LanguageClientCompletionProposal(m_pos, model);
proposal->m_document = m_document; proposal->m_document = m_document;
proposal->m_pos = m_pos; proposal->m_pos = m_pos;
proposal->setFragile(true); proposal->setFragile(true);
proposal->setSupportsPrefix(false); proposal->setSupportsPrefix(false);
setAsyncProposalAvailable(proposal);
qCDebug(LOGLSPCOMPLETION) << QTime::currentTime() << " : " qCDebug(LOGLSPCOMPLETION) << QTime::currentTime() << " : "
<< items.count() << " completions handled"; << items.count() << " completions handled";
} }