Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb56707

Browse files
authored
Sort global System usings before other global usings (#1004)
1 parent a877f7d commit eb56707

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global using System;
2+
global using System.Web;
3+
global using AWord;
4+
global using ZWord;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global using ZWord;
2+
global using AWord;
3+
global using System.Web;
4+
global using System;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global using System;
2+
global using System.Web;
3+
global using AWord;
4+
global using ZWord;
5+
using System;
6+
using System.Web;
7+
using AWord;
8+
using ZWord;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global using ZWord;
2+
using ZWord;
3+
global using AWord;
4+
using AWord;
5+
global using System.Web;
6+
using System.Web;
7+
global using System;
8+
using System;

Src/CSharpier/SyntaxPrinter/UsingDirectives.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private static IEnumerable<List<UsingData>> GroupUsings(
134134
FormattingContext context
135135
)
136136
{
137+
var globalSystemUsings = new List<UsingData>();
137138
var globalUsings = new List<UsingData>();
138139
var globalAliasUsings = new List<UsingData>();
139140
var systemUsings = new List<UsingData>();
@@ -187,9 +188,18 @@ FormattingContext context
187188

188189
if (usingDirective.GlobalKeyword.RawSyntaxKind() != SyntaxKind.None)
189190
{
190-
(usingDirective.Alias is not null ? globalAliasUsings : globalUsings).Add(
191-
usingData
192-
);
191+
if (usingDirective.Alias is not null)
192+
{
193+
globalAliasUsings.Add(usingData);
194+
}
195+
else if (usingDirective.Name is not null && IsSystemName(usingDirective.Name))
196+
{
197+
globalSystemUsings.Add(usingData);
198+
}
199+
else
200+
{
201+
globalUsings.Add(usingData);
202+
}
193203
}
194204
else if (usingDirective.StaticKeyword.RawSyntaxKind() != SyntaxKind.None)
195205
{
@@ -214,6 +224,7 @@ FormattingContext context
214224
}
215225
}
216226

227+
yield return globalSystemUsings.OrderBy(o => o.Using, Comparer).ToList();
217228
yield return globalUsings.OrderBy(o => o.Using, Comparer).ToList();
218229
yield return globalAliasUsings.OrderBy(o => o.Using, Comparer).ToList();
219230
yield return systemUsings.OrderBy(o => o.Using, Comparer).ToList();

0 commit comments

Comments
 (0)