From 79b8e5397d340d70ad755c7bd8301846d89cafab Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 16 Jun 2022 15:21:34 +0200 Subject: [PATCH] ClangCodeModel: Prevent surprisingly late "follow symbol" reactions It can happen under certain circumstances (high system load, overworked clangd, ...) that "follow symbol" requests get replied to very late, with the user having manually navigated to the target document in the mean time or started doing something else entirely. In such a situation, it would be disruptive if we were to jump to a symbol suddenly, stealing the cursor from the unsuspecting user. We now prevent this by aborting the "follow symbol" procedure if the user does something else with the document. Fixes: QTCREATORBUG-20878 Change-Id: Iea52db661e8ba634951b18654a94e4b90580f001 Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdfollowsymbol.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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.