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

Improve CLI logging #1242

Merged
merged 4 commits into from
Nov 10, 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
7 changes: 1 addition & 6 deletions src/CommandLine/Commands/AnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override async Task<AnalyzeCommandResult> ExecuteAsync(ProjectOrSolution
|| analyzerAssembly.HasAnalyzers
|| analyzerAssembly.HasFixers)
{
WriteLine($"Add analyzer assembly '{analyzerAssembly.FullName}'", ConsoleColors.DarkGray, Verbosity.Detailed);
WriteLine($"Loaded analyzer assembly '{analyzerAssembly.FullName}'", ConsoleColors.DarkGray, Verbosity.Detailed);
}
};

Expand Down Expand Up @@ -127,9 +127,4 @@ private static void WriteAnalysisResults(IEnumerable<ProjectAnalysisResult> resu
WriteLine(Verbosity.Minimal);
WriteLine($"{totalCount} {((totalCount == 1) ? "diagnostic" : "diagnostics")} found", ConsoleColors.Green, Verbosity.Minimal);
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Analysis was canceled.", Verbosity.Quiet);
}
}
7 changes: 1 addition & 6 deletions src/CommandLine/Commands/FindSymbolsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override async Task<CommandResult> ExecuteAsync(ProjectOrSolution project

allSymbols = symbols?.ToImmutableArray() ?? ImmutableArray<ISymbol>.Empty;

WriteLine($"Done analyzing solution '{solution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Analyzed solution '{solution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);
}

if (allSymbols.Any())
Expand Down Expand Up @@ -175,11 +175,6 @@ private static Task<ImmutableArray<ISymbol>> AnalyzeProject(
return SymbolFinder.FindSymbolsAsync(project, options, progress, cancellationToken);
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Analysis was canceled.", Verbosity.Quiet);
}

private static void WriteSymbol(
ISymbol symbol,
Verbosity verbosity,
Expand Down
11 changes: 3 additions & 8 deletions src/CommandLine/Commands/FixCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ private async Task<FixCommandResult> FixAsync(

CodeFixer codeFixer = GetCodeFixer(solution);

WriteLine($"Fix '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Analyze '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);

Stopwatch stopwatch = Stopwatch.StartNew();

ProjectFixResult result = await codeFixer.FixProjectAsync(project, cancellationToken);

stopwatch.Stop();

WriteLine($"Done fixing project '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Analyzed project '{project.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);

results = ImmutableArray.Create(result);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ CodeFixer GetCodeFixer(Solution solution)
|| analyzerAssembly.HasAnalyzers
|| analyzerAssembly.HasFixers)
{
WriteLine($"Add analyzer assembly '{analyzerAssembly.FullName}'", ConsoleColors.DarkGray, Verbosity.Detailed);
WriteLine($"Loaded analyzer assembly '{analyzerAssembly.FullName}'", ConsoleColors.DarkGray, Verbosity.Detailed);
}
};

Expand Down Expand Up @@ -284,9 +284,4 @@ void WriteDiagnosticRules(
}
}
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Fixing was canceled.", Verbosity.Quiet);
}
}
15 changes: 5 additions & 10 deletions src/CommandLine/Commands/FormatCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async Task<ImmutableArray<DocumentId>> FormatSolutionAsync(Solution solu
LogHelpers.WriteFormattedDocuments(formattedDocuments, project, solutionDirectory);
}

WriteLine($" Done analyzing '{project.Name}'", Verbosity.Normal);
WriteLine($" Analyzed '{project.Name}'", Verbosity.Normal);
});
#else
await Parallel.ForEachAsync(
Expand All @@ -101,7 +101,7 @@ await Parallel.ForEachAsync(
LogHelpers.WriteFormattedDocuments(formattedDocuments, project, solutionDirectory);
}

WriteLine($" Done analyzing '{project.Name}'", Verbosity.Normal);
WriteLine($" Analyzed '{project.Name}'", Verbosity.Normal);
});
#endif

Expand All @@ -116,7 +116,7 @@ await Parallel.ForEachAsync(
newSolution = newSolution.WithDocumentText(documentId, sourceText);
}

WriteLine($"Apply changes to solution '{solution.FilePath}'", Verbosity.Normal);
WriteLine($"Applying changes to solution '{solution.FilePath}'...", Verbosity.Normal);

