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;
|
||||
}
|
||||
|
||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder
|
||||
= clang::format::getStyle("file",
|
||||
m_fileName->toFSPathString().toStdString(),
|
||||
"none",
|
||||
"",
|
||||
&llvmFileSystemAdapter);
|
||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = clang::format::getStyle(
|
||||
"file", m_fileName->toFSPathString().toStdString(), "none", "", &llvmFileSystemAdapter, true);
|
||||
|
||||
if (styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle())) {
|
||||
addQtcStatementMacros(*styleFromProjectFolder);
|
||||
|
@@ -326,28 +326,8 @@ void ClangFormatConfigWidget::apply()
|
||||
if (!m_editorWidget->isEnabled())
|
||||
return;
|
||||
|
||||
clang::format::FormatStyle currentSettingsStyle;
|
||||
const Utils::expected_str<void> success
|
||||
= parseConfigurationContent(m_editor->document()->contents().toStdString(),
|
||||
currentSettingsStyle);
|
||||
|
||||
auto saveSettings = [this] {
|
||||
QString errorString;
|
||||
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();
|
||||
QString errorString;
|
||||
m_editor->document()->save(&errorString, m_config->filePath());
|
||||
}
|
||||
|
||||
TextEditor::CodeStyleEditorWidget *createClangFormatConfigWidget(
|
||||
|
@@ -256,8 +256,8 @@ void ClangFormatGlobalConfigWidget::initCurrentProjectLabel()
|
||||
|
||||
bool ClangFormatGlobalConfigWidget::projectClangFormatFileExists()
|
||||
{
|
||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder
|
||||
= clang::format::getStyle("file", m_project->projectFilePath().path().toStdString(), "none");
|
||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = clang::format::getStyle(
|
||||
"file", m_project->projectFilePath().path().toStdString(), "none", "", nullptr, true);
|
||||
|
||||
return styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle());
|
||||
}
|
||||
|
@@ -394,7 +394,8 @@ Utils::FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreference
|
||||
|
||||
static QString s_errorMessage;
|
||||
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*/) {
|
||||
s_errorMessage = QString::fromStdString(diag.getMessage().str()) + " "
|
||||
@@ -403,11 +404,12 @@ Utils::expected_str<void> parseConfigurationContent(const std::string &fileConte
|
||||
};
|
||||
|
||||
style.Language = clang::format::FormatStyle::LK_Cpp;
|
||||
const std::error_code error = parseConfiguration(llvm::MemoryBufferRef(fileContent, "YAML"),
|
||||
&style,
|
||||
false,
|
||||
diagHandler,
|
||||
nullptr);
|
||||
const std::error_code error = parseConfiguration(
|
||||
llvm::MemoryBufferRef(fileContent, "YAML"),
|
||||
&style,
|
||||
allowUnknownOptions,
|
||||
diagHandler,
|
||||
nullptr);
|
||||
|
||||
if (error)
|
||||
return make_unexpected(s_errorMessage);
|
||||
@@ -418,7 +420,7 @@ Utils::expected_str<void> parseConfigurationFile(const Utils::FilePath &filePath
|
||||
clang::format::FormatStyle &style)
|
||||
{
|
||||
return parseConfigurationContent(filePath.fileContents().value_or(QByteArray()).toStdString(),
|
||||
style);
|
||||
style, true);
|
||||
}
|
||||
|
||||
} // namespace ClangFormat
|
||||
|
@@ -49,7 +49,8 @@ clang::format::FormatStyle currentQtStyle(const TextEditor::ICodeStylePreference
|
||||
Utils::FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreferences *codeStyle);
|
||||
|
||||
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,
|
||||
clang::format::FormatStyle &style);
|
||||
|
||||
|
Reference in New Issue
Block a user