Editor: delete assist interface in lsp/clangd support

The complete memory management in the code assistant needs an overhaul.
For now just delete or at least track the assist interface with scoped
pointers.

Fixes: QTCREATORBUG-28408
Change-Id: I0bd4cfaa36a660b6fd5bb467af3b13414ed76e63
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
David Schulz
2022-11-07 12:02:07 +01:00
parent 3c6435387b
commit 08002c6278
6 changed files with 14 additions and 6 deletions

View File

@@ -417,6 +417,7 @@ IAssistProposal *CustomAssistProcessor::perform(const AssistInterface *interface
break;
}
}
delete interface;
GenericProposalModelPtr model(new GenericProposalModel);
model->loadContent(completions);
const auto proposal = new GenericProposal(m_position, model);

View File

@@ -12,6 +12,7 @@
#include <languageclient/languageclientsymbolsupport.h>
#include <languageserverprotocol/lsptypes.h>
#include <languageserverprotocol/jsonrpcmessages.h>
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/codeassist/iassistprovider.h>
#include <texteditor/textdocument.h>
@@ -41,8 +42,9 @@ public:
void resetData(bool resetFollowSymbolData);
private:
IAssistProposal *perform(const AssistInterface *) override
IAssistProposal *perform(const AssistInterface *interface) override
{
delete interface;
return nullptr;
}

View File

@@ -293,7 +293,8 @@ LanguageClientCompletionAssistProcessor::~LanguageClientCompletionAssistProcesso
QTextDocument *LanguageClientCompletionAssistProcessor::document() const
{
return m_document;
QTC_ASSERT(m_assistInterface, return nullptr);
return m_assistInterface->textDocument();
}
QList<AssistProposalItemInterface *> LanguageClientCompletionAssistProcessor::generateCompletionItems(
@@ -315,6 +316,7 @@ static QString assistReasonString(AssistReason reason)
IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistInterface *interface)
{
m_assistInterface.reset(interface);
QTC_ASSERT(m_client, return nullptr);
m_pos = interface->position();
m_basePos = m_pos;
@@ -366,7 +368,6 @@ IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistIn
m_client->sendMessage(completionRequest);
m_client->addAssistProcessor(this);
m_currentRequest = completionRequest.id();
m_document = interface->textDocument();
m_filePath = interface->filePath();
qCDebug(LOGLSPCOMPLETION) << QTime::currentTime()
<< " : request completions at " << m_pos
@@ -425,7 +426,7 @@ void LanguageClientCompletionAssistProcessor::handleCompletionResponse(
model->loadContent(proposalItems);
LanguageClientCompletionProposal *proposal = new LanguageClientCompletionProposal(m_basePos,
model);
proposal->m_document = m_document;
proposal->m_document = m_assistInterface->textDocument();
proposal->m_pos = m_pos;
proposal->setSupportsPrefix(false);
setAsyncProposalAvailable(proposal);

View File

@@ -11,6 +11,7 @@
#include <texteditor/codeassist/iassistprocessor.h>
#include <QPointer>
#include <QScopedPointer>
#include <functional>
#include <optional>
@@ -74,7 +75,7 @@ protected:
private:
void handleCompletionResponse(const LanguageServerProtocol::CompletionRequest::Response &response);
QPointer<QTextDocument> m_document;
QScopedPointer<const TextEditor::AssistInterface> m_assistInterface;
Utils::FilePath m_filePath;
QPointer<Client> m_client;
std::optional<LanguageServerProtocol::MessageId> m_currentRequest;

View File

@@ -10,6 +10,8 @@
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/codeassist/ifunctionhintproposalmodel.h>
#include <QScopedPointer>
using namespace TextEditor;
using namespace LanguageServerProtocol;
@@ -66,6 +68,7 @@ FunctionHintProcessor::FunctionHintProcessor(Client *client)
IAssistProposal *FunctionHintProcessor::perform(const AssistInterface *interface)
{
const QScopedPointer<const AssistInterface> deleter(interface);
QTC_ASSERT(m_client, return nullptr);
m_pos = interface->position();
QTextCursor cursor(interface->textDocument());

View File

@@ -19,7 +19,7 @@ public:
virtual ~IAssistProcessor();
virtual IAssistProposal *immediateProposal(const AssistInterface *) { return nullptr; }
virtual IAssistProposal *perform(const AssistInterface *interface) = 0;
virtual IAssistProposal *perform(const AssistInterface *interface) = 0; // takes ownership
void setAsyncProposalAvailable(IAssistProposal *proposal);