diff options
author | David Schulz <david.schulz@qt.io> | 2022-08-18 10:16:42 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-08-18 11:58:57 +0000 |
commit | dc2cd9db946d4f176269b852e55f21134590f4b0 (patch) | |
tree | e6330783d9a34b91619fef916e4df5154f211dc5 | |
parent | e4b35fa5763e4a11258f94fc2381acb4c8792d29 (diff) | |
download | qt-creator-dc2cd9db946d4f176269b852e55f21134590f4b0.tar.gz |
LanguageClient: correctly disconnect documents changed signal on reset
connect calls to a lambda can not be disconnected with the
sender->disconnect(receiver);
syntax, so save the connection in a QMetaObject::Connection and use this
to disconnect the signal.
Fixes: QTCREATORBUG-27596
Change-Id: I69f5d990aab4e85d768e2101f0157a7dee3c1fa1
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | src/plugins/languageclient/client.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index eeb1499a74..bb4c4e6e32 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -278,7 +278,17 @@ public: QString m_displayName; LanguageFilter m_languagFilter; QJsonObject m_initializationOptions; - QMap<TextEditor::TextDocument *, QString> m_openedDocument; + class OpenedDocument + { + public: + ~OpenedDocument() + { + QObject::disconnect(contentsChangedConnection); + } + QMetaObject::Connection contentsChangedConnection; + QString documentContents; + }; + QMap<TextEditor::TextDocument *, OpenedDocument> m_openedDocument; // Used for build system artifacts (e.g. UI headers) that Qt Creator "live-generates" ahead of // the build. @@ -610,11 +620,14 @@ void Client::openDocument(TextEditor::TextDocument *document) } } - d->m_openedDocument[document] = document->plainText(); - connect(document, &TextDocument::contentsChangedWithPosition, this, - [this, document](int position, int charsRemoved, int charsAdded) { - documentContentsChanged(document, position, charsRemoved, charsAdded); - }); + d->m_openedDocument[document].documentContents = document->plainText(); + d->m_openedDocument[document].contentsChangedConnection + = connect(document, + &TextDocument::contentsChangedWithPosition, + this, + [this, document](int position, int charsRemoved, int charsAdded) { + documentContentsChanged(document, position, charsRemoved, charsAdded); + }); if (!d->m_documentVersions.contains(filePath)) d->m_documentVersions[filePath] = 0; d->sendOpenNotification(filePath, document->mimeType(), document->plainText(), @@ -1075,7 +1088,7 @@ void Client::documentContentsChanged(TextEditor::TextDocument *document, } } if (append) { - QTextDocument oldDoc(d->m_openedDocument[document]); + QTextDocument oldDoc(d->m_openedDocument[document].documentContents); QTextCursor cursor(&oldDoc); // Workaround https://bugreports.qt.io/browse/QTBUG-80662 // The contentsChanged gives a character count that can be wrong for QTextCursor @@ -1096,7 +1109,7 @@ void Client::documentContentsChanged(TextEditor::TextDocument *document, d->m_documentsToUpdate[document] = { DidChangeTextDocumentParams::TextDocumentContentChangeEvent(document->plainText())}; } - d->m_openedDocument[document] = document->plainText(); + d->m_openedDocument[document].documentContents = document->plainText(); } ++d->m_documentVersions[document->filePath()]; @@ -1521,8 +1534,6 @@ bool ClientPrivate::reset() m_dynamicCapabilities.reset(); if (m_diagnosticManager) m_diagnosticManager->clearDiagnostics(); - for (auto it = m_openedDocument.cbegin(); it != m_openedDocument.cend(); ++it) - it.key()->disconnect(this); m_openedDocument.clear(); // temporary container needed since m_resetAssistProvider is changed in resetAssistProviders for (TextEditor::TextDocument *document : m_resetAssistProvider.keys()) |