From dc4b9e48dcaeeb8e84ff6784a60b8a4fb39e5e8e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 14 Jan 2022 10:55:15 +0100 Subject: [PATCH] Clangd: clean up text marks after deleting client This is a blindshot and more a workaround than a fix. Assert and try to cleanup dangling text marks after a client got deleted. In theory those marks should get deleted by the DiagnosticManager but somehow, they are still alive and happy after the client was deleted. Task-number: QTCREATORBUG-26585 Change-Id: I9d5d708db3fbbe30a09d322400d97184fe40a518 Reviewed-by: Christian Kandeler --- src/plugins/clangcodemodel/clangtextmark.cpp | 10 ++++++++++ src/plugins/clangcodemodel/clangtextmark.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/plugins/clangcodemodel/clangtextmark.cpp b/src/plugins/clangcodemodel/clangtextmark.cpp index ad548b4f5e3..f7160df1237 100644 --- a/src/plugins/clangcodemodel/clangtextmark.cpp +++ b/src/plugins/clangcodemodel/clangtextmark.cpp @@ -406,6 +406,11 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath, ClangDiagnosticManager::addTask(m_diagnostic); } + m_clientDeleted = QObject::connect(client, &QObject::destroyed, [this] (){ + QTC_ASSERT_STRING("ClangdClient deleted before TextMark"); + delete this; + }); + // Copy to clipboard action QVector actions; QAction *action = new QAction(); @@ -433,6 +438,11 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath, setActions(actions); } +ClangdTextMark::~ClangdTextMark() +{ + QObject::disconnect(m_clientDeleted); +} + bool ClangdTextMark::addToolTipContent(QLayout *target) const { const auto canApplyFixIt = [c = m_client, diag = m_lspDiagnostic, fp = fileName()] { diff --git a/src/plugins/clangcodemodel/clangtextmark.h b/src/plugins/clangcodemodel/clangtextmark.h index 15b97ab32f1..8ab892e1bcf 100644 --- a/src/plugins/clangcodemodel/clangtextmark.h +++ b/src/plugins/clangcodemodel/clangtextmark.h @@ -73,6 +73,7 @@ public: ClangdTextMark(const ::Utils::FilePath &filePath, const LanguageServerProtocol::Diagnostic &diagnostic, const LanguageClient::Client *client); + ~ClangdTextMark(); private: bool addToolTipContent(QLayout *target) const override; @@ -80,6 +81,8 @@ private: const LanguageServerProtocol::Diagnostic m_lspDiagnostic; const ClangBackEnd::DiagnosticContainer m_diagnostic; const QPointer m_client; + + QMetaObject::Connection m_clientDeleted; }; } // namespace Internal