ClangCodeModel: Fix semantic highlighting for __func__

This is a local variable, not a macro.
Also take into account the new upstream support for this (see
https://reviews.llvm.org/D131175), which required us to fix our
assumption that "static" always means "static member".

Change-Id: I69f3c98737571cbd55f9c64c02292426acb6031b
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-08-18 17:48:23 +02:00
parent 4cf75c78ac
commit 1c0ef80861
2 changed files with 21 additions and 15 deletions

View File

@@ -135,7 +135,8 @@ public:
ExtraHighlightingResultsCollector(QFutureInterface<HighlightingResult> &future, ExtraHighlightingResultsCollector(QFutureInterface<HighlightingResult> &future,
HighlightingResults &results, HighlightingResults &results,
const Utils::FilePath &filePath, const ClangdAstNode &ast, const Utils::FilePath &filePath, const ClangdAstNode &ast,
const QTextDocument *doc, const QString &docContent); const QTextDocument *doc, const QString &docContent,
const QVersionNumber &clangdVersion);
void collect(); void collect();
private: private:
@@ -156,6 +157,7 @@ private:
const ClangdAstNode &m_ast; const ClangdAstNode &m_ast;
const QTextDocument * const m_doc; const QTextDocument * const m_doc;
const QString &m_docContent; const QString &m_docContent;
const int m_clangdVersion;
ClangdAstNode::FileStatus m_currentFileStatus = ClangdAstNode::FileStatus::Unknown; ClangdAstNode::FileStatus m_currentFileStatus = ClangdAstNode::FileStatus::Unknown;
}; };
@@ -351,9 +353,12 @@ void doSemanticHighlighting(
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"))) {
if (styles.mainStyle != C_FIELD && styles.mainStyle != C_TEXT) if (styles.mainStyle == C_FUNCTION) {
styles.mixinStyles.push_back(styles.mainStyle);
styles.mainStyle = C_STATIC_MEMBER; styles.mainStyle = C_STATIC_MEMBER;
styles.mixinStyles.push_back(C_FUNCTION);
} else if (styles.mainStyle == C_FIELD) {
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);
@@ -364,7 +369,8 @@ void doSemanticHighlighting(
auto results = QtConcurrent::blockingMapped<HighlightingResults>(tokens, toResult); auto results = QtConcurrent::blockingMapped<HighlightingResults>(tokens, toResult);
const QList<BlockRange> ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents); const QList<BlockRange> ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents);
ExtraHighlightingResultsCollector(future, results, filePath, ast, &doc, docContents).collect(); ExtraHighlightingResultsCollector(future, results, filePath, ast, &doc, docContents,
clangdVersion).collect();
if (!future.isCanceled()) { if (!future.isCanceled()) {
qCInfo(clangdLogHighlight) << "reporting" << results.size() << "highlighting results"; qCInfo(clangdLogHighlight) << "reporting" << results.size() << "highlighting results";
QMetaObject::invokeMethod(textDocument, [textDocument, ifdefedOutBlocks, docRevision] { QMetaObject::invokeMethod(textDocument, [textDocument, ifdefedOutBlocks, docRevision] {
@@ -391,9 +397,9 @@ void doSemanticHighlighting(
ExtraHighlightingResultsCollector::ExtraHighlightingResultsCollector( ExtraHighlightingResultsCollector::ExtraHighlightingResultsCollector(
QFutureInterface<HighlightingResult> &future, HighlightingResults &results, QFutureInterface<HighlightingResult> &future, HighlightingResults &results,
const Utils::FilePath &filePath, const ClangdAstNode &ast, const QTextDocument *doc, const Utils::FilePath &filePath, const ClangdAstNode &ast, const QTextDocument *doc,
const QString &docContent) const QString &docContent, const QVersionNumber &clangdVersion)
: m_future(future), m_results(results), m_filePath(filePath), m_ast(ast), m_doc(doc), : m_future(future), m_results(results), m_filePath(filePath), m_ast(ast), m_doc(doc),
m_docContent(docContent) m_docContent(docContent), m_clangdVersion(clangdVersion.majorVersion())
{ {
} }
@@ -583,8 +589,8 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
} }
const bool isExpression = node.role() == "expression"; const bool isExpression = node.role() == "expression";
if (isExpression && node.kind() == "Predefined") { if (m_clangdVersion < 16 && isExpression && node.kind() == "Predefined") {
insertResult(node, C_MACRO); insertResult(node, C_LOCAL);
return; return;
} }

View File

@@ -1297,12 +1297,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 QTest::newRow("built-in variable 1") << 950 << 21 << 950 << 29
<< QList<int>{C_MACRO} << 0; << QList<int>{C_LOCAL} << 0;
QTest::newRow("built-in define 2") << 951 << 21 << 951 << 33 QTest::newRow("built-in variable 2") << 951 << 21 << 951 << 33
<< QList<int>{C_MACRO} << 0; << QList<int>{C_LOCAL} << 0;
QTest::newRow("built-in define 3") << 952 << 21 << 952 << 40 QTest::newRow("built-in variable 3") << 952 << 21 << 952 << 40
<< QList<int>{C_MACRO} << 0; << QList<int>{C_LOCAL} << 0;
QTest::newRow("deref operator (object)") << 960 << 10 << 960 << 11 << QList<int>{C_LOCAL} << 0; QTest::newRow("deref operator (object)") << 960 << 10 << 960 << 11 << QList<int>{C_LOCAL} << 0;
QTest::newRow("deref operator (member)") << 960 << 12 << 960 << 13 << QList<int>{C_FIELD} << 0; QTest::newRow("deref operator (member)") << 960 << 12 << 960 << 13 << QList<int>{C_FIELD} << 0;
QTest::newRow("nested call") << 979 << 20 << 979 << 21 << QList<int>{C_LOCAL} << 0; QTest::newRow("nested call") << 979 << 20 << 979 << 21 << QList<int>{C_LOCAL} << 0;