ClangCodeModel: Fix highlighting of literals with clangd

Some literals are keywords.

Task-number: QTCREATORBUG-27059
Change-Id: I6315bfd4e4179990e55bc046084fdf0a4e3f9e8e
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-02-15 11:24:02 +01:00
parent a189a74dea
commit 6414f22be7
3 changed files with 15 additions and 3 deletions

View File

@@ -3565,9 +3565,11 @@ void ExtraHighlightingResultsCollector::collectFromNode(const AstNode &node)
if (node.kind().endsWith("Literal")) {
HighlightingResult result;
result.useTextSyles = true;
const bool isStringLike = node.kind().startsWith("String")
|| node.kind().startsWith("Character");
result.textStyles.mainStyle = isStringLike ? C_STRING : C_NUMBER;
const bool isKeyword = node.kind() == "CXXBoolLiteral"
|| node.kind() == "CXXNullPtrLiteral";
const bool isStringLike = !isKeyword && (node.kind().startsWith("String")
|| node.kind().startsWith("Character"));
result.textStyles.mainStyle = isKeyword ? C_KEYWORD : isStringLike ? C_STRING : C_NUMBER;
setResultPosFromRange(result, node.range());
insertResult(result);
return;

View File

@@ -1292,6 +1292,9 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_FIELD} << 0;
QTest::newRow("member initialization: member (built-in type)") << 911 << 23 << 911 << 27
<< QList<int>{C_FIELD} << 0;
QTest::newRow("keywords: true") << 920 << 15 << 920 << 19 << QList<int>{C_KEYWORD} << 0;
QTest::newRow("keywords: false") << 921 << 15 << 921 << 20 << QList<int>{C_KEYWORD} << 0;
QTest::newRow("keywords: nullptr") << 922 << 15 << 922 << 22 << QList<int>{C_KEYWORD} << 0;
}
void ClangdTestHighlighting::test()

View File

@@ -914,3 +914,10 @@ void constructorMemberInitialization()
int m_m2;
};
}
void keywords()
{
bool b1 = true;
bool b2 = false;
void *p = nullptr;
}