@@ -3946,20 +3946,23 @@ const char *DefaultFallbackStyle = "LLVM";
3946
3946
3947
3947
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
3948
3948
loadAndParseConfigFile (StringRef ConfigFile, llvm::vfs::FileSystem *FS,
3949
- FormatStyle *Style, bool AllowUnknownOptions) {
3949
+ FormatStyle *Style, bool AllowUnknownOptions,
3950
+ llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr ) {
3950
3951
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
3951
3952
FS->getBufferForFile (ConfigFile.str ());
3952
3953
if (auto EC = Text.getError ())
3953
3954
return EC;
3954
- if (auto EC = parseConfiguration (*Text.get (), Style, AllowUnknownOptions))
3955
+ if (auto EC = parseConfiguration (*Text.get (), Style, AllowUnknownOptions,
3956
+ DiagHandler)) {
3955
3957
return EC;
3958
+ }
3956
3959
return Text;
3957
3960
}
3958
3961
3959
- llvm::Expected<FormatStyle> getStyle (StringRef StyleName, StringRef FileName,
3960
- StringRef FallbackStyleName,
3961
- StringRef Code, llvm::vfs::FileSystem *FS,
3962
- bool AllowUnknownOptions ) {
3962
+ llvm::Expected<FormatStyle>
3963
+ getStyle (StringRef StyleName, StringRef FileName, StringRef FallbackStyleName,
3964
+ StringRef Code, llvm::vfs::FileSystem *FS, bool AllowUnknownOptions ,
3965
+ llvm::SourceMgr::DiagHandlerTy DiagHandler ) {
3963
3966
FormatStyle Style = getLLVMStyle (guessLanguage (FileName, Code));
3964
3967
FormatStyle FallbackStyle = getNoStyle ();
3965
3968
if (!getPredefinedStyle (FallbackStyleName, Style.Language , &FallbackStyle))
@@ -3973,7 +3976,7 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
3973
3976
StringRef Source = " <command-line>" ;
3974
3977
if (std::error_code ec =
3975
3978
parseConfiguration (llvm::MemoryBufferRef (StyleName, Source), &Style,
3976
- AllowUnknownOptions)) {
3979
+ AllowUnknownOptions, DiagHandler )) {
3977
3980
return make_string_error (" Error parsing -style: " + ec.message ());
3978
3981
}
3979
3982
@@ -3993,7 +3996,8 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
3993
3996
StyleName.starts_with_insensitive (" file:" )) {
3994
3997
auto ConfigFile = StyleName.substr (5 );
3995
3998
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
3996
- loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions);
3999
+ loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions,
4000
+ DiagHandler);
3997
4001
if (auto EC = Text.getError ()) {
3998
4002
return make_string_error (" Error reading " + ConfigFile + " : " +
3999
4003
EC.message ());
@@ -4028,12 +4032,13 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
4028
4032
// Reset possible inheritance
4029
4033
Style.InheritsParentConfig = false ;
4030
4034
4031
- auto dropDiagnosticHandler = [](const llvm::SMDiagnostic &, void *) {};
4035
+ auto diagHandlerOrDropHandling =
4036
+ DiagHandler ? DiagHandler : [](llvm::SMDiagnostic const &, void *) {};
4032
4037
4033
4038
auto applyChildFormatTexts = [&](FormatStyle *Style) {
4034
4039
for (const auto &MemBuf : llvm::reverse (ChildFormatTextToApply)) {
4035
4040
auto EC = parseConfiguration (*MemBuf, Style, AllowUnknownOptions,
4036
- dropDiagnosticHandler );
4041
+ diagHandlerOrDropHandling );
4037
4042
// It was already correctly parsed.
4038
4043
assert (!EC);
4039
4044
static_cast <void >(EC);
@@ -4067,7 +4072,8 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
4067
4072
}
4068
4073
4069
4074
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
4070
- loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions);
4075
+ loadAndParseConfigFile (ConfigFile, FS, &Style, AllowUnknownOptions,
4076
+ DiagHandler);
4071
4077
if (auto EC = Text.getError ()) {
4072
4078
if (EC != ParseError::Unsuitable) {
4073
4079
return make_string_error (" Error reading " + ConfigFile + " : " +
0 commit comments