forked from qt-creator/qt-creator
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 <david.schulz@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <texteditor/codeassist/iassistprovider.h>
|
#include <texteditor/codeassist/iassistprovider.h>
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
using namespace CppEditor;
|
using namespace CppEditor;
|
||||||
@@ -143,6 +144,16 @@ ClangdFollowSymbol::ClangdFollowSymbol(ClangdClient *client, const QTextCursor &
|
|||||||
d(new Private(this, client, cursor, editorWidget, document->filePath(), callback,
|
d(new Private(this, client, cursor, editorWidget, document->filePath(), callback,
|
||||||
openInSplit))
|
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
|
// 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
|
// AST node corresponding to the cursor position, so we can find out whether
|
||||||
// we have to look for overrides.
|
// we have to look for overrides.
|
||||||
|
Reference in New Issue
Block a user