@@ -665,21 +665,25 @@ template <> struct MappingTraits<FormatStyle::SortIncludesOptions> {
665665 IO.enumCase (Value, " Never" , FormatStyle::SortIncludesOptions ({}));
666666 IO.enumCase (Value, " CaseInsensitive" ,
667667 FormatStyle::SortIncludesOptions ({/* Enabled=*/ true ,
668- /* IgnoreCase=*/ true }));
668+ /* IgnoreCase=*/ true ,
669+ /* IgnoreExtension=*/ false }));
669670 IO.enumCase (Value, " CaseSensitive" ,
670671 FormatStyle::SortIncludesOptions ({/* Enabled=*/ true ,
671- /* IgnoreCase=*/ false }));
672+ /* IgnoreCase=*/ false ,
673+ /* IgnoreExtension=*/ false }));
672674
673675 // For backward compatibility.
674676 IO.enumCase (Value, " false" , FormatStyle::SortIncludesOptions ({}));
675677 IO.enumCase (Value, " true" ,
676678 FormatStyle::SortIncludesOptions ({/* Enabled=*/ true ,
677- /* IgnoreCase=*/ false }));
679+ /* IgnoreCase=*/ false ,
680+ /* IgnoreExtension=*/ false }));
678681 }
679682
680683 static void mapping (IO &IO, FormatStyle::SortIncludesOptions &Value) {
681684 IO.mapOptional (" Enabled" , Value.Enabled );
682685 IO.mapOptional (" IgnoreCase" , Value.IgnoreCase );
686+ IO.mapOptional (" IgnoreExtension" , Value.IgnoreExtension );
683687 }
684688};
685689
@@ -1650,7 +1654,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
16501654 LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
16511655 LLVMStyle.ShortNamespaceLines = 1 ;
16521656 LLVMStyle.SkipMacroDefinitionBody = false ;
1653- LLVMStyle.SortIncludes = {/* Enabled=*/ true , /* IgnoreCase=*/ false };
1657+ LLVMStyle.SortIncludes = {/* Enabled=*/ true , /* IgnoreCase=*/ false ,
1658+ /* IgnoreExtension=*/ false };
16541659 LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
16551660 LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
16561661 LLVMStyle.SpaceAfterCStyleCast = false ;
@@ -3239,19 +3244,27 @@ static void sortCppIncludes(const FormatStyle &Style,
32393244 SmallVector<unsigned , 16 > Indices =
32403245 llvm::to_vector<16 >(llvm::seq<unsigned >(0 , Includes.size ()));
32413246
3242- if (Style.SortIncludes .Enabled && Style. SortIncludes . IgnoreCase ) {
3247+ if (Style.SortIncludes .Enabled ) {
32433248 stable_sort (Indices, [&](unsigned LHSI, unsigned RHSI) {
3244- const auto LHSFilenameLower = Includes[LHSI].Filename .lower ();
3245- const auto RHSFilenameLower = Includes[RHSI].Filename .lower ();
3246- return std::tie (Includes[LHSI].Priority , LHSFilenameLower,
3247- Includes[LHSI].Filename ) <
3248- std::tie (Includes[RHSI].Priority , RHSFilenameLower,
3249- Includes[RHSI].Filename );
3250- });
3251- } else {
3252- stable_sort (Indices, [&](unsigned LHSI, unsigned RHSI) {
3253- return std::tie (Includes[LHSI].Priority , Includes[LHSI].Filename ) <
3254- std::tie (Includes[RHSI].Priority , Includes[RHSI].Filename );
3249+ SmallString<128 > LHSStem, RHSStem;
3250+ if (Style.SortIncludes .IgnoreExtension ) {
3251+ LHSStem = Includes[LHSI].Filename ;
3252+ RHSStem = Includes[RHSI].Filename ;
3253+ llvm::sys::path::replace_extension (LHSStem, " " );
3254+ llvm::sys::path::replace_extension (RHSStem, " " );
3255+ }
3256+ std::string LHSStemLower, RHSStemLower;
3257+ std::string LHSFilenameLower, RHSFilenameLower;
3258+ if (Style.SortIncludes .IgnoreCase ) {
3259+ LHSStemLower = LHSStem.str ().lower ();
3260+ RHSStemLower = RHSStem.str ().lower ();
3261+ LHSFilenameLower = Includes[LHSI].Filename .lower ();
3262+ RHSFilenameLower = Includes[RHSI].Filename .lower ();
3263+ }
3264+ return std::tie (Includes[LHSI].Priority , LHSStemLower, LHSStem,
3265+ LHSFilenameLower, Includes[LHSI].Filename ) <
3266+ std::tie (Includes[RHSI].Priority , RHSStemLower, RHSStem,
3267+ RHSFilenameLower, Includes[RHSI].Filename );
32553268 });
32563269 }
32573270
0 commit comments