From ec7c60cd673e012c0decc7905867dcfe707c730a Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 29 Sep 2021 13:00:36 +0200 Subject: [PATCH] ClangCodeModel: Do not report non-type template parameters as types ... with clangd. Change-Id: I9edad375eacc6c33a833c88da64dc29f79334157 Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 4 +++- src/plugins/clangcodemodel/test/clangdtests.cpp | 10 ++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 6103fada825..7a6c1045ec3 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -2616,7 +2616,9 @@ static void semanticHighlighter(QFutureInterface &future, } else if (token.type == "type") { styles.mainStyle = C_TYPE; } else if (token.type == "typeParameter") { - styles.mainStyle = C_TYPE; + // clangd reports both type and non-type template parameters as type parameters, + // but the latter can be distinguished by the readonly modifier. + styles.mainStyle = token.modifiers.contains("readonly") ? C_PARAMETER : C_TYPE; } if (token.modifiers.contains("declaration")) styles.mixinStyles.push_back(C_DECLARATION); diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index 7829cb0b74d..d0726af4a49 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -909,7 +909,7 @@ void ClangdTestHighlighting::test_data() QTest::newRow("template parameter default argument") << 265 << 41 << 265 << 44 << QList{C_TYPE} << 0; QTest::newRow("template non-type parameter") << 265 << 50 << 265 << 74 - << QList{C_LOCAL, C_DECLARATION} << 0; + << QList{C_PARAMETER, C_DECLARATION} << 0; QTest::newRow("template non-type parameter default argument") << 265 << 77 << 265 << 78 << QList{C_NUMBER} << 0; QTest::newRow("template template parameter") << 265 << 103 << 265 << 128 @@ -935,7 +935,7 @@ void ClangdTestHighlighting::test_data() QTest::newRow("local var declaration of template parameter type") << 268 << 27 << 268 << 57 << QList{C_LOCAL, C_DECLARATION} << 0; QTest::newRow("reference to non-type template parameter") << 269 << 46 << 269 << 70 - << QList{C_LOCAL} << 0; + << QList{C_PARAMETER} << 0; QTest::newRow("local var declaration initialized with non-type template parameter") << 269 << 10 << 269 << 43 << QList{C_LOCAL, C_DECLARATION} << 0; @@ -1331,12 +1331,6 @@ void ClangdTestHighlighting::test() QEXPECT_FAIL("non-final virtual function call via pointer", "clangd < 14 does not send virtual modifier", Continue); } - QEXPECT_FAIL("template non-type parameter", - "FIXME: clangd reports non-type template parameters at \"typeParameter\"", - Continue); - QEXPECT_FAIL("reference to non-type template parameter", - "FIXME: clangd reports non-type template parameters at \"typeParameter\"", - Continue); QEXPECT_FAIL("non-const reference via member function call as output argument (function)", "Without punctuation and comment tokens from clangd, it's not possible " "to highlight entire expressions. But do we really want this? What about nested "