Changeset View
Changeset View
Standalone View
Standalone View
lib/Format/Format.cpp
Context not available. | |||||
".clang-format file located in one of the parent\n" | ".clang-format file located in one of the parent\n" | ||||
"directories of the source file (or current\n" | "directories of the source file (or current\n" | ||||
"directory for stdin).\n" | "directory for stdin).\n" | ||||
"Use -style=file:<configfile> to explicitly specify\n" | |||||
ioeric: Could you also update the comment in include/clang/Format/Format.h? | |||||
"the configuration file.\n" | |||||
"Use -style=\"{key: value, ...}\" to set specific\n" | "Use -style=\"{key: value, ...}\" to set specific\n" | ||||
"parameters, e.g.:\n" | "parameters, e.g.:\n" | ||||
" -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\""; | " -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\""; | ||||
Context not available. | |||||
return Style; | return Style; | ||||
} | } | ||||
// Check for explicit config filename | |||||
if (StyleName.startswith_lower("file:")) { | |||||
SmallString<128> ConfigFile(StyleName.substr(5)); | |||||
auto Status = FS->status(ConfigFile.str()); | |||||
Not Done ReplyInline ActionsI think not finding the config file should be an error. djasper: I think not finding the config file should be an error. | |||||
bool FoundConfigFile = | |||||
Status && (Status->getType() == llvm::sys::fs::file_type::regular_file); | |||||
if (!FoundConfigFile) { | |||||
return make_string_error("Configuration file " + ConfigFile + " not found"); | |||||
} | |||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = | |||||
FS->getBufferForFile(ConfigFile.str()); | |||||
if (std::error_code EC = Text.getError()) | |||||
return make_string_error(EC.message()); | |||||
if (std::error_code ec = parseConfiguration(Text.get()->getBuffer(), &Style)) { | |||||
ioericUnsubmitted Not Done ReplyInline ActionsI think the logic of parsing config files should be similar in the "--style=file" case. Could you pull it into a function to avoid duplication? ioeric: I think the logic of parsing config files should be similar in the "--style=file" case. Could… | |||||
if (ec == ParseError::Unsuitable) { | |||||
return make_string_error("Configuration file " + ConfigFile + | |||||
" does not support " + getLanguageName(Style.Language)); | |||||
} | |||||
return make_string_error("Error reading " + ConfigFile + ": " + ec.message()); | |||||
} | |||||
DEBUG(llvm::dbgs() << "Using configuration file " << ConfigFile << "\n"); | |||||
return Style; | |||||
} | |||||
if (!StyleName.equals_lower("file")) { | if (!StyleName.equals_lower("file")) { | ||||
if (!getPredefinedStyle(StyleName, Style.Language, &Style)) | if (!getPredefinedStyle(StyleName, Style.Language, &Style)) | ||||
return make_string_error("Invalid value for -style"); | return make_string_error("Invalid value for -style"); | ||||
Context not available. |
Could you also update the comment in include/clang/Format/Format.h?