clangbackend: Fix highlighting for #include directives

These were falsely categorized as string literals. No one ever noticed,
because highlighting information for string literals was ignored until
baf25e4cdb.

Change-Id: Ib59fde04359aecb6da3995de1a9febbbf41b12c8
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2020-10-30 12:28:37 +01:00
parent 76ae5780c4
commit e35dfd592f
2 changed files with 7 additions and 2 deletions

View File

@@ -440,7 +440,10 @@ void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion)
m_types.mainHighlightingType = HighlightingType::PreprocessorDefinition;
break;
case CXCursor_InclusionDirective:
m_types.mainHighlightingType = HighlightingType::StringLiteral;
// Included files are sometimes reported as strings and sometimes as
// include directives, depending on various circumstances.
m_types.mainHighlightingType = m_token->spelling() == "include"
? HighlightingType::Preprocessor : HighlightingType::StringLiteral;
break;
case CXCursor_LabelRef:
case CXCursor_LabelStmt:

View File

@@ -928,7 +928,8 @@ TEST_F(TokenProcessor, PreprocessorInclusionDirective)
{
const auto infos = translationUnit.tokenInfosInRange(sourceRange(239, 18));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::StringLiteral));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor));
ASSERT_THAT(infos[2], HasOnlyType(HighlightingType::StringLiteral));
}
TEST_F(TokenProcessor, GotoLabelStatement)
@@ -1080,6 +1081,7 @@ TEST_F(TokenProcessor, PreprocessorInclusionDirectiveWithAngleBrackets )
{
const auto infos = translationUnit.tokenInfosInRange(sourceRange(289, 38));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor));
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral));
}