diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-06-21 17:44:14 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-11-08 14:21:25 +0000 |
commit | f93c316b73a6564bc6ccac94d0c89b686d98362a (patch) | |
tree | 1888b5f8c53569a0bc5ce4e1d26aec9883543de4 | |
parent | bb11788a0ac868d9f89970a202df52b07c32c190 (diff) |
ClangCodeModel: Adapt to new upstream feature
See https://reviews.llvm.org/D130015.
Change-Id: I2c2590265f2d7a2c2b5e966b0dc65ceff6b1b3e6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/clangcodemodel/clangdsemantichighlighting.cpp | 14 | ||||
-rw-r--r-- | src/plugins/clangcodemodel/test/clangdtests.cpp | 16 |
2 files changed, 10 insertions, 20 deletions
diff --git a/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp b/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp index fbddb0b605..322a21058f 100644 --- a/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp +++ b/src/plugins/clangcodemodel/clangdsemantichighlighting.cpp @@ -164,9 +164,15 @@ void doSemanticHighlighting( const Position endPos = startPos.withOffset(token.length, &doc); return Range(startPos, endPos); }; - const auto isOutputParameter = [&ast, &tokenRange](const ExpandedSemanticToken &token) { + const int clangdMajorVersion = clangdVersion.majorVersion(); + const auto isOutputParameter = [&ast, &tokenRange, clangdMajorVersion] + (const ExpandedSemanticToken &token) { if (token.modifiers.contains(QLatin1String("usedAsMutableReference"))) return true; + if (token.modifiers.contains(QLatin1String("usedAsMutablePointer"))) + return true; + if (clangdMajorVersion >= 16) + return false; if (token.type != "variable" && token.type != "property" && token.type != "parameter") return false; const Range range = tokenRange(token); @@ -260,7 +266,7 @@ void doSemanticHighlighting( }; const std::function<HighlightingResult(const ExpandedSemanticToken &)> toResult - = [&ast, &isOutputParameter, &tokenRange, ver = clangdVersion.majorVersion()] + = [&ast, &isOutputParameter, &tokenRange, clangdMajorVersion] (const ExpandedSemanticToken &token) { TextStyles styles; if (token.type == "variable") { @@ -277,7 +283,7 @@ void doSemanticHighlighting( ? C_VIRTUAL_METHOD : C_FUNCTION; if (token.modifiers.contains("definition")) { styles.mixinStyles.push_back(C_FUNCTION_DEFINITION); - } else if (ver < 16 && ast.isValid()) { + } else if (clangdMajorVersion < 16 && ast.isValid()) { const ClangdAstPath path = getAstPath(ast, tokenRange(token)); if (path.length() > 1) { const ClangdAstNode declNode = path.at(path.length() - 2); @@ -291,7 +297,7 @@ void doSemanticHighlighting( styles.mainStyle = C_TYPE; if (token.modifiers.contains("constructorOrDestructor")) { styles.mainStyle = C_FUNCTION; - } else if (ver < 16 && ast.isValid()) { + } else if (clangdMajorVersion < 16 && ast.isValid()) { const ClangdAstPath path = getAstPath(ast, tokenRange(token)); if (!path.isEmpty()) { if (path.last().kind() == "CXXConstructor") { diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index f00e675651..96a6383aba 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -1012,12 +1012,6 @@ void ClangdTestHighlighting::test_data() << QList<int>{C_LOCAL} << 0; QTest::newRow("const pointer argument") << 491 << 26 << 491 << 27 << QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0; - QTest::newRow("non-const reference via member function call as output argument (object)") - << 580 << 29 << 580 << 30 - << QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0; - QTest::newRow("non-const reference via member function call as output argument (function)") - << 580 << 31 << 580 << 37 - << QList<int>{C_FUNCTION, C_OUTPUT_ARGUMENT} << 0; QTest::newRow("value argument") << 501 << 57 << 501 << 58 << QList<int>{C_LOCAL} << 0; QTest::newRow("non-const ref argument as second arg") << 501 << 61 << 501 << 62 @@ -1026,8 +1020,6 @@ void ClangdTestHighlighting::test_data() << QList<int>{C_PARAMETER, C_OUTPUT_ARGUMENT} << 0; QTest::newRow("non-const pointer argument expression") << 513 << 30 << 513 << 31 << QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0; - QTest::newRow("non-const ref argument from qualified member (object)") << 525 << 31 << 525 << 39 - << QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0; QTest::newRow("non-const ref argument from qualified member (member)") << 525 << 40 << 525 << 46 << QList<int>{C_FIELD, C_OUTPUT_ARGUMENT} << 0; QTest::newRow("non-const ref argument to constructor") << 540 << 47 << 540 << 55 @@ -1394,14 +1386,6 @@ void ClangdTestHighlighting::test() actualStyles << s; } - QEXPECT_FAIL("non-const reference via member function call as output argument (object)", - "See below", 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 " - "calls where the inner arguments are const?", - Continue); - QCOMPARE(actualStyles, expectedStyles); QCOMPARE(result.kind, expectedKind); } |