diff --git a/src/plugins/clangcodemodel/clangdfollowsymbol.cpp b/src/plugins/clangcodemodel/clangdfollowsymbol.cpp index 53ec97342f4..64993a03ba0 100644 --- a/src/plugins/clangcodemodel/clangdfollowsymbol.cpp +++ b/src/plugins/clangcodemodel/clangdfollowsymbol.cpp @@ -38,6 +38,7 @@ #include #include +#include #include using namespace CppEditor; @@ -143,6 +144,16 @@ ClangdFollowSymbol::ClangdFollowSymbol(ClangdClient *client, const QTextCursor & d(new Private(this, client, cursor, editorWidget, document->filePath(), callback, openInSplit)) { + // Abort if the user does something else with the document in the meantime. + connect(document, &TextDocument::contentsChanged, this, &ClangdFollowSymbol::done, + Qt::QueuedConnection); + if (editorWidget) { + connect(editorWidget, &CppEditorWidget::cursorPositionChanged, + this, &ClangdFollowSymbol::done, Qt::QueuedConnection); + } + connect(qApp, &QApplication::focusChanged, + this, &ClangdFollowSymbol::done, Qt::QueuedConnection); + // Step 1: Follow the symbol via "Go to Definition". At the same time, request the // AST node corresponding to the cursor position, so we can find out whether // we have to look for overrides.