Skip to content

Commit

Permalink
Sort global System usings before other global usings (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti authored Nov 15, 2023
1 parent a877f7d commit eb56707
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global using System;
global using System.Web;
global using AWord;
global using ZWord;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global using ZWord;
global using AWord;
global using System.Web;
global using System;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 14 additions & 3 deletions Src/CSharpier/SyntaxPrinter/UsingDirectives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private static IEnumerable<List<UsingData>> GroupUsings(
FormattingContext context
)
{
var globalSystemUsings = new List<UsingData>();
var globalUsings = new List<UsingData>();
var globalAliasUsings = new List<UsingData>();
var systemUsings = new List<UsingData>();
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down

0 comments on commit eb56707

Please sign in to comment.