From d5ebefd0df78b35a09a8bc6932318eed7b60a9d4 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 15 Sep 2021 16:58:46 +0200 Subject: [PATCH] CppEditor: Highlight strings in the basic highlighter ... in the context of #include and #define. These are not highlighted with clangd. Amends 99790aaa42. Change-Id: Ia86f8606d9c1d72ff9f59909e36bfd0c44704b04 Reviewed-by: David Schulz --- src/plugins/cppeditor/cpphighlighter.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index 86087b0239f..260bf2a9d7c 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -96,6 +96,7 @@ void CppHighlighter::highlightBlock(const QString &text) bool expectPreprocessorKeyword = false; bool onlyHighlightComments = false; + bool blockHasPreprocessorDirective = false; for (int i = 0; i < tokens.size(); ++i) { const Token &tk = tokens.at(i); @@ -153,6 +154,7 @@ void CppHighlighter::highlightBlock(const QString &text) setFormatWithSpaces(text, tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_PREPROCESSOR)); expectPreprocessorKeyword = true; + blockHasPreprocessorDirective = true; } else if (highlightCurrentWordAsPreprocessor && (tk.isKeyword() || tk.is(T_IDENTIFIER)) && isPPKeyword(Utils::midView(text, tk.utf16charsBegin(), tk.utf16chars()))) { setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_PREPROCESSOR)); @@ -180,8 +182,8 @@ void CppHighlighter::highlightBlock(const QString &text) // // and because clangd does not include punctuation in its semantic // // tokens, the semicolon would stay formatted as a string even // // after the semantic highlighter has run. - if (!CppModelManager::instance()->isClangCodeModelActive() - && !highlightRawStringLiteral(text, tk)) { + if ((!CppModelManager::instance()->isClangCodeModelActive() + || blockHasPreprocessorDirective) && !highlightRawStringLiteral(text, tk)) { setFormatWithSpaces(text, tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_STRING)); }