Commit e6bf3990 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Clang: Stop highlighting keywords in preprocessor directives



Task-number: QTCREATORBUG-15516
Change-Id: I30046ae7c1a73144985639800227012bf5a4e357
Reviewed-by: Marco Bubke's avatarMarco Bubke <marco.bubke@qt.io>
parent 7ffdcd10
......@@ -383,8 +383,15 @@ HighlightingType HighlightingMark::punctuationKind(const Cursor &cursor)
}
static HighlightingType highlightingTypeForKeyword(CXTranslationUnit cxTranslationUnit,
CXToken *cxToken)
CXToken *cxToken,
const Cursor &cursor)
{
switch (cursor.kind()) {
case CXCursor_PreprocessingDirective: return HighlightingType::Preprocessor;
case CXCursor_InclusionDirective: return HighlightingType::StringLiteral;
default: break;
}
const ClangString spelling = clang_getTokenSpelling(cxTranslationUnit, *cxToken);
const char *c = spelling.cString();
if (std::strcmp(c, "bool") == 0
......@@ -414,7 +421,7 @@ void HighlightingMark::collectKinds(CXTranslationUnit cxTranslationUnit,
types = HighlightingTypes();
switch (cxTokenKind) {
case CXToken_Keyword: types.mainHighlightingType = highlightingTypeForKeyword(cxTranslationUnit, cxToken); break;
case CXToken_Keyword: types.mainHighlightingType = highlightingTypeForKeyword(cxTranslationUnit, cxToken, originalCursor); break;
case CXToken_Punctuation: types.mainHighlightingType = punctuationKind(cursor); break;
case CXToken_Identifier: identifierKind(cursor, Recursion::FirstPass); break;
case CXToken_Comment: types.mainHighlightingType = HighlightingType::Comment; break;
......
......@@ -554,3 +554,8 @@ template<class T> class Coo<T*>;
namespace N { void goo(); }
using N::goo;
#if 1
#endif
#include <new>
......@@ -1121,6 +1121,21 @@ TEST_F(HighlightingMarks, UsingFunction)
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Function));
}
TEST_F(HighlightingMarks, PreprocessorIfDirective)
{
const auto infos = translationUnit.highlightingMarksInRange(sourceRange(558, 6));
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Preprocessor));
}
TEST_F(HighlightingMarks, PreprocessorInclusionDirectiveWithKeyword)
{
const auto infos = translationUnit.highlightingMarksInRange(sourceRange(561, 15));
infos.toHighlightingMarksContainers();
ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::StringLiteral));
}
Data *HighlightingMarks::d;
void HighlightingMarks::SetUpTestCase()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment