diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsGlobalSystemToTop.expected.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsGlobalSystemToTop.expected.test new file mode 100644 index 000000000..6ece74ca5 --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsGlobalSystemToTop.expected.test @@ -0,0 +1,4 @@ +global using System; +global using System.Web; +global using AWord; +global using ZWord; diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsGlobalSystemToTop.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsGlobalSystemToTop.test new file mode 100644 index 000000000..653fdeff5 --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsGlobalSystemToTop.test @@ -0,0 +1,4 @@ +global using ZWord; +global using AWord; +global using System.Web; +global using System; diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsMixedCorrectly.expected.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsMixedCorrectly.expected.test new file mode 100644 index 000000000..2ce2ff17b --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsMixedCorrectly.expected.test @@ -0,0 +1,8 @@ +global using System; +global using System.Web; +global using AWord; +global using ZWord; +using System; +using System.Web; +using AWord; +using ZWord; diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsMixedCorrectly.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsMixedCorrectly.test new file mode 100644 index 000000000..622e2a3be --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/UsingDirectives_SortsMixedCorrectly.test @@ -0,0 +1,8 @@ +global using ZWord; +using ZWord; +global using AWord; +using AWord; +global using System.Web; +using System.Web; +global using System; +using System; diff --git a/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs b/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs index 1d2f7e5f1..2406b53a3 100644 --- a/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs +++ b/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs @@ -134,6 +134,7 @@ private static IEnumerable> GroupUsings( FormattingContext context ) { + var globalSystemUsings = new List(); var globalUsings = new List(); var globalAliasUsings = new List(); var systemUsings = new List(); @@ -187,9 +188,18 @@ FormattingContext context if (usingDirective.GlobalKeyword.RawSyntaxKind() != SyntaxKind.None) { - (usingDirective.Alias is not null ? globalAliasUsings : globalUsings).Add( - usingData - ); + if (usingDirective.Alias is not null) + { + globalAliasUsings.Add(usingData); + } + else if (usingDirective.Name is not null && IsSystemName(usingDirective.Name)) + { + globalSystemUsings.Add(usingData); + } + else + { + globalUsings.Add(usingData); + } } else if (usingDirective.StaticKeyword.RawSyntaxKind() != SyntaxKind.None) { @@ -214,6 +224,7 @@ FormattingContext context } } + yield return globalSystemUsings.OrderBy(o => o.Using, Comparer).ToList(); yield return globalUsings.OrderBy(o => o.Using, Comparer).ToList(); yield return globalAliasUsings.OrderBy(o => o.Using, Comparer).ToList(); yield return systemUsings.OrderBy(o => o.Using, Comparer).ToList();