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 <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-09-15 16:58:46 +02:00
parent 44912450f4
commit d5ebefd0df

View File

@@ -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));
}