forked from qt-creator/qt-creator
LanguageClient: guard client access in formatter
Change-Id: I76bd41b3a786b1893bc159e0363f90494fd14b9f Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -49,6 +49,7 @@ static const FormattingOptions formattingOptions(const TextEditor::TabSettings &
|
|||||||
QFutureWatcher<ChangeSet> *LanguageClientFormatter::format(
|
QFutureWatcher<ChangeSet> *LanguageClientFormatter::format(
|
||||||
const QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)
|
const QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(m_client, return nullptr);
|
||||||
cancelCurrentRequest();
|
cancelCurrentRequest();
|
||||||
m_progress = QFutureInterface<ChangeSet>();
|
m_progress = QFutureInterface<ChangeSet>();
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ QFutureWatcher<ChangeSet> *LanguageClientFormatter::format(
|
|||||||
|
|
||||||
void LanguageClientFormatter::cancelCurrentRequest()
|
void LanguageClientFormatter::cancelCurrentRequest()
|
||||||
{
|
{
|
||||||
if (m_currentRequest.has_value()) {
|
if (QTC_GUARD(m_client) && m_currentRequest.has_value()) {
|
||||||
m_progress.reportCanceled();
|
m_progress.reportCanceled();
|
||||||
m_progress.reportFinished();
|
m_progress.reportFinished();
|
||||||
m_client->cancelRequest(*m_currentRequest);
|
m_client->cancelRequest(*m_currentRequest);
|
||||||
@@ -113,8 +114,8 @@ void LanguageClientFormatter::cancelCurrentRequest()
|
|||||||
void LanguageClientFormatter::handleResponse(const DocumentRangeFormattingRequest::Response &response)
|
void LanguageClientFormatter::handleResponse(const DocumentRangeFormattingRequest::Response &response)
|
||||||
{
|
{
|
||||||
m_currentRequest = std::nullopt;
|
m_currentRequest = std::nullopt;
|
||||||
if (const std::optional<DocumentRangeFormattingRequest::Response::Error> &error = response
|
const std::optional<DocumentRangeFormattingRequest::Response::Error> &error = response.error();
|
||||||
.error())
|
if (QTC_GUARD(m_client) && error)
|
||||||
m_client->log(*error);
|
m_client->log(*error);
|
||||||
ChangeSet changeSet;
|
ChangeSet changeSet;
|
||||||
if (std::optional<LanguageClientArray<TextEdit>> result = response.result()) {
|
if (std::optional<LanguageClientArray<TextEdit>> result = response.result()) {
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include <texteditor/formatter.h>
|
#include <texteditor/formatter.h>
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
namespace TextEditor { class TextDocument; }
|
namespace TextEditor { class TextDocument; }
|
||||||
namespace LanguageClient {
|
namespace LanguageClient {
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ private:
|
|||||||
void handleResponse(
|
void handleResponse(
|
||||||
const LanguageServerProtocol::DocumentRangeFormattingRequest::Response &response);
|
const LanguageServerProtocol::DocumentRangeFormattingRequest::Response &response);
|
||||||
|
|
||||||
Client *m_client = nullptr; // not owned
|
QPointer<Client> m_client = nullptr; // not owned
|
||||||
QMetaObject::Connection m_cancelConnection;
|
QMetaObject::Connection m_cancelConnection;
|
||||||
TextEditor::TextDocument *m_document; // not owned
|
TextEditor::TextDocument *m_document; // not owned
|
||||||
bool m_ignoreCancel = false;
|
bool m_ignoreCancel = false;
|
||||||
|
Reference in New Issue
Block a user