From a1b910724decf22e2d64d7ed78923e6dbfa23f58 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 30 Mar 2022 17:31:26 +0200 Subject: [PATCH] ClangCodeModel: Fix local renamings with clangd This functionality somehow stayed in the proof-of-concept stage, working only for free functions. Fixes: QTCREATORBUG-27249 Change-Id: I840beae66314330ce643e159c596e702a0ec3273 Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 5 ++++- src/plugins/clangcodemodel/test/clangdtests.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 6d343c62a2a..ab08f9cc96f 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -1989,7 +1989,10 @@ void ClangdClient::findLocalUsages(TextDocument *document, const QTextCursor &cu const QList astPath = getAstPath(ast, linkPos); bool isVar = false; for (auto it = astPath.rbegin(); it != astPath.rend(); ++it) { - if (it->role() == "declaration" && it->kind() == "Function") { + if (it->role() == "declaration" + && (it->kind() == "Function" || it->kind() == "CXXMethod" + || it->kind() == "CXXConstructor" || it->kind() == "CXXDestructor" + || it->kind() == "Lambda")) { if (!isVar) break; diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index b672dec291d..0381bd25772 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -434,8 +434,8 @@ void ClangdTestLocalReferences::test_data() /* QList{{40, 7, 3}, {43, 9, 3}} */; QTest::newRow("instantiated template object") << 52 << 19 << QList{{52, 19, 3}, {53, 5, 3}}; - QTest::newRow("variable in template") << 62 << 13 << QList() - /* QList{{62, 13, 3}, {63, 11, 3}} */; + QTest::newRow("variable in template") << 62 << 13 + << QList{{62, 13, 3}, {63, 11, 3}}; QTest::newRow("member in template") << 67 << 7 << QList() /* QList{{64, 16, 3}, {67, 7, 3}} */; QTest::newRow("template type") << 58 << 19 << QList()