From 64fee150ef66a67320b05884efbee658454e9a0d Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 9 Feb 2022 12:08:04 +0100 Subject: [PATCH] ClangCodeModel: Consider whitespace in preprocessor directives ... when highlighting with clangd. That is, treat "# ifdef" the same as "#ifdef". Fixes: QTCREATORBUG-27021 Change-Id: Ic57ed42e09f95611dd85ca3c112e23b52a3f91fc Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 97d0799b862..07e8956f0a0 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -2532,7 +2532,7 @@ private: // clangd reports also the #ifs, #elses and #endifs around the disabled code as disabled, // and not even in a consistent manner. We don't want this, so we have to clean up here. // But note that we require this behavior, as otherwise we would not be able to grey out -// e.g. empty lines after an #fdef, due to the lack of symbols. +// e.g. empty lines after an #ifdef, due to the lack of symbols. static QList cleanupDisabledCode(HighlightingResults &results, const QTextDocument *doc, const QString &docContent) { @@ -2558,8 +2558,13 @@ static QList cleanupDisabledCode(HighlightingResults &results, const && !content.startsWith(QLatin1String("#elif")) && !content.startsWith(QLatin1String("#else")) && !content.startsWith(QLatin1String("#endif"))) { - ++it; - continue; + static const QStringList ppSuffixes{"if", "ifdef", "elif", "else", "endif"}; + const QList contentList = content.split(' ', Qt::SkipEmptyParts); + if (contentList.size() < 2 || contentList.first() != QLatin1String("#") + || !ppSuffixes.contains(contentList.at(1))) { + ++it; + continue; + } } if (!wasIfdefedOut) {