Beautifier: Fix format for clang-format's command line style parameter

clang-format uses YAML for its configuration file. Thus the content has
to be properly reformated when used in a single line as command line
argument.

Task-number: QTCREATORBUG-15604
Change-Id: I867caf7ccb1f2f396677e2d0cd5335e5255e03ea
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Lorenz Haas
2016-01-19 20:26:59 +01:00
committed by Lorenz Haas
parent 357e7ee965
commit e4f9d21d28

View File

@@ -49,9 +49,11 @@
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
#include <texteditor/texteditor.h>
#include <utils/algorithm.h>
#include <QAction>
#include <QMenu>
#include <QStringList>
namespace Beautifier {
namespace Internal {
@@ -136,8 +138,14 @@ Command ClangFormat::command(int offset, int length) const
if (m_settings->usePredefinedStyle()) {
command.addOption(QLatin1String("-style=") + m_settings->predefinedStyle());
} else {
command.addOption(QLatin1String("-style={")
+ m_settings->style(m_settings->customStyle()).remove(QLatin1Char('\n'))
// 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('}'));
}