forked from qt-creator/qt-creator
ClangCodeModel: Ignore boolean and pointer literals
... when doing semantic highlighting. The syntax highlighter already handles these. Change-Id: I048e033eda5b72d2e6eafaaccdb66040a00afe6a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -597,11 +597,11 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
|
|||||||
if (node.kind() == "UserDefinedLiteral")
|
if (node.kind() == "UserDefinedLiteral")
|
||||||
return;
|
return;
|
||||||
if (node.kind().endsWith("Literal")) {
|
if (node.kind().endsWith("Literal")) {
|
||||||
const bool isKeyword = node.kind() == "CXXBoolLiteral"
|
if (node.kind() == "CXXBoolLiteral" || node.kind() == "CXXNullPtrLiteral")
|
||||||
|| node.kind() == "CXXNullPtrLiteral";
|
|
||||||
if (!isKeyword && (node.kind().startsWith("String") || node.kind().startsWith("Character")))
|
|
||||||
return;
|
return;
|
||||||
insertResult(node, isKeyword ? C_KEYWORD : C_NUMBER);
|
if (node.kind().startsWith("String") || node.kind().startsWith("Character"))
|
||||||
|
return;
|
||||||
|
insertResult(node, C_NUMBER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node.role() == "type" && node.kind() == "Builtin") {
|
if (node.role() == "type" && node.kind() == "Builtin") {
|
||||||
|
@@ -1259,9 +1259,6 @@ void ClangdTestHighlighting::test_data()
|
|||||||
<< QList<int>{C_FIELD} << 0;
|
<< QList<int>{C_FIELD} << 0;
|
||||||
QTest::newRow("member initialization: member (built-in type)") << 911 << 23 << 911 << 27
|
QTest::newRow("member initialization: member (built-in type)") << 911 << 23 << 911 << 27
|
||||||
<< QList<int>{C_FIELD} << 0;
|
<< 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;
|
|
||||||
QTest::newRow("operator<<") << 934 << 10 << 934 << 14 << QList<int>{C_GLOBAL} << 0;
|
QTest::newRow("operator<<") << 934 << 10 << 934 << 14 << QList<int>{C_GLOBAL} << 0;
|
||||||
QTest::newRow("operator>>") << 936 << 10 << 936 << 13 << QList<int>{C_GLOBAL} << 0;
|
QTest::newRow("operator>>") << 936 << 10 << 936 << 13 << QList<int>{C_GLOBAL} << 0;
|
||||||
QTest::newRow("operator>>") << 936 << 17 << 936 << 18 << QList<int>{C_LOCAL} << 0;
|
QTest::newRow("operator>>") << 936 << 17 << 936 << 18 << QList<int>{C_LOCAL} << 0;
|
||||||
|
@@ -496,6 +496,11 @@ void CppHighlighterTest::test_data()
|
|||||||
QTest::newRow("raw string suffix 3") << 6 << 51 << 6 << 52 << C_KEYWORD;
|
QTest::newRow("raw string suffix 3") << 6 << 51 << 6 << 52 << C_KEYWORD;
|
||||||
QTest::newRow("semicolon") << 6 << 53 << 6 << 53 << C_PUNCTUATION;
|
QTest::newRow("semicolon") << 6 << 53 << 6 << 53 << C_PUNCTUATION;
|
||||||
QTest::newRow("closing brace") << 7 << 1 << 7 << 1 << C_PUNCTUATION;
|
QTest::newRow("closing brace") << 7 << 1 << 7 << 1 << C_PUNCTUATION;
|
||||||
|
QTest::newRow("void") << 9 << 1 << 9 << 4 << C_PRIMITIVE_TYPE;
|
||||||
|
QTest::newRow("bool") << 11 << 5 << 11 << 8 << C_PRIMITIVE_TYPE;
|
||||||
|
QTest::newRow("true") << 11 << 15 << 11 << 18 << C_KEYWORD;
|
||||||
|
QTest::newRow("false") << 12 << 15 << 12 << 19 << C_KEYWORD;
|
||||||
|
QTest::newRow("nullptr") << 13 << 15 << 13 << 21 << C_KEYWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppHighlighterTest::test()
|
void CppHighlighterTest::test()
|
||||||
|
@@ -5,3 +5,10 @@ auto func()
|
|||||||
R"notaprefix!(
|
R"notaprefix!(
|
||||||
barfoobar)" R"(second)" /* comment */ R"(third)";
|
barfoobar)" R"(second)" /* comment */ R"(third)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void keywords()
|
||||||
|
{
|
||||||
|
bool b1 = true;
|
||||||
|
bool b2 = false;
|
||||||
|
void *p = nullptr;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user