Copilot: fixup compression timer cleanup

Unfortunately the timer gets deleted to early when the temporary object
that gets copied into the hash gets deleted. Delete the timer only if
the editor widget or client gets destructed.

Amends e6e895d6be

Change-Id: Ifee0dce337e7fc69ffeaeb82901135bd23ea8d81
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2023-03-24 13:35:03 +01:00
committed by Marcus Tillmanns
parent b5af4501df
commit 48cd81b015
2 changed files with 1 additions and 7 deletions

View File

@@ -95,7 +95,7 @@ void CopilotClient::scheduleRequest(TextEditorWidget *editor)
requestCompletions(editor); requestCompletions(editor);
}); });
connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() { connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() {
m_scheduledRequests.remove(editor); delete m_scheduledRequests.take(editor).timer;
cancelRunningRequest(editor); cancelRunningRequest(editor);
}); });
connect(editor, &TextEditorWidget::cursorPositionChanged, this, [this, editor] { connect(editor, &TextEditorWidget::cursorPositionChanged, this, [this, editor] {
@@ -108,11 +108,6 @@ void CopilotClient::scheduleRequest(TextEditorWidget *editor)
m_scheduledRequests[editor].timer->start(500); m_scheduledRequests[editor].timer->start(500);
} }
CopilotClient::ScheduleData::~ScheduleData()
{
delete timer;
}
void CopilotClient::requestCompletions(TextEditorWidget *editor) void CopilotClient::requestCompletions(TextEditorWidget *editor)
{ {
Utils::MultiTextCursor cursor = editor->multiTextCursor(); Utils::MultiTextCursor cursor = editor->multiTextCursor();

View File

@@ -50,7 +50,6 @@ private:
QMap<TextEditor::TextEditorWidget *, GetCompletionRequest> m_runningRequests; QMap<TextEditor::TextEditorWidget *, GetCompletionRequest> m_runningRequests;
struct ScheduleData struct ScheduleData
{ {
~ScheduleData();
int cursorPosition = -1; int cursorPosition = -1;
QTimer *timer = nullptr; QTimer *timer = nullptr;
}; };