forked from qt-creator/qt-creator
Beautifier: Fix clang-format's custom style handling
Instead of dealing with clang-format's YAML format use proper command line parameters. Task-number: QTCREATORBUG-15604 Change-Id: Ie0b22aff105c8d208d30e2e945b0036b0b8606c1 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -132,23 +132,19 @@ Command ClangFormat::command(int offset, int length) const
|
||||
|
||||
if (m_settings->usePredefinedStyle()) {
|
||||
command.addOption(QLatin1String("-style=") + m_settings->predefinedStyle());
|
||||
command.addOption(QLatin1String("-assume-filename=%filename"));
|
||||
} else {
|
||||
// The clang-format option file is YAML
|
||||
const QStringList lines = m_settings->style(m_settings->customStyle())
|
||||
.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
||||
const QStringList options = Utils::filtered(lines, [](const QString &s) -> bool {
|
||||
const QString option = s.trimmed();
|
||||
return !(option.startsWith(QLatin1Char('#')) || option == QLatin1String("---"));
|
||||
});
|
||||
command.addOption(QLatin1String("-style={") + options.join(QLatin1String(", "))
|
||||
+ QLatin1Char('}'));
|
||||
command.addOption(QLatin1String("-style=file"));
|
||||
const QString path =
|
||||
QFileInfo(m_settings->styleFileName(m_settings->customStyle())).absolutePath();
|
||||
command.addOption(QLatin1String("-assume-filename=") + path + QDir::separator()
|
||||
+ QLatin1String("%filename"));
|
||||
}
|
||||
|
||||
if (offset != -1) {
|
||||
command.addOption(QLatin1String("-offset=") + QString::number(offset));
|
||||
command.addOption(QLatin1String("-length=") + QString::number(length));
|
||||
}
|
||||
command.addOption(QLatin1String("-assume-filename=%file"));
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user