Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit fa21a4d

Browse files
committed
Added a verbose switch
There really isn't a reason to print out the times for every file in a default run.
1 parent 59b7e82 commit fa21a4d

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/CodeFormatter/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ private static int Main(string[] args)
2424
{
2525
if (args.Length < 1)
2626
{
27-
Console.WriteLine("CodeFormatter <project or solution> [/file:<filename>] [/nocopyright] [/nounicode] [/tables] [/c:<config1,config2> [/copyright:file]");
27+
Console.WriteLine("CodeFormatter <project or solution> [/file:<filename>] [/nocopyright] [/nounicode] [/tables] [/c:<config1,config2> [/copyright:file] [/verbose]");
2828
Console.WriteLine(" <filename> - Only apply changes to files with specified name.");
2929
Console.WriteLine(" <configs> - Additional preprocessor configurations the formatter");
3030
Console.WriteLine(" should run under.");
3131
Console.WriteLine(" <copyright> - Specifies file containing copyright header.");
3232
Console.WriteLine(" Use ConvertTests to convert MSTest tests to xUnit.");
3333
Console.WriteLine(" <tables> - Let tables opt out of formatting by defining DOTNET_FORMATTER");
34+
Console.WriteLine(" <verbose> - Verbose output");
3435
Console.WriteLine(" <nounicode> - Do not convert unicode strings to escape sequences");
3536
Console.WriteLine(" <nocopyright>- Do not update the copyright message.");
3637
return -1;
@@ -49,6 +50,7 @@ private static int Main(string[] args)
4950
var copyrightHeader = FormattingConstants.DefaultCopyrightHeader;
5051
var convertUnicode = true;
5152
var allowTables = false;
53+
var verbose = false;
5254
var comparer = StringComparer.OrdinalIgnoreCase;
5355

5456
for (int i = 1; i < args.Length; i++)
@@ -88,6 +90,10 @@ private static int Main(string[] args)
8890
{
8991
convertUnicode = false;
9092
}
93+
else if (comparer.Equals(arg, "/verbose"))
94+
{
95+
verbose = true;
96+
}
9197
else if (comparer.Equals(arg, "/tables"))
9298
{
9399
allowTables = true;
@@ -113,6 +119,7 @@ private static int Main(string[] args)
113119
copyrightHeader,
114120
allowTables,
115121
convertUnicode,
122+
verbose,
116123
ct).Wait(ct);
117124
Console.WriteLine("Completed formatting.");
118125
return 0;
@@ -140,6 +147,7 @@ private static async Task RunAsync(
140147
ImmutableArray<string> copyrightHeader,
141148
bool allowTables,
142149
bool convertUnicode,
150+
bool verbose,
143151
CancellationToken cancellationToken)
144152
{
145153
var workspace = MSBuildWorkspace.Create();
@@ -149,7 +157,9 @@ private static async Task RunAsync(
149157
engine.CopyrightHeader = copyrightHeader;
150158
engine.AllowTables = allowTables;
151159
engine.ConvertUnicodeCharacters = convertUnicode;
160+
engine.Verbose = verbose;
152161

162+
Console.WriteLine(Path.GetFileName(projectOrSolutionPath));
153163
string extension = Path.GetExtension(projectOrSolutionPath);
154164
if (StringComparer.OrdinalIgnoreCase.Equals(extension, ".sln"))
155165
{

src/Microsoft.DotNet.CodeFormatting/FormattingEngineImplementation.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ internal sealed class FormattingEngineImplementation : IFormattingEngine
3434
private readonly IEnumerable<IGlobalSemanticFormattingRule> _globalSemanticRules;
3535
private readonly Stopwatch _watch = new Stopwatch();
3636
private bool _allowTables;
37+
private bool _verbose;
3738

3839
public ImmutableArray<string> CopyrightHeader
3940
{
@@ -64,6 +65,12 @@ public bool AllowTables
6465
get { return _allowTables; }
6566
set { _allowTables = value; }
6667
}
68+
69+
public bool Verbose
70+
{
71+
get { return _verbose; }
72+
set { _verbose = value; }
73+
}
6774

6875
public bool ConvertUnicodeCharacters
6976
{
@@ -213,7 +220,10 @@ private void StartDocument()
213220
private void EndDocument(Document document)
214221
{
215222
_watch.Stop();
216-
FormatLogger.WriteLine(" {0} {1} seconds", document.Name, _watch.Elapsed.TotalSeconds);
223+
if (_verbose)
224+
{
225+
FormatLogger.WriteLine(" {0} {1} seconds", document.Name, _watch.Elapsed.TotalSeconds);
226+
}
217227
}
218228

219229
/// <summary>
@@ -224,7 +234,7 @@ private void EndDocument(Document document)
224234
/// </summary>
225235
private async Task<Solution> RunSyntaxPass(Solution originalSolution, IReadOnlyList<DocumentId> documentIds, CancellationToken cancellationToken)
226236
{
227-
FormatLogger.WriteLine("Syntax Pass");
237+
FormatLogger.WriteLine("\tSyntax Pass");
228238

229239
var currentSolution = originalSolution;
230240
foreach (var documentId in documentIds)
@@ -264,7 +274,7 @@ private SyntaxNode RunSyntaxPass(SyntaxNode root, string languageName)
264274

265275
private async Task<Solution> RunLocalSemanticPass(Solution solution, IReadOnlyList<DocumentId> documentIds, CancellationToken cancellationToken)
266276
{
267-
FormatLogger.WriteLine("Local Semantic Pass");
277+
FormatLogger.WriteLine("\tLocal Semantic Pass");
268278
foreach (var localSemanticRule in _localSemanticRules)
269279
{
270280
solution = await RunLocalSemanticPass(solution, documentIds, localSemanticRule, cancellationToken);
@@ -275,7 +285,11 @@ private async Task<Solution> RunLocalSemanticPass(Solution solution, IReadOnlyLi
275285

276286
private async Task<Solution> RunLocalSemanticPass(Solution originalSolution, IReadOnlyList<DocumentId> documentIds, ILocalSemanticFormattingRule localSemanticRule, CancellationToken cancellationToken)
277287
{
278-
FormatLogger.WriteLine(" {0}", localSemanticRule.GetType().Name);
288+
if (_verbose)
289+
{
290+
FormatLogger.WriteLine(" {0}", localSemanticRule.GetType().Name);
291+
}
292+
279293
var currentSolution = originalSolution;
280294
foreach (var documentId in documentIds)
281295
{
@@ -301,7 +315,7 @@ private async Task<Solution> RunLocalSemanticPass(Solution originalSolution, IRe
301315

302316
private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyList<DocumentId> documentIds, CancellationToken cancellationToken)
303317
{
304-
FormatLogger.WriteLine("Global Semantic Pass");
318+
FormatLogger.WriteLine("\tGlobal Semantic Pass");
305319
foreach (var globalSemanticRule in _globalSemanticRules)
306320
{
307321
solution = await RunGlobalSemanticPass(solution, documentIds, globalSemanticRule, cancellationToken);
@@ -312,7 +326,11 @@ private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyL
312326

313327
private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyList<DocumentId> documentIds, IGlobalSemanticFormattingRule globalSemanticRule, CancellationToken cancellationToken)
314328
{
315-
FormatLogger.WriteLine(" {0}", globalSemanticRule.GetType().Name);
329+
if (_verbose)
330+
{
331+
FormatLogger.WriteLine(" {0}", globalSemanticRule.GetType().Name);
332+
}
333+
316334
foreach (var documentId in documentIds)
317335
{
318336
var document = solution.GetDocument(documentId);

src/Microsoft.DotNet.CodeFormatting/IFormattingEngine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface IFormattingEngine
1717
ImmutableArray<string> FileNames { get; set; }
1818
bool AllowTables { get; set; }
1919
bool ConvertUnicodeCharacters { get; set; }
20+
bool Verbose { get; set; }
2021
Task FormatSolutionAsync(Solution solution, CancellationToken cancellationToken);
2122
Task FormatProjectAsync(Project porject, CancellationToken cancellationToken);
2223
}

0 commit comments

Comments
 (0)