aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangcodemodel/test
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2023-06-23 13:32:35 +0200
committerDavid Schulz <[email protected]>2023-06-28 12:33:51 +0000
commit520264999af1ac56693c9720e0aeb2e032749d5d (patch)
tree39c7c03601c7510ba887c8061a80e2bfad0ab901 /src/plugins/clangcodemodel/test
parenta6e57425699f233d670c59d16bc247dfb08c028a (diff)
ClangCodeModel: fix crash on followSymbol
Big files are loaded in chunks inside a QEventLoop. If follow symbol is triggered via mouse and opens such a big file and the mouse is moved while loading that file ClangdFollowSymbol got deleted while opening the file in ClangdClient::followSymbol. Instead of the hard deletion just cancel that follow symbol operation and make sure done is emitted afterwards. The handling of that done signal takes care of the deletion of that follow symbol operation. Change-Id: Iba4ad6abb541186c2f26506f82fe1bc582818fca Reviewed-by: <[email protected]> Reviewed-by: Christian Kandeler <[email protected]>
Diffstat (limited to 'src/plugins/clangcodemodel/test')
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp32
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index 5a52a207853..ceaf25787e8 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -4,6 +4,7 @@
#include "clangdtests.h"
#include "../clangdclient.h"
+#include "../clangdfollowsymbol.h"
#include "../clangmodelmanagersupport.h"
#include <coreplugin/editormanager/editormanager.h>
@@ -428,6 +429,37 @@ void ClangdTestFollowSymbol::test()
QCOMPARE(actualLink.targetColumn + 1, targetColumn);
}
+// Make sure it is safe to call follow symbol in a follow symbol handler. Since follow symbol
+// potentially opens a file that gets loaded in chunks which handles user events inbetween
+// the chunks we can potentially call a follow symbol while currently handling another one.
+void ClangdTestFollowSymbol::testFollowSymbolInHandler()
+{
+ TextEditor::TextDocument *const doc = document("header.h");
+ QVERIFY(doc);
+ QTimer timer;
+ timer.setSingleShot(true);
+ QEventLoop loop;
+ QTextCursor cursor(doc->document());
+ const int pos = Text::positionInText(doc->document(), 48, 9);
+ cursor.setPosition(pos);
+ QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
+
+ bool deleted = false;
+
+ const auto handler = [&](const Link &) {
+ client()->followSymbol(doc, cursor, nullptr, [&](const Link &) { loop.quit(); }, true,
+ FollowTo::SymbolDef, false);
+ QVERIFY(!deleted);
+ };
+
+ client()->followSymbol(doc, cursor, nullptr, handler, true, FollowTo::SymbolDef, false);
+ QVERIFY(client()->currentFollowSymbolOperation());
+ connect(client()->currentFollowSymbolOperation(), &QObject::destroyed, [&] { deleted = true; });
+ timer.start(10000);
+ loop.exec();
+ QVERIFY(timer.isActive());
+ timer.stop();
+}
ClangdTestLocalReferences::ClangdTestLocalReferences()
{
diff --git a/src/plugins/clangcodemodel/test/clangdtests.h b/src/plugins/clangcodemodel/test/clangdtests.h
index 90f4eca45af..92bf4efe90c 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.h
+++ b/src/plugins/clangcodemodel/test/clangdtests.h
@@ -86,6 +86,7 @@ public:
private slots:
void test_data();
void test();
+ void testFollowSymbolInHandler();
};
class ClangdTestLocalReferences : public ClangdTest