if (!solution.Workspace.TryApplyChanges(newSolution))
{
Expand All @@ -131,7 +131,7 @@ await Parallel.ForEachAsync(
WriteLine($"{count} {((count == 1) ? "document" : "documents")} formatted", ConsoleColors.Green, Verbosity.Minimal);

WriteLine(Verbosity.Minimal);
WriteLine($"Done formatting solution '{solution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Analyzed solution '{solution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);

return changedDocuments.SelectMany(f => f).ToImmutableArray();
}
Expand All @@ -156,7 +156,7 @@ private static async Task<ImmutableArray<DocumentId>> FormatProjectAsync(Project
{
Solution newSolution = newProject.Solution;

WriteLine($"Apply changes to solution '{newSolution.FilePath}'", Verbosity.Normal);
WriteLine($"Applying changes to solution '{newSolution.FilePath}'...", Verbosity.Normal);

if (!solution.Workspace.TryApplyChanges(newSolution))
{
Expand All @@ -183,9 +183,4 @@ private static void WriteSummary(int count)
WriteLine(Verbosity.Minimal);
WriteLine($"{count} {((count == 1) ? "document" : "documents")} formatted", ConsoleColors.Green, Verbosity.Minimal);
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Formatting was canceled.", Verbosity.Minimal);
}
}
13 changes: 4 additions & 9 deletions src/CommandLine/Commands/LogicalLinesOfCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override async Task<LinesOfCodeCommandResult> ExecuteAsync(ProjectOrSolut

private async Task<CodeMetricsInfo> CountLinesAsync(Project project, ICodeMetricsService service, CodeMetricsOptions options, CancellationToken cancellationToken)
{
WriteLine($"Count logical lines for '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Counting logical lines for '{project.Name}'...", ConsoleColors.Cyan, Verbosity.Minimal);

Stopwatch stopwatch = Stopwatch.StartNew();

Expand All @@ -78,14 +78,14 @@ private async Task<CodeMetricsInfo> CountLinesAsync(Project project, ICodeMetric
codeMetrics.TotalLineCount);

WriteLine(Verbosity.Minimal);
WriteLine($"Done counting logical lines for '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Normal);
LogHelpers.WriteElapsedTime($"Counted logical lines for '{project.FilePath}'", stopwatch.Elapsed, Verbosity.Normal);

return codeMetrics;
}

private async Task<ImmutableDictionary<ProjectId, CodeMetricsInfo>> CountLinesAsync(Solution solution, CodeMetricsOptions options, CancellationToken cancellationToken)
{
WriteLine($"Count logical lines for solution '{solution.FilePath}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Counting logical lines for solution '{solution.FilePath}'...", ConsoleColors.Cyan, Verbosity.Minimal);

IEnumerable<Project> projects = FilterProjects(solution);

Expand All @@ -111,7 +111,7 @@ private async Task<ImmutableDictionary<ProjectId, CodeMetricsInfo>> CountLinesAs
codeMetrics.Sum(f => f.Value.TotalLineCount));

WriteLine(Verbosity.Minimal);
WriteLine($"Done counting logical lines for solution '{solution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Normal);
LogHelpers.WriteElapsedTime($"Counted logical lines for solution '{solution.FilePath}'", stopwatch.Elapsed, Verbosity.Normal);

return codeMetrics;
}
Expand Down Expand Up @@ -157,9 +157,4 @@ protected override void ProcessResults(IList<LinesOfCodeCommandResult> results)
totalPreprocessorDirectiveLineCount: results.Sum(f => f.Metrics.PreprocessorDirectiveLineCount),
totalLineCount: results.Sum(f => f.Metrics.TotalLineCount));
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Logical lines counting was canceled.", Verbosity.Quiet);
}
}
8 changes: 3 additions & 5 deletions src/CommandLine/Commands/MSBuildWorkspaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static async Task<ProjectOrSolution> OpenProjectOrSolutionAsync(
{
bool isSolution = string.Equals(Path.GetExtension(path), ".sln", StringComparison.OrdinalIgnoreCase);

WriteLine($"Load {((isSolution) ? "solution" : "project")} '{path}'", Verbosity.Minimal);
WriteLine($"Loading {((isSolution) ? "solution" : "project")} '{path}'...", Verbosity.Minimal);

ProjectOrSolution projectOrSolution;

Expand All @@ -247,8 +247,6 @@ private static async Task<ProjectOrSolution> OpenProjectOrSolutionAsync(
throw new ProjectOrSolutionLoadException($"Error occurred while loading {((isSolution) ? "solution" : "project")} '{path}'", ex);
}

WriteLine($"Done loading {((projectOrSolution.IsSolution) ? "solution" : "project")} '{projectOrSolution.FilePath}'", Verbosity.Minimal);

return projectOrSolution;
}

Expand Down Expand Up @@ -379,7 +377,7 @@ private protected async Task<ImmutableArray<Compilation>> GetCompilationsAsync(

Solution solution = projectOrSolution.AsSolution();

WriteLine($"Compile solution '{solution.FilePath}'", Verbosity.Minimal);
WriteLine($"Compiling solution '{solution.FilePath}'", Verbosity.Minimal);

Stopwatch stopwatch = Stopwatch.StartNew();

Expand All @@ -401,7 +399,7 @@ private protected async Task<ImmutableArray<Compilation>> GetCompilationsAsync(

stopwatch.Stop();

WriteLine($"Done compiling solution '{solution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Compiled solution '{solution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);

return compilations.ToImmutableArray();
}
Expand Down
13 changes: 4 additions & 9 deletions src/CommandLine/Commands/PhysicalLinesOfCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override async Task<LinesOfCodeCommandResult> ExecuteAsync(ProjectOrSolut

private async Task<CodeMetricsInfo> CountLinesAsync(Project project, ICodeMetricsService service, CodeMetricsOptions options, CancellationToken cancellationToken)
{
WriteLine($"Count lines for '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Counting lines for '{project.Name}'...", ConsoleColors.Cyan, Verbosity.Minimal);

Stopwatch stopwatch = Stopwatch.StartNew();

Expand All @@ -84,14 +84,14 @@ private async Task<CodeMetricsInfo> CountLinesAsync(Project project, ICodeMetric
codeMetrics.TotalLineCount);

WriteLine(Verbosity.Minimal);
WriteLine($"Done counting lines for '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Normal);
LogHelpers.WriteElapsedTime($"Counted lines for '{project.FilePath}'", stopwatch.Elapsed, Verbosity.Normal);

return codeMetrics;
}

private async Task<ImmutableDictionary<ProjectId, CodeMetricsInfo>> CountLinesAsync(Solution solution, CodeMetricsOptions options, CancellationToken cancellationToken)
{
WriteLine($"Count lines for solution '{solution.FilePath}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Counting lines for solution '{solution.FilePath}'...", ConsoleColors.Cyan, Verbosity.Minimal);

IEnumerable<Project> projects = FilterProjects(solution);

Expand All @@ -118,7 +118,7 @@ private async Task<ImmutableDictionary<ProjectId, CodeMetricsInfo>> CountLinesAs
codeMetrics.Sum(f => f.Value.TotalLineCount));

WriteLine(Verbosity.Minimal);
WriteLine($"Done counting lines for solution '{solution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Counted lines for solution '{solution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);

return codeMetrics;
}
Expand Down Expand Up @@ -184,9 +184,4 @@ protected override void ProcessResults(IList<LinesOfCodeCommandResult> results)
totalPreprocessorDirectiveLineCount: results.Sum(f => f.Metrics.PreprocessorDirectiveLineCount),
totalLineCount: results.Sum(f => f.Metrics.TotalLineCount));
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Lines counting was canceled.", Verbosity.Quiet);
}
}
9 changes: 2 additions & 7 deletions src/CommandLine/Commands/RenameSymbolCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public override async Task<RenameSymbolCommandResult> ExecuteAsync(ProjectOrSolu

renamer = GetSymbolRenamer(solution);

WriteLine($"Fix '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Analyze '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);

Stopwatch stopwatch = Stopwatch.StartNew();

await renamer.RenameSymbolsAsync(project, cancellationToken);

stopwatch.Stop();

WriteLine($"Done fixing project '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Analyzed project '{project.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);
}
else
{
Expand Down Expand Up @@ -111,9 +111,4 @@ SymbolRenameState GetSymbolRenamer(Solution solution)
options: options);
}
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Renaming was canceled.", Verbosity.Minimal);
}
}
9 changes: 2 additions & 7 deletions src/CommandLine/Commands/SpellcheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ private async Task<SpellcheckCommandResult> FixAsync(

spellingFixer = GetSpellingFixer(solution);

WriteLine($"Fix '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Analyze '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal);

Stopwatch stopwatch = Stopwatch.StartNew();

results = await spellingFixer.FixProjectAsync(project, cancellationToken);

stopwatch.Stop();

WriteLine($"Done fixing project '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Analyzed project '{project.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);
}
else
{
Expand Down Expand Up @@ -128,11 +128,6 @@ SpellcheckAnalyzer GetSpellingFixer(Solution solution)
}
}

protected override void OperationCanceled(OperationCanceledException ex)
{
WriteLine("Spellchecking was canceled.", Verbosity.Minimal);
}

private void WriteSummary(ImmutableArray<SpellingFixResult> results)
{
if (!ShouldWrite(Verbosity.Normal))
Expand Down
4 changes: 2 additions & 2 deletions src/CommandLine/Rename/CliSymbolRenameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ protected override async Task RenameSymbolsAsync(

await AnalyzeProjectAsync(project, renameScopes[i], cancellationToken);

WriteLine($" Done renaming {GetScopePluralName(renameScopes[i])} in '{project.Name}' in {stopwatch.Elapsed - lastElapsed:mm\\:ss\\.ff}", Verbosity.Normal);
LogHelpers.WriteElapsedTime($" Renamed {GetScopePluralName(renameScopes[i])} in '{project.Name}'", stopwatch.Elapsed - lastElapsed, Verbosity.Normal);
}
}

stopwatch.Stop();

WriteLine($"Done renaming symbols in solution '{CurrentSolution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Renamed symbols in solution '{CurrentSolution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);
}

public override async Task RenameSymbolsAsync(Project project, CancellationToken cancellationToken = default)
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLine/Xml/AnalyzerAssemblyXmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private static void SerializeDocument(
diagnostics,
fixAllProviders)));

WriteLine($"Save analyzer assembly analysis to '{filePath}'", ConsoleColors.DarkGray, Verbosity.Diagnostic);
WriteLine($"Saving analyzer assembly analysis to '{filePath}'...", ConsoleColors.DarkGray, Verbosity.Diagnostic);

using (var fileStream = new FileStream(filePath, FileMode.Create))
using (XmlWriter xmlWriter = XmlWriter.Create(fileStream, new XmlWriterSettings() { Indent = true, CloseOutput = false }))
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLine/Xml/DiagnosticXmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static void SerializeDocument(string filePath, XElement summary, params
summary,
new XElement("Projects", projects))));

