ClangCodeModel: Properly highlight static data members

C_STATIC_MEMBER is mutually exclusive with C_FIELD, so it must not be a
mix-in style.

Task-number: QTCREATORBUG-27111
Change-Id: If9e5f44790f1b7d124f4b2e9859f8c2223c0c424
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-03-01 11:10:54 +01:00
parent 1778008067
commit f8cec0a85a
2 changed files with 11 additions and 4 deletions

View File

@@ -2821,8 +2821,11 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
} }
if (token.modifiers.contains(QLatin1String("declaration"))) if (token.modifiers.contains(QLatin1String("declaration")))
styles.mixinStyles.push_back(C_DECLARATION); styles.mixinStyles.push_back(C_DECLARATION);
if (token.modifiers.contains(QLatin1String("static"))) if (token.modifiers.contains(QLatin1String("static"))) {
styles.mixinStyles.push_back(C_STATIC_MEMBER); if (styles.mainStyle != C_FIELD && styles.mainStyle != C_TEXT)
styles.mixinStyles.push_back(styles.mainStyle);
styles.mainStyle = C_STATIC_MEMBER;
}
if (isOutputParameter(token)) if (isOutputParameter(token))
styles.mixinStyles.push_back(C_OUTPUT_ARGUMENT); styles.mixinStyles.push_back(C_OUTPUT_ARGUMENT);
qCDebug(clangdLogHighlight) << "adding highlighting result" qCDebug(clangdLogHighlight) << "adding highlighting result"

View File

@@ -998,6 +998,10 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen); << QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen);
QTest::newRow("class template instantiation (closing angle bracket)") << 384 << 22 << 384 << 23 QTest::newRow("class template instantiation (closing angle bracket)") << 384 << 22 << 384 << 23
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketClose); << QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketClose);
QTest::newRow("static member function decl") << 395 << 17 << 395 << 30
<< QList<int>{C_STATIC_MEMBER, C_DECLARATION, C_FUNCTION} << 0;
QTest::newRow("static member function call") << 400 << 17 << 400 << 30
<< QList<int>{C_STATIC_MEMBER, C_FUNCTION} << 0;
QTest::newRow("namespace in declaration") << 413 << 4 << 413 << 26 QTest::newRow("namespace in declaration") << 413 << 4 << 413 << 26
<< QList<int>{C_NAMESPACE} << 0; << QList<int>{C_NAMESPACE} << 0;
QTest::newRow("namespaced class in declaration") << 413 << 28 << 413 << 41 QTest::newRow("namespaced class in declaration") << 413 << 28 << 413 << 41
@@ -1122,9 +1126,9 @@ void ClangdTestHighlighting::test_data()
QTest::newRow("local variable captured by lambda") << 442 << 24 << 442 << 27 QTest::newRow("local variable captured by lambda") << 442 << 24 << 442 << 27
<< QList<int>{C_LOCAL} << 0; << QList<int>{C_LOCAL} << 0;
QTest::newRow("static protected member") << 693 << 16 << 693 << 30 QTest::newRow("static protected member") << 693 << 16 << 693 << 30
<< QList<int>{C_FIELD, C_DECLARATION, C_STATIC_MEMBER} << 0; << QList<int>{C_STATIC_MEMBER, C_DECLARATION} << 0;
QTest::newRow("static private member") << 696 << 16 << 696 << 28 QTest::newRow("static private member") << 696 << 16 << 696 << 28
<< QList<int>{C_FIELD, C_DECLARATION, C_STATIC_MEMBER} << 0; << QList<int>{C_STATIC_MEMBER, C_DECLARATION} << 0;
QTest::newRow("alias template declaration (opening angle bracket)") << 700 << 10 << 700 << 11 QTest::newRow("alias template declaration (opening angle bracket)") << 700 << 10 << 700 << 11
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen); << QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen);
QTest::newRow("alias template declaration (closing angle bracket)") << 700 << 16 << 700 << 17 QTest::newRow("alias template declaration (closing angle bracket)") << 700 << 16 << 700 << 17