From 7bad9e4c872dd3e2a3bdd9717c4f17be6616b5db Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 10 Nov 2023 16:17:25 +0100 Subject: [PATCH] Improve CLI logging (#1242) --- src/CommandLine/Commands/AnalyzeCommand.cs | 7 +------ .../Commands/FindSymbolsCommand.cs | 7 +------ src/CommandLine/Commands/FixCommand.cs | 11 +++------- src/CommandLine/Commands/FormatCommand.cs | 15 +++++--------- .../Commands/LogicalLinesOfCodeCommand.cs | 13 ++++-------- .../Commands/MSBuildWorkspaceCommand.cs | 8 +++----- .../Commands/PhysicalLinesOfCodeCommand.cs | 13 ++++-------- .../Commands/RenameSymbolCommand.cs | 9 ++------- src/CommandLine/Commands/SpellcheckCommand.cs | 9 ++------- .../Rename/CliSymbolRenameState.cs | 4 ++-- .../Xml/AnalyzerAssemblyXmlSerializer.cs | 2 +- .../Xml/DiagnosticXmlSerializer.cs | 2 +- src/Workspaces.Core/CodeFixes/CodeFixer.cs | 10 +++++----- .../Diagnostics/CodeAnalyzer.cs | 6 +++--- src/Workspaces.Core/Logging/LogHelpers.cs | 20 +++++++++++++++++++ .../Spelling/SpellcheckAnalyzer.cs | 8 ++++---- 16 files changed, 61 insertions(+), 83 deletions(-) diff --git a/src/CommandLine/Commands/AnalyzeCommand.cs b/src/CommandLine/Commands/AnalyzeCommand.cs index ebc0a078cc..63e5f5f98b 100644 --- a/src/CommandLine/Commands/AnalyzeCommand.cs +++ b/src/CommandLine/Commands/AnalyzeCommand.cs @@ -54,7 +54,7 @@ public override async Task 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); } }; @@ -127,9 +127,4 @@ private static void WriteAnalysisResults(IEnumerable 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); - } } diff --git a/src/CommandLine/Commands/FindSymbolsCommand.cs b/src/CommandLine/Commands/FindSymbolsCommand.cs index 05806f1e57..a023dbc29b 100644 --- a/src/CommandLine/Commands/FindSymbolsCommand.cs +++ b/src/CommandLine/Commands/FindSymbolsCommand.cs @@ -118,7 +118,7 @@ public override async Task ExecuteAsync(ProjectOrSolution project allSymbols = symbols?.ToImmutableArray() ?? ImmutableArray.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()) @@ -175,11 +175,6 @@ private static Task> 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, diff --git a/src/CommandLine/Commands/FixCommand.cs b/src/CommandLine/Commands/FixCommand.cs index 2d91ffd487..8ab1c13d50 100644 --- a/src/CommandLine/Commands/FixCommand.cs +++ b/src/CommandLine/Commands/FixCommand.cs @@ -93,7 +93,7 @@ private async Task 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(); @@ -101,7 +101,7 @@ private async Task FixAsync( 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); } @@ -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); } }; @@ -284,9 +284,4 @@ void WriteDiagnosticRules( } } } - - protected override void OperationCanceled(OperationCanceledException ex) - { - WriteLine("Fixing was canceled.", Verbosity.Quiet); - } } diff --git a/src/CommandLine/Commands/FormatCommand.cs b/src/CommandLine/Commands/FormatCommand.cs index 3fa931647a..1694022243 100644 --- a/src/CommandLine/Commands/FormatCommand.cs +++ b/src/CommandLine/Commands/FormatCommand.cs @@ -79,7 +79,7 @@ private async Task> 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( @@ -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 @@ -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)) { @@ -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(); } @@ -156,7 +156,7 @@ private static async Task> 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)) { @@ -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); - } } diff --git a/src/CommandLine/Commands/LogicalLinesOfCodeCommand.cs b/src/CommandLine/Commands/LogicalLinesOfCodeCommand.cs index d48a180ac8..732771205c 100644 --- a/src/CommandLine/Commands/LogicalLinesOfCodeCommand.cs +++ b/src/CommandLine/Commands/LogicalLinesOfCodeCommand.cs @@ -57,7 +57,7 @@ public override async Task ExecuteAsync(ProjectOrSolut private async Task 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(); @@ -78,14 +78,14 @@ private async Task 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> 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 projects = FilterProjects(solution); @@ -111,7 +111,7 @@ private async Task> 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; } @@ -157,9 +157,4 @@ protected override void ProcessResults(IList 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); - } } diff --git a/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs b/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs index 148c686b27..d74f4a9eb0 100644 --- a/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs +++ b/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs @@ -227,7 +227,7 @@ private static async Task 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; @@ -247,8 +247,6 @@ private static async Task 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; } @@ -379,7 +377,7 @@ private protected async Task> GetCompilationsAsync( Solution solution = projectOrSolution.AsSolution(); - WriteLine($"Compile solution '{solution.FilePath}'", Verbosity.Minimal); + WriteLine($"Compiling solution '{solution.FilePath}'", Verbosity.Minimal); Stopwatch stopwatch = Stopwatch.StartNew(); @@ -401,7 +399,7 @@ private protected async Task> 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(); } diff --git a/src/CommandLine/Commands/PhysicalLinesOfCodeCommand.cs b/src/CommandLine/Commands/PhysicalLinesOfCodeCommand.cs index 533c24bbb0..cbd8568a18 100644 --- a/src/CommandLine/Commands/PhysicalLinesOfCodeCommand.cs +++ b/src/CommandLine/Commands/PhysicalLinesOfCodeCommand.cs @@ -62,7 +62,7 @@ public override async Task ExecuteAsync(ProjectOrSolut private async Task 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(); @@ -84,14 +84,14 @@ private async Task 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> 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 projects = FilterProjects(solution); @@ -118,7 +118,7 @@ private async Task> 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; } @@ -184,9 +184,4 @@ protected override void ProcessResults(IList 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); - } } diff --git a/src/CommandLine/Commands/RenameSymbolCommand.cs b/src/CommandLine/Commands/RenameSymbolCommand.cs index e23af41da9..8e38d977b7 100644 --- a/src/CommandLine/Commands/RenameSymbolCommand.cs +++ b/src/CommandLine/Commands/RenameSymbolCommand.cs @@ -61,7 +61,7 @@ public override async Task 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(); @@ -69,7 +69,7 @@ public override async Task ExecuteAsync(ProjectOrSolu 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 { @@ -111,9 +111,4 @@ SymbolRenameState GetSymbolRenamer(Solution solution) options: options); } } - - protected override void OperationCanceled(OperationCanceledException ex) - { - WriteLine("Renaming was canceled.", Verbosity.Minimal); - } } diff --git a/src/CommandLine/Commands/SpellcheckCommand.cs b/src/CommandLine/Commands/SpellcheckCommand.cs index 3c38891087..9b721cedf5 100644 --- a/src/CommandLine/Commands/SpellcheckCommand.cs +++ b/src/CommandLine/Commands/SpellcheckCommand.cs @@ -89,7 +89,7 @@ private async Task FixAsync( spellingFixer = GetSpellingFixer(solution); - WriteLine($"Fix '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal); + WriteLine($"Analyze '{project.Name}'", ConsoleColors.Cyan, Verbosity.Minimal); Stopwatch stopwatch = Stopwatch.StartNew(); @@ -97,7 +97,7 @@ private async Task FixAsync( 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 { @@ -128,11 +128,6 @@ SpellcheckAnalyzer GetSpellingFixer(Solution solution) } } - protected override void OperationCanceled(OperationCanceledException ex) - { - WriteLine("Spellchecking was canceled.", Verbosity.Minimal); - } - private void WriteSummary(ImmutableArray results) { if (!ShouldWrite(Verbosity.Normal)) diff --git a/src/CommandLine/Rename/CliSymbolRenameState.cs b/src/CommandLine/Rename/CliSymbolRenameState.cs index 84e2b8db4d..bc88331743 100644 --- a/src/CommandLine/Rename/CliSymbolRenameState.cs +++ b/src/CommandLine/Rename/CliSymbolRenameState.cs @@ -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) diff --git a/src/CommandLine/Xml/AnalyzerAssemblyXmlSerializer.cs b/src/CommandLine/Xml/AnalyzerAssemblyXmlSerializer.cs index 95c8ab0c44..3f7b8c2430 100644 --- a/src/CommandLine/Xml/AnalyzerAssemblyXmlSerializer.cs +++ b/src/CommandLine/Xml/AnalyzerAssemblyXmlSerializer.cs @@ -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 })) diff --git a/src/CommandLine/Xml/DiagnosticXmlSerializer.cs b/src/CommandLine/Xml/DiagnosticXmlSerializer.cs index 19940b2923..cf242093dc 100644 --- a/src/CommandLine/Xml/DiagnosticXmlSerializer.cs +++ b/src/CommandLine/Xml/DiagnosticXmlSerializer.cs @@ -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 })) diff --git a/src/Workspaces.Core/CodeFixes/CodeFixer.cs b/src/Workspaces.Core/CodeFixes/CodeFixer.cs index ec838dde07..4d58974c86 100644 --- a/src/Workspaces.Core/CodeFixes/CodeFixer.cs +++ b/src/Workspaces.Core/CodeFixes/CodeFixer.cs @@ -64,7 +64,7 @@ public async Task> FixSolutionAsync(Func> FixSolutionAsync(Func 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; diff --git a/src/Workspaces.Core/Diagnostics/CodeAnalyzer.cs b/src/Workspaces.Core/Diagnostics/CodeAnalyzer.cs index bd6ca18ab8..2b33de202e 100644 --- a/src/Workspaces.Core/Diagnostics/CodeAnalyzer.cs +++ b/src/Workspaces.Core/Diagnostics/CodeAnalyzer.cs @@ -74,7 +74,7 @@ public async Task> AnalyzeSolutionAsync( } else { - WriteLine($"Skip '{project.Name}' {$"{i + 1}/{projectIds.Length}"}", ConsoleColors.DarkGray, Verbosity.Minimal); + WriteLine($"Skipping '{project.Name}' {$"{i + 1}/{projectIds.Length}"}", ConsoleColors.DarkGray, Verbosity.Minimal); } lastElapsed = stopwatch.Elapsed; @@ -82,7 +82,7 @@ public async Task> AnalyzeSolutionAsync( stopwatch.Stop(); - 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 (results.Count > 0) WriteProjectAnalysisResults(results); @@ -100,7 +100,7 @@ public async Task AnalyzeProjectAsync(Project project, Ca stopwatch.Stop(); - WriteLine($"Done analyzing project '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal); + LogHelpers.WriteElapsedTime($"Analyzed project '{project.FilePath}'", stopwatch.Elapsed, Verbosity.Minimal); WriteProjectAnalysisResults(new ProjectAnalysisResult[] { result }); diff --git a/src/Workspaces.Core/Logging/LogHelpers.cs b/src/Workspaces.Core/Logging/LogHelpers.cs index c795fc49db..1d676477ff 100644 --- a/src/Workspaces.Core/Logging/LogHelpers.cs +++ b/src/Workspaces.Core/Logging/LogHelpers.cs @@ -30,6 +30,26 @@ internal static class LogHelpers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName); + public static void WriteElapsedTime(string message, TimeSpan elapsedTime, Verbosity verbosity) + { + if (!ShouldWrite(verbosity)) + return; + + Write(message, verbosity); + Write(" ", verbosity); + + if (elapsedTime.TotalMilliseconds >= 1000) + { + double seconds = elapsedTime.TotalMilliseconds / 1000; + + WriteLine($"(in {seconds:n1} s)", verbosity); + } + else + { + WriteLine($"(in {elapsedTime.TotalMilliseconds:n0} ms)", verbosity); + } + } + public static void WriteDiagnostic( Diagnostic diagnostic, string? baseDirectoryPath = null, diff --git a/src/Workspaces.Core/Spelling/SpellcheckAnalyzer.cs b/src/Workspaces.Core/Spelling/SpellcheckAnalyzer.cs index 052ee1ca07..0ca1463b11 100644 --- a/src/Workspaces.Core/Spelling/SpellcheckAnalyzer.cs +++ b/src/Workspaces.Core/Spelling/SpellcheckAnalyzer.cs @@ -76,7 +76,7 @@ public async Task> FixSolutionAsync(Func results2 = await FixProjectAsync(project, cancellationToken).ConfigureAwait(false); @@ -84,19 +84,19 @@ public async Task> FixSolutionAsync(Func f).ToImmutableArray(); }