WriteLine($"Save code analysis to '{filePath}'", ConsoleColors.DarkGray, Verbosity.Diagnostic);
WriteLine($"Saving code analysis to '{filePath}'...", ConsoleColors.DarkGray, Verbosity.Diagnostic);

using (var fileStream = new FileStream(filePath, FileMode.Create))
using (XmlWriter xmlWriter = XmlWriter.Create(fileStream, new XmlWriterSettings() { Indent = true, CloseOutput = false }))
Expand Down
10 changes: 5 additions & 5 deletions src/Workspaces.Core/CodeFixes/CodeFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<ImmutableArray<ProjectFixResult>> FixSolutionAsync(Func<Projec

if (predicate is null || predicate(project))
{
WriteLine($"Fix '{project.Name}' {$"{i + 1}/{projects.Length}"}", ConsoleColors.Cyan, Verbosity.Minimal);
WriteLine($"Analyze '{project.Name}' {$"{i + 1}/{projects.Length}"}", ConsoleColors.Cyan, Verbosity.Minimal);

ProjectFixResult result = await FixProjectAsync(project, cancellationToken).ConfigureAwait(false);

Expand All @@ -75,21 +75,21 @@ public async Task<ImmutableArray<ProjectFixResult>> FixSolutionAsync(Func<Projec
}
else
{
WriteLine($"Skip '{project.Name}' {$"{i + 1}/{projects.Length}"}", ConsoleColors.DarkGray, Verbosity.Minimal);
WriteLine($"Skipping '{project.Name}' {$"{i + 1}/{projects.Length}"}", ConsoleColors.DarkGray, Verbosity.Minimal);

results.Add(ProjectFixResult.Skipped);
}

TimeSpan elapsed = stopwatch.Elapsed;

WriteLine($"Done fixing '{project.Name}' in {elapsed - lastElapsed:mm\\:ss\\.ff}", Verbosity.Normal);
LogHelpers.WriteElapsedTime($"Analyzed '{project.Name}'", elapsed - lastElapsed, Verbosity.Normal);

lastElapsed = elapsed;
}

stopwatch.Stop();

WriteLine($"Done fixing solution '{CurrentSolution.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
LogHelpers.WriteElapsedTime($"Analyzed solution '{CurrentSolution.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal);

return results.ToImmutableArray();
}
Expand Down Expand Up @@ -598,7 +598,7 @@ private async Task<int> AddFileBannerAsync(

Document newDocument = document.WithSyntaxRoot(newRoot);

WriteLine($" Add banner to '{PathUtilities.TrimStart(document.FilePath!, solutionDirectory)}'", ConsoleColors.DarkGray, Verbosity.Detailed);
WriteLine($" Added banner to '{PathUtilities.TrimStart(document.FilePath!, solutionDirectory)}'", ConsoleColors.DarkGray, Verbosity.Detailed);

project = newDocument.Project;

Expand Down
Loading