Skip to content

Commit

Permalink
Initial work for sorting usings
Browse files Browse the repository at this point in the history
closes #661
  • Loading branch information
belav committed Jul 1, 2023
1 parent c80bab8 commit de96c75
Show file tree
Hide file tree
Showing 21 changed files with 326 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Shell/Init.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
foreach ($file in Get-ChildItem $PSScriptRoot -Filter "*.psm1") {
Import-Module $file.FullName -DisableNameChecking
Import-Module $file.FullName -DisableNameChecking -Force
}

Write-Host -ForegroundColor DarkMagenta "Welcome to CSharpier shell"
Expand Down
22 changes: 13 additions & 9 deletions Shell/ReviewBranch.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,26 @@ function CSH-ReviewBranch {
}

Set-Location $pathToTestingRepo
& git reset --hard

git checkout $postBranch
$postBranchOutput = (git status) | Out-String
& git reset --hard *> $null
try {
& git checkout $postBranch 2>&1
}
catch { }
$postBranchOutput = (git status 2>&1) | Out-String
$firstRun = -not $postBranchOutput.Contains("On branch $postBranch")

$fastParam = ""
if ($fast -eq $true) {
$fastParam = "--fast"
}

if ($firstRun)
{
if ($firstRun) {
Set-Location $repositoryRoot
$checkoutMainOutput = (git checkout main) | Out-String
if (-not $checkoutMainOutput.Contains("Your branch is up to date with ")) {
try {
& git checkout main | Out-String
}
catch {
Write-Host "Could not checkout main on csharpier, working directory is probably not clean"
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if DEBUG
using Insite.Bad;
#endif
using System;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if DEBUG
using Insite.Bad;
#endif
using System;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using AWord;
using BWord;
using MWord;
using YWord;
using ZWord;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using MWord;
using ZWord;
using AWord;
using BWord;
using YWord;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global using Global;
using System;
using Custom;
using static Expression;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if BUILD_MSI_TASKS
using System;

using Microsoft.Build.Framework;

namespace RepoTasks;

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if BUILD_MSI_TASKS
using System;
using Microsoft.Build.Framework;

namespace RepoTasks;

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Licensed to something

using Apple;
using Microsoft;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Licensed to something

using Microsoft;
using Apple;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#define USE_STRUCT
using System;
using System.Runtime.CompilerServices;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#define USE_STRUCT
using System.Runtime.CompilerServices;
using System;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#undef USE_STRUCT
using System;
using System.Runtime.CompilerServices;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#undef USE_STRUCT
using System.Runtime.CompilerServices;
using System;

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System;

using System.Web; // keeping the blank line above this in the expected is odd, but there isn't a good way to know which spaces to remove besides the first one

using AWord; // the blank line above here tests that we don't add two blank lines between system and non-system
using ZWord;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using ZWord;

using AWord; // the blank line above here tests that we don't add two blank lines between system and non-system

using System.Web; // keeping the blank line above this in the expected is odd, but there isn't a good way to know which spaces to remove besides the first one
using System;
14 changes: 1 addition & 13 deletions Src/CSharpier/SyntaxPrinter/NamespaceLikePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,7 @@ FormattingContext context
docs.Add(Doc.HardLine);
}

docs.Add(
Doc.Join(
Doc.HardLine,
usings.Select(
(o, i) =>
UsingDirective.Print(
o,
context,
printExtraLines: i != 0 || externs.Count != 0
)
)
)
);
docs.Add(UsingDirectives.PrintWithSorting(usings, context, externs.Count != 0));
}

var isCompilationUnitWithAttributes = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public static Doc Print(
)
{
return Doc.Concat(
// TODO when should this actually print?
printExtraLines ? ExtraNewLines.Print(node) : Doc.Null,
Token.PrintWithSuffix(node.GlobalKeyword, " ", context),
Token.PrintWithSuffix(node.UsingKeyword, " ", context),
Token.PrintWithSuffix(node.StaticKeyword, " ", context),
// TODO should only skip on the first one that exists
Token.PrintWithSuffix(node.GlobalKeyword, " ", context, skipLeadingTrivia: true),
Token.PrintWithSuffix(node.UsingKeyword, " ", context, skipLeadingTrivia: true),
Token.PrintWithSuffix(node.StaticKeyword, " ", context, skipLeadingTrivia: true),
node.Alias == null ? Doc.Null : NameEquals.Print(node.Alias, context),
Node.Print(node.NamespaceOrType, context),
Token.Print(node.SemicolonToken, context)
Expand Down
7 changes: 4 additions & 3 deletions Src/CSharpier/SyntaxPrinter/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ public static Doc Print(SyntaxToken syntaxToken, FormattingContext context)
public static Doc PrintWithSuffix(
SyntaxToken syntaxToken,
Doc suffixDoc,
FormattingContext context
FormattingContext context,
bool skipLeadingTrivia = false
)
{
return PrintSyntaxToken(syntaxToken, context, suffixDoc);
return PrintSyntaxToken(syntaxToken, context, suffixDoc, skipLeadingTrivia);
}

private static Doc PrintSyntaxToken(
Expand Down Expand Up @@ -251,7 +252,7 @@ void AddLeadingComment(CommentType commentType)
}
}

while (skipLastHardline && docs.Any() && docs.Last() is HardLine)
while (skipLastHardline && docs.Any() && docs.Last() is HardLine or NullDoc)
{
docs.RemoveAt(docs.Count - 1);
}
Expand Down
Loading

0 comments on commit de96c75

Please sign in to comment.