forked from qt-creator/qt-creator
ClangFormat: Allow unknown options in .clang-format file
This commit disables syntax checks for the .clang-format file, enabling its use even if it contains errors. Removed pop-up shown when save .clang-format file with errors but left warning when editing it in Code Style Tab. Fixes: QTCREATORBUG-30087 Change-Id: I37a0b1e9d602fcbe4fbbc27f7ab190bcd5c1a1fd Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -961,12 +961,8 @@ const clang::format::FormatStyle &ClangFormatBaseIndenterPrivate::styleForFile()
|
|||||||
return m_cachedStyle.style;
|
return m_cachedStyle.style;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder
|
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = clang::format::getStyle(
|
||||||
= clang::format::getStyle("file",
|
"file", m_fileName->toFSPathString().toStdString(), "none", "", &llvmFileSystemAdapter, true);
|
||||||
m_fileName->toFSPathString().toStdString(),
|
|
||||||
"none",
|
|
||||||
"",
|
|
||||||
&llvmFileSystemAdapter);
|
|
||||||
|
|
||||||
if (styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle())) {
|
if (styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle())) {
|
||||||
addQtcStatementMacros(*styleFromProjectFolder);
|
addQtcStatementMacros(*styleFromProjectFolder);
|
||||||
|
@@ -326,28 +326,8 @@ void ClangFormatConfigWidget::apply()
|
|||||||
if (!m_editorWidget->isEnabled())
|
if (!m_editorWidget->isEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clang::format::FormatStyle currentSettingsStyle;
|
|
||||||
const Utils::expected_str<void> success
|
|
||||||
= parseConfigurationContent(m_editor->document()->contents().toStdString(),
|
|
||||||
currentSettingsStyle);
|
|
||||||
|
|
||||||
auto saveSettings = [this] {
|
|
||||||
QString errorString;
|
QString errorString;
|
||||||
m_editor->document()->save(&errorString, m_config->filePath());
|
m_editor->document()->save(&errorString, m_config->filePath());
|
||||||
};
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
saveSettings();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMessageBox mBox;
|
|
||||||
mBox.setText(Tr::tr("The current ClangFormat (C++ > Code Style > ClangFormat) settings are not "
|
|
||||||
"valid. Are you sure you want to apply them?"));
|
|
||||||
mBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
|
|
||||||
mBox.setDefaultButton(QMessageBox::No);
|
|
||||||
if (mBox.exec() == QMessageBox::Yes)
|
|
||||||
saveSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::CodeStyleEditorWidget *createClangFormatConfigWidget(
|
TextEditor::CodeStyleEditorWidget *createClangFormatConfigWidget(
|
||||||
|
@@ -256,8 +256,8 @@ void ClangFormatGlobalConfigWidget::initCurrentProjectLabel()
|
|||||||
|
|
||||||
bool ClangFormatGlobalConfigWidget::projectClangFormatFileExists()
|
bool ClangFormatGlobalConfigWidget::projectClangFormatFileExists()
|
||||||
{
|
{
|
||||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder
|
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = clang::format::getStyle(
|
||||||
= clang::format::getStyle("file", m_project->projectFilePath().path().toStdString(), "none");
|
"file", m_project->projectFilePath().path().toStdString(), "none", "", nullptr, true);
|
||||||
|
|
||||||
return styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle());
|
return styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle());
|
||||||
}
|
}
|
||||||
|
@@ -394,7 +394,8 @@ Utils::FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreference
|
|||||||
|
|
||||||
static QString s_errorMessage;
|
static QString s_errorMessage;
|
||||||
Utils::expected_str<void> parseConfigurationContent(const std::string &fileContent,
|
Utils::expected_str<void> parseConfigurationContent(const std::string &fileContent,
|
||||||
clang::format::FormatStyle &style)
|
clang::format::FormatStyle &style,
|
||||||
|
bool allowUnknownOptions)
|
||||||
{
|
{
|
||||||
auto diagHandler = [](const llvm::SMDiagnostic &diag, void * /*context*/) {
|
auto diagHandler = [](const llvm::SMDiagnostic &diag, void * /*context*/) {
|
||||||
s_errorMessage = QString::fromStdString(diag.getMessage().str()) + " "
|
s_errorMessage = QString::fromStdString(diag.getMessage().str()) + " "
|
||||||
@@ -403,9 +404,10 @@ Utils::expected_str<void> parseConfigurationContent(const std::string &fileConte
|
|||||||
};
|
};
|
||||||
|
|
||||||
style.Language = clang::format::FormatStyle::LK_Cpp;
|
style.Language = clang::format::FormatStyle::LK_Cpp;
|
||||||
const std::error_code error = parseConfiguration(llvm::MemoryBufferRef(fileContent, "YAML"),
|
const std::error_code error = parseConfiguration(
|
||||||
|
llvm::MemoryBufferRef(fileContent, "YAML"),
|
||||||
&style,
|
&style,
|
||||||
false,
|
allowUnknownOptions,
|
||||||
diagHandler,
|
diagHandler,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
@@ -418,7 +420,7 @@ Utils::expected_str<void> parseConfigurationFile(const Utils::FilePath &filePath
|
|||||||
clang::format::FormatStyle &style)
|
clang::format::FormatStyle &style)
|
||||||
{
|
{
|
||||||
return parseConfigurationContent(filePath.fileContents().value_or(QByteArray()).toStdString(),
|
return parseConfigurationContent(filePath.fileContents().value_or(QByteArray()).toStdString(),
|
||||||
style);
|
style, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ClangFormat
|
} // namespace ClangFormat
|
||||||
|
@@ -49,7 +49,8 @@ clang::format::FormatStyle currentQtStyle(const TextEditor::ICodeStylePreference
|
|||||||
Utils::FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreferences *codeStyle);
|
Utils::FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreferences *codeStyle);
|
||||||
|
|
||||||
Utils::expected_str<void> parseConfigurationContent(const std::string &fileContent,
|
Utils::expected_str<void> parseConfigurationContent(const std::string &fileContent,
|
||||||
clang::format::FormatStyle &style);
|
clang::format::FormatStyle &style,
|
||||||
|
bool allowUnknownOptions = false);
|
||||||
Utils::expected_str<void> parseConfigurationFile(const Utils::FilePath &filePath,
|
Utils::expected_str<void> parseConfigurationFile(const Utils::FilePath &filePath,
|
||||||
clang::format::FormatStyle &style);
|
clang::format::FormatStyle &style);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user