Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort global System usings before other global usings #1004

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading