Skip to content

Commit

Permalink
Sort static system usings above other static usings (#1174)
Browse files Browse the repository at this point in the history
* Sort static system usings above other static usings

closes #1162

* formatting files
  • Loading branch information
belav authored Feb 17, 2024
1 parent d2cd509 commit c81a5ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using static System;
using static System.Web;
using static AWord;
using static ZWord;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using static ZWord;
using static AWord;
using static System.Web;
using static System;
11 changes: 10 additions & 1 deletion Src/CSharpier/SyntaxPrinter/UsingDirectives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ FormattingContext context
var systemUsings = new List<UsingData>();
var aliasNameUsings = new List<UsingData>();
var regularUsings = new List<UsingData>();
var staticSystemUsings = new List<UsingData>();
var staticUsings = new List<UsingData>();
var aliasUsings = new List<UsingData>();
var directiveGroup = new List<UsingData>();
Expand Down Expand Up @@ -203,7 +204,14 @@ FormattingContext context
}
else if (usingDirective.StaticKeyword.RawSyntaxKind() != SyntaxKind.None)
{
staticUsings.Add(usingData);
if (usingDirective.Name is not null && IsSystemName(usingDirective.Name))
{
staticSystemUsings.Add(usingData);
}
else
{
staticUsings.Add(usingData);
}
}
else if (usingDirective.Alias is not null)
{
Expand All @@ -230,6 +238,7 @@ FormattingContext context
yield return systemUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return aliasNameUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return regularUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return staticSystemUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return staticUsings.OrderBy(o => o.Using, Comparer).ToList();
yield return aliasUsings.OrderBy(o => o.Using, Comparer).ToList();
// we need the directive groups at the end, the #endif directive
Expand Down

0 comments on commit c81a5ea

Please sign in to comment.