ClangCodeModel: Fix persistent SwitchDeclDef object

If both AST and document symbols are available right away, the
ClangdSwitchDeclDef object emits its done() signal before it is
connected and stays around, potentially firing off new "follow symbol"
requests to the bewilderment of innocent users.

Fixes: QTCREATORBUG-28183
Change-Id: I972c8d4d9d7b7435e293d76fe710b19c9c4fb287
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-11-07 13:34:45 +01:00
parent a1851c7cf1
commit c4ee485bdf

View File

@@ -13,6 +13,7 @@
#include <utils/qtcassert.h>
#include <QApplication>
#include <QMetaObject>
#include <QTextCursor>
#include <optional>
@@ -68,6 +69,7 @@ ClangdSwitchDeclDef::ClangdSwitchDeclDef(ClangdClient *client, TextDocument *doc
[this](const DocumentUri &uri, const DocumentSymbolsResult &symbols) {
if (uri != d->uri)
return;
d->client->documentSymbolCache()->disconnect(this);
d->docSymbols = symbols;
if (d->ast)
d->handleDeclDefSwitchReplies();
@@ -108,7 +110,7 @@ void ClangdSwitchDeclDef::emitDone()
return;
d->done = true;
emit done();
QMetaObject::invokeMethod(this, &ClangdSwitchDeclDef::done, Qt::QueuedConnection);
}
std::optional<ClangdAstNode> ClangdSwitchDeclDef::Private::getFunctionNode() const