forked from qt-creator/qt-creator
ClangCodeModel: Fix clangd highlighting of string literals
... passed to macros defined in a different file.
This amends e77e57420a. Contrary to our expectation, it is possible that
AST nodes that are marked as belonging (only) to a header file can
contain child nodes that belong to the main file.
Fixes: QTCREATORBUG-26553
Change-Id: I4d1d877d8e1e2dcf7d81b63aa98e1149b5514e3f
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3640,12 +3640,11 @@ void ExtraHighlightingResultsCollector::visitNode(const AstNode &node)
|
|||||||
if (m_future.isCanceled())
|
if (m_future.isCanceled())
|
||||||
return;
|
return;
|
||||||
switch (node.fileStatus(m_filePath)) {
|
switch (node.fileStatus(m_filePath)) {
|
||||||
case AstNode::FileStatus::Foreign:
|
|
||||||
return;
|
|
||||||
case AstNode::FileStatus::Ours:
|
case AstNode::FileStatus::Ours:
|
||||||
case AstNode::FileStatus::Unknown:
|
case AstNode::FileStatus::Unknown:
|
||||||
collectFromNode(node);
|
collectFromNode(node);
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
case AstNode::FileStatus::Foreign:
|
||||||
case ClangCodeModel::Internal::AstNode::FileStatus::Mixed: {
|
case ClangCodeModel::Internal::AstNode::FileStatus::Mixed: {
|
||||||
const auto children = node.children();
|
const auto children = node.children();
|
||||||
if (!children)
|
if (!children)
|
||||||
|
|||||||
@@ -1252,6 +1252,10 @@ void ClangdTestHighlighting::test_data()
|
|||||||
QTest::newRow("simple return") << 841 << 12 << 841 << 15 << QList<int>{C_LOCAL} << 0;
|
QTest::newRow("simple return") << 841 << 12 << 841 << 15 << QList<int>{C_LOCAL} << 0;
|
||||||
QTest::newRow("lambda parameter") << 847 << 49 << 847 << 52
|
QTest::newRow("lambda parameter") << 847 << 49 << 847 << 52
|
||||||
<< QList<int>{C_PARAMETER, C_DECLARATION} << 0;
|
<< QList<int>{C_PARAMETER, C_DECLARATION} << 0;
|
||||||
|
QTest::newRow("string literal passed to macro from same file") << 853 << 32 << 853 << 38
|
||||||
|
<< QList<int>{C_STRING} << 0;
|
||||||
|
QTest::newRow("string literal passed to macro from header file") << 854 << 32 << 854 << 38
|
||||||
|
<< QList<int>{C_STRING} << 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdTestHighlighting::test()
|
void ClangdTestHighlighting::test()
|
||||||
|
|||||||
@@ -846,3 +846,10 @@ void testConstRefAutoLambdaArgs()
|
|||||||
{
|
{
|
||||||
useContainer(FooPtrVector(), [](const auto &arg) {});
|
useContainer(FooPtrVector(), [](const auto &arg) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define USE_STRING(s) (s)
|
||||||
|
void useString()
|
||||||
|
{
|
||||||
|
const char *s = USE_STRING("TEXT");
|
||||||
|
s = USE_STRING_FROM_HEADER("TEXT");
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
#define USE_STRING_FROM_HEADER(s) (s)
|
||||||
|
|||||||
Reference in New Issue
Block a user