forked from qt-creator/qt-creator
FilePath: Return optional bytearray for file contents
For differentiating between "error" and "empty file". Change-Id: I2c019ceac625e7be3180afa4d47ae3a24df91c1d Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -754,9 +754,10 @@ clang::format::FormatStyle ClangFormatBaseIndenter::styleForFile() const
|
||||
|
||||
clang::format::FormatStyle currentSettingsStyle;
|
||||
currentSettingsStyle.Language = clang::format::FormatStyle::LK_Cpp;
|
||||
const std::error_code error
|
||||
= clang::format::parseConfiguration(filePath.fileContents().toStdString(),
|
||||
¤tSettingsStyle);
|
||||
const std::error_code error = clang::format::parseConfiguration(filePath.fileContents()
|
||||
.value_or(QByteArray())
|
||||
.toStdString(),
|
||||
¤tSettingsStyle);
|
||||
QTC_ASSERT(error.value() == static_cast<int>(clang::format::ParseError::Success),
|
||||
return qtcStyle());
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@ ClangFormatFile::ClangFormatFile(Utils::FilePath filePath)
|
||||
}
|
||||
|
||||
m_style.Language = clang::format::FormatStyle::LK_Cpp;
|
||||
const std::error_code error
|
||||
= clang::format::parseConfiguration(m_filePath.fileContents().toStdString(), &m_style);
|
||||
const std::error_code error = clang::format::parseConfiguration(m_filePath.fileContents()
|
||||
.value_or(QByteArray())
|
||||
.toStdString(),
|
||||
&m_style);
|
||||
if (error.value() != static_cast<int>(clang::format::ParseError::Success)) {
|
||||
resetStyleToQtC();
|
||||
}
|
||||
@@ -124,8 +126,8 @@ CppEditor::CppCodeStyleSettings ClangFormatFile::toCppCodeStyleSettings(
|
||||
|
||||
FormatStyle style;
|
||||
style.Language = clang::format::FormatStyle::LK_Cpp;
|
||||
const std::error_code error = parseConfiguration(m_filePath.fileContents().toStdString(),
|
||||
&style);
|
||||
const std::error_code error
|
||||
= parseConfiguration(m_filePath.fileContents().value_or(QByteArray()).toStdString(), &style);
|
||||
QTC_ASSERT(error.value() == static_cast<int>(ParseError::Success), return settings);
|
||||
|
||||
// Modifier offset should be opposite to indent width in order indentAccessSpecifiers
|
||||
@@ -210,8 +212,8 @@ TextEditor::TabSettings ClangFormatFile::toTabSettings(ProjectExplorer::Project
|
||||
|
||||
FormatStyle style;
|
||||
style.Language = clang::format::FormatStyle::LK_Cpp;
|
||||
const std::error_code error = parseConfiguration(m_filePath.fileContents().toStdString(),
|
||||
&style);
|
||||
const std::error_code error
|
||||
= parseConfiguration(m_filePath.fileContents().value_or(QByteArray()).toStdString(), &style);
|
||||
QTC_ASSERT(error.value() == static_cast<int>(ParseError::Success), return settings);
|
||||
|
||||
settings.m_indentSize = style.IndentWidth;
|
||||
|
||||
Reference in New Issue
Block a user