forked from qt-creator/qt-creator
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: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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<BlockRange> cleanupDisabledCode(HighlightingResults &results, const QTextDocument *doc,
|
||||
const QString &docContent)
|
||||
{
|
||||
@@ -2558,9 +2558,14 @@ static QList<BlockRange> cleanupDisabledCode(HighlightingResults &results, const
|
||||
&& !content.startsWith(QLatin1String("#elif"))
|
||||
&& !content.startsWith(QLatin1String("#else"))
|
||||
&& !content.startsWith(QLatin1String("#endif"))) {
|
||||
static const QStringList ppSuffixes{"if", "ifdef", "elif", "else", "endif"};
|
||||
const QList<QStringView> contentList = content.split(' ', Qt::SkipEmptyParts);
|
||||
if (contentList.size() < 2 || contentList.first() != QLatin1String("#")
|
||||
|| !ppSuffixes.contains(contentList.at(1))) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wasIfdefedOut) {
|
||||
// The #if or #else that starts disabled code should not be disabled.
|
||||
|
Reference in New Issue
Block a user