ClangCodeModel: Properly highlight built-in defines

These are not reported as semantic tokens, so consult the AST

Task-number: QTCREATORBUG-27111
Change-Id: I38efcfbdc3197173a50033a74a1bc631eaa8d2c1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2022-02-25 10:15:42 +01:00
parent 4d10a2df36
commit 64a1bf6c43
3 changed files with 22 additions and 1 deletions

View File

@@ -3598,8 +3598,16 @@ void ExtraHighlightingResultsCollector::collectFromNode(const AstNode &node)
} }
const bool isExpression = node.role() == "expression"; const bool isExpression = node.role() == "expression";
const bool isDeclaration = node.role() == "declaration"; if (isExpression && node.kind() == "Predefined") {
HighlightingResult result;
result.useTextSyles = true;
result.textStyles.mainStyle = C_PREPROCESSOR;
setResultPosFromRange(result, node.range());
insertResult(result);
return;
}
const bool isDeclaration = node.role() == "declaration";
const int nodeStartPos = posForNodeStart(node); const int nodeStartPos = posForNodeStart(node);
const int nodeEndPos = posForNodeEnd(node); const int nodeEndPos = posForNodeEnd(node);
const QList<AstNode> children = node.children().value_or(QList<AstNode>()); const QList<AstNode> children = node.children().value_or(QList<AstNode>());

View File

@@ -1302,6 +1302,12 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_FIELD} << 0; << QList<int>{C_FIELD} << 0;
QTest::newRow("output arg") << 945 << 20 << 945 << 23 QTest::newRow("output arg") << 945 << 20 << 945 << 23
<< QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0; << QList<int>{C_LOCAL, C_OUTPUT_ARGUMENT} << 0;
QTest::newRow("built-in define 1") << 950 << 21 << 950 << 29
<< QList<int>{C_PREPROCESSOR} << 0;
QTest::newRow("built-in define 2") << 951 << 21 << 951 << 33
<< QList<int>{C_PREPROCESSOR} << 0;
QTest::newRow("built-in define 3") << 952 << 21 << 952 << 40
<< QList<int>{C_PREPROCESSOR} << 0;
} }
void ClangdTestHighlighting::test() void ClangdTestHighlighting::test()

View File

@@ -944,3 +944,10 @@ void inputsAndOutputsFromObject(const WithVector &s)
std::vector<int> out; std::vector<int> out;
transform(s.v, out, [] {}); transform(s.v, out, [] {});
} }
void builtinDefines()
{
const auto f1 = __func__;
const auto f2 = __FUNCTION__;
const auto f3 = __PRETTY_FUNCTION__;
}