@@ -659,15 +659,26 @@ template <> struct ScalarEnumerationTraits<FormatStyle::ShortLambdaStyle> {
659
659
}
660
660
};
661
661
662
- template <> struct ScalarEnumerationTraits <FormatStyle::SortIncludesOptions> {
663
- static void enumeration (IO &IO, FormatStyle::SortIncludesOptions &Value) {
664
- IO.enumCase (Value, " Never" , FormatStyle::SI_Never);
665
- IO.enumCase (Value, " CaseInsensitive" , FormatStyle::SI_CaseInsensitive);
666
- IO.enumCase (Value, " CaseSensitive" , FormatStyle::SI_CaseSensitive);
662
+ template <> struct MappingTraits <FormatStyle::SortIncludesOptions> {
663
+ static void enumInput (IO &IO, FormatStyle::SortIncludesOptions &Value) {
664
+ IO.enumCase (Value, " Never" , FormatStyle::SortIncludesOptions ({}));
665
+ IO.enumCase (Value, " CaseInsensitive" ,
666
+ FormatStyle::SortIncludesOptions ({/* Enabled=*/ true ,
667
+ /* IgnoreCase=*/ true }));
668
+ IO.enumCase (Value, " CaseSensitive" ,
669
+ FormatStyle::SortIncludesOptions ({/* Enabled=*/ true ,
670
+ /* IgnoreCase=*/ false }));
667
671
668
672
// For backward compatibility.
669
- IO.enumCase (Value, " false" , FormatStyle::SI_Never);
670
- IO.enumCase (Value, " true" , FormatStyle::SI_CaseSensitive);
673
+ IO.enumCase (Value, " false" , FormatStyle::SortIncludesOptions ({}));
674
+ IO.enumCase (Value, " true" ,
675
+ FormatStyle::SortIncludesOptions ({/* Enabled=*/ true ,
676
+ /* IgnoreCase=*/ false }));
677
+ }
678
+
679
+ static void mapping (IO &IO, FormatStyle::SortIncludesOptions &Value) {
680
+ IO.mapOptional (" Enabled" , Value.Enabled );
681
+ IO.mapOptional (" IgnoreCase" , Value.IgnoreCase );
671
682
}
672
683
};
673
684
@@ -1636,7 +1647,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
1636
1647
LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
1637
1648
LLVMStyle.ShortNamespaceLines = 1 ;
1638
1649
LLVMStyle.SkipMacroDefinitionBody = false ;
1639
- LLVMStyle.SortIncludes = FormatStyle::SI_CaseSensitive ;
1650
+ LLVMStyle.SortIncludes = { /* Enabled= */ true , /* IgnoreCase= */ false } ;
1640
1651
LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
1641
1652
LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
1642
1653
LLVMStyle.SpaceAfterCStyleCast = false ;
@@ -1901,7 +1912,6 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
1901
1912
" java" ,
1902
1913
" javax" ,
1903
1914
};
1904
- ChromiumStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
1905
1915
} else if (Language == FormatStyle::LK_JavaScript) {
1906
1916
ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
1907
1917
ChromiumStyle.AllowShortLoopsOnASingleLine = false ;
@@ -2029,7 +2039,7 @@ FormatStyle getClangFormatStyle() {
2029
2039
FormatStyle getNoStyle () {
2030
2040
FormatStyle NoStyle = getLLVMStyle ();
2031
2041
NoStyle.DisableFormat = true ;
2032
- NoStyle.SortIncludes = FormatStyle::SI_Never ;
2042
+ NoStyle.SortIncludes = {} ;
2033
2043
NoStyle.SortUsingDeclarations = FormatStyle::SUD_Never;
2034
2044
return NoStyle;
2035
2045
}
@@ -3220,7 +3230,7 @@ static void sortCppIncludes(const FormatStyle &Style,
3220
3230
SmallVector<unsigned , 16 > Indices =
3221
3231
llvm::to_vector<16 >(llvm::seq<unsigned >(0 , Includes.size ()));
3222
3232
3223
- if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive ) {
3233
+ if (Style.SortIncludes . Enabled && Style. SortIncludes . IgnoreCase ) {
3224
3234
stable_sort (Indices, [&](unsigned LHSI, unsigned RHSI) {
3225
3235
const auto LHSFilenameLower = Includes[LHSI].Filename .lower ();
3226
3236
const auto RHSFilenameLower = Includes[RHSI].Filename .lower ();
@@ -3595,7 +3605,7 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
3595
3605
ArrayRef<tooling::Range> Ranges,
3596
3606
StringRef FileName, unsigned *Cursor) {
3597
3607
tooling::Replacements Replaces;
3598
- if (!Style.SortIncludes || Style.DisableFormat )
3608
+ if (!Style.SortIncludes . Enabled || Style.DisableFormat )
3599
3609
return Replaces;
3600
3610
if (isLikelyXml (Code))
3601
3611
return Replaces;
0 commit comments