llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Joseph Tay (DynamicProdBreaker) <details> <summary>Changes</summary> Linking @<!-- -->TheShermanTanker who originally requested for this feature here. As https://github.com/llvm/llvm-project/issues/201422 mentions, after the commit that addressed https://github.com/llvm/llvm-project/issues/34447 it became impossible to only sort includes with clang format, as DisableFormat is now hardcoded into the include sorter to disable it when true. Prior discussion to the patch that changed this logic mentioned that there aren't many approaches that are acceptable to allowing only includes to be sorted again, but raised the suggestion that having DisableFormat turn off SortIncludes normally, but letting SortIncludes enable itself again if it is explicitly specified might be acceptable. In light of this, reimplement how DisableFormat disables include sorting by having the enabled flag for SortIncludes be disabled at the moment DisableFormat is set, to allow the actual SortIncludes setting to override it later, which implements the proposed behaviour of DisableFormat turning off SortIncludes when SortIncludes isn't requested, but allowing include sorting to happen when SortIncludes is set explicitly together with DisableFormat. --- Full diff: https://github.com/llvm/llvm-project/pull/208916.diff 1 Files Affected: - (modified) clang/lib/Format/Format.cpp (+3-1) ``````````diff diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 037111d8e9e5d..0b33ca3f33a11 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1355,6 +1355,8 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle); IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment); IO.mapOptional("DisableFormat", Style.DisableFormat); + if (Style.DisableFormat) + Style.SortIncludes.Enabled = false; IO.mapOptional("EmptyLineAfterAccessModifier", Style.EmptyLineAfterAccessModifier); IO.mapOptional("EmptyLineBeforeAccessModifier", @@ -4034,7 +4036,7 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef<tooling::Range> Ranges, StringRef FileName, unsigned *Cursor) { tooling::Replacements Replaces; - if (!Style.SortIncludes.Enabled || Style.DisableFormat) + if (!Style.SortIncludes.Enabled) return Replaces; if (isLikelyXml(Code)) return Replaces; `````````` </details> https://github.com/llvm/llvm-project/pull/208916 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
