summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Haas <lykurg@gmail.com>2016-01-19 20:26:59 +0100
committerLorenz Haas <lorenz.haas@histomatics.de>2016-02-24 17:16:07 +0000
commite4f9d21d2879fcbf68331de8099e00aca08649e4 (patch)
tree085a826791d4c73da9bbc80438a5e6c060d2438d
parent357e7ee96504173f9d5afffe6081fed1f6bf063e (diff)
downloadqt-creator-e4f9d21d2879fcbf68331de8099e00aca08649e4.tar.gz
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>
-rw-r--r--src/plugins/beautifier/clangformat/clangformat.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/plugins/beautifier/clangformat/clangformat.cpp b/src/plugins/beautifier/clangformat/clangformat.cpp
index 79eee4a135..17bab746cc 100644
--- a/src/plugins/beautifier/clangformat/clangformat.cpp
+++ b/src/plugins/beautifier/clangformat/clangformat.cpp
@@ -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('}'));
}