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