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

Commit 06bcea5

Browse files
committed
Cleaned up the output.
1 parent 31530ff commit 06bcea5

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

src/CodeFormatter/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static async Task RunAsync(string projectOrSolutionPath, IEnumerable<str
6868
{
6969
var workspace = MSBuildWorkspace.Create();
7070
var engine = FormattingEngine.Create(ruleTypes, filenames);
71+
engine.Verbose = true;
7172

7273
string extension = Path.GetExtension(projectOrSolutionPath);
7374
if (StringComparer.OrdinalIgnoreCase.Equals(extension, ".sln"))

src/Microsoft.DotNet.CodeFormatting/FormattingEngineImplementation.cs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ internal sealed class FormattingEngineImplementation : IFormattingEngine
2525
private readonly IEnumerable<ILocalSemanticFormattingRule> _localSemanticRules;
2626
private readonly IEnumerable<IGlobalSemanticFormattingRule> _globalSemanticRules;
2727
private readonly Stopwatch _watch = new Stopwatch();
28+
private bool _verbose;
29+
30+
public bool Verbose
31+
{
32+
get { return _verbose; }
33+
set { _verbose = value; }
34+
}
2835

2936
[ImportingConstructor]
3037
public FormattingEngineImplementation(
@@ -103,26 +110,23 @@ private async Task<SyntaxNode> GetSyntaxRootAndFilter(Document document, Cancell
103110
return await document.GetSyntaxRootAsync(cancellationToken);
104111
}
105112

106-
private void StartDocument(Document document, int depth = 1)
113+
private void StartDocument()
107114
{
108-
for (int i = 0; i < depth; i++)
109-
{
110-
Console.Write(" ");
111-
}
112-
113-
Console.Write("Processing {0}", document.Name);
114115
_watch.Restart();
115116
}
116117

117-
private void EndDocument()
118+
private void EndDocument(Document document)
118119
{
119120
_watch.Stop();
120-
if (_watch.Elapsed.TotalSeconds > 1)
121+
if (_verbose && _watch.Elapsed.TotalSeconds > 1)
121122
{
122-
Console.WriteLine(" {0} seconds", _watch.Elapsed.TotalSeconds);
123+
Console.WriteLine();
124+
Console.WriteLine(" {0} {1} seconds", document.Name, _watch.Elapsed.TotalSeconds);
125+
}
126+
else
127+
{
128+
Console.Write(".");
123129
}
124-
125-
Console.WriteLine();
126130
}
127131

128132
/// <summary>
@@ -145,16 +149,17 @@ private async Task<Solution> RunSyntaxPass(Solution originalSolution, IReadOnlyL
145149
continue;
146150
}
147151

148-
StartDocument(document);
152+
StartDocument();
149153
var newRoot = RunSyntaxPass(syntaxRoot);
150-
EndDocument();
154+
EndDocument(document);
151155

152156
if (newRoot != syntaxRoot)
153157
{
154158
currentSolution = currentSolution.WithDocumentSyntaxRoot(document.Id, newRoot);
155159
}
156160
}
157161

162+
Console.WriteLine();
158163
return currentSolution;
159164
}
160165

@@ -176,6 +181,7 @@ private async Task<Solution> RunLocalSemanticPass(Solution solution, IReadOnlyLi
176181
solution = await RunLocalSemanticPass(solution, documentIds, localSemanticRule, cancellationToken);
177182
}
178183

184+
Console.WriteLine();
179185
return solution;
180186
}
181187

@@ -192,16 +198,17 @@ private async Task<Solution> RunLocalSemanticPass(Solution originalSolution, IRe
192198
continue;
193199
}
194200

195-
StartDocument(document, depth: 2);
201+
StartDocument();
196202
var newRoot = await localSemanticRule.ProcessAsync(document, syntaxRoot, cancellationToken);
197-
EndDocument();
203+
EndDocument(document);
198204

199205
if (syntaxRoot != newRoot)
200206
{
201207
currentSolution = currentSolution.WithDocumentSyntaxRoot(documentId, newRoot);
202208
}
203209
}
204210

211+
Console.WriteLine();
205212
return currentSolution;
206213
}
207214

@@ -213,6 +220,7 @@ private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyL
213220
solution = await RunGlobalSemanticPass(solution, documentIds, globalSemanticRule, cancellationToken);
214221
}
215222

223+
Console.WriteLine();
216224
return solution;
217225
}
218226

@@ -228,11 +236,12 @@ private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyL
228236
continue;
229237
}
230238

231-
StartDocument(document, depth: 2);
239+
StartDocument();
232240
solution = await globalSemanticRule.ProcessAsync(document, syntaxRoot, cancellationToken);
233-
EndDocument();
241+
EndDocument(document);
234242
}
235243

244+
Console.WriteLine();
236245
return solution;
237246
}
238247
}

src/Microsoft.DotNet.CodeFormatting/IFormattingEngine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Microsoft.DotNet.CodeFormatting
1111
{
1212
public interface IFormattingEngine
1313
{
14+
bool Verbose { get; set; }
1415
Task FormatSolutionAsync(Solution solution, CancellationToken cancellationToken);
1516
Task FormatProjectAsync(Project porject, CancellationToken cancellationToken);
1617
}

0 commit comments

Comments
 (0)