提交 ee2e5bae 编写于 作者: S Sam Harwell

Include file counts in success message for dotnet-format

上级 f5a9d937
......@@ -61,9 +61,11 @@ public static async Task<int> FormatWorkspaceAsync(ILogger logger, string soluti
logger.LogTrace(Resources.Workspace_loaded_in_0_ms, workspaceStopwatch.ElapsedMilliseconds);
workspaceStopwatch.Restart();
exitCode = await FormatFilesInWorkspaceAsync(logger, workspace, projectPath, codingConventionsManager, saveFormattedFiles, cancellationToken).ConfigureAwait(false);
int fileCount;
int filesFormatted;
(exitCode, fileCount, filesFormatted) = await FormatFilesInWorkspaceAsync(logger, workspace, projectPath, codingConventionsManager, saveFormattedFiles, cancellationToken).ConfigureAwait(false);
logger.LogDebug(Resources.Format_complete_in_0_ms, workspaceStopwatch.ElapsedMilliseconds);
logger.LogDebug(Resources.Formatted_0_of_1_files_in_2_ms, filesFormatted, fileCount, workspaceStopwatch.ElapsedMilliseconds);
}
logger.LogInformation(Resources.Format_complete);
......@@ -92,11 +94,13 @@ void LogWorkspaceWarnings(object sender, WorkspaceDiagnosticEventArgs args)
}
}
private static async Task<int> FormatFilesInWorkspaceAsync(ILogger logger, Workspace workspace, string projectPath, ICodingConventionsManager codingConventionsManager, bool saveFormattedFiles, CancellationToken cancellationToken)
private static async Task<(int status, int fileCount, int filesFormatted)> FormatFilesInWorkspaceAsync(ILogger logger, Workspace workspace, string projectPath, ICodingConventionsManager codingConventionsManager, bool saveFormattedFiles, CancellationToken cancellationToken)
{
var projectIds = workspace.CurrentSolution.ProjectIds.ToImmutableArray();
var optionsApplier = new EditorConfigOptionsApplier();
var totalFileCount = 0;
var totalFilesFormatted = 0;
foreach (var projectId in projectIds)
{
var project = workspace.CurrentSolution.GetProject(projectId);
......@@ -114,18 +118,20 @@ private static async Task<int> FormatFilesInWorkspaceAsync(ILogger logger, Works
logger.LogInformation(Resources.Formatting_code_files_in_project_0, project.Name);
var formattedSolution = await FormatFilesInProjectAsync(logger, project, codingConventionsManager, optionsApplier, cancellationToken).ConfigureAwait(false);
var (formattedSolution, filesFormatted) = await FormatFilesInProjectAsync(logger, project, codingConventionsManager, optionsApplier, cancellationToken).ConfigureAwait(false);
totalFileCount += project.DocumentIds.Count;
totalFilesFormatted += filesFormatted;
if (saveFormattedFiles && !workspace.TryApplyChanges(formattedSolution))
{
logger.LogError(Resources.Failed_to_save_formatting_changes);
return 1;
return (1, totalFileCount, totalFilesFormatted);
}
}
return 0;
return (0, totalFileCount, totalFilesFormatted);
}
private static async Task<Solution> FormatFilesInProjectAsync(ILogger logger, Project project, ICodingConventionsManager codingConventionsManager, EditorConfigOptionsApplier optionsApplier, CancellationToken cancellationToken)
private static async Task<(Solution solution, int filesFormatted)> FormatFilesInProjectAsync(ILogger logger, Project project, ICodingConventionsManager codingConventionsManager, EditorConfigOptionsApplier optionsApplier, CancellationToken cancellationToken)
{
var isCommentTrivia = project.Language == LanguageNames.CSharp
? IsCSharpCommentTrivia
......@@ -173,6 +179,7 @@ private static async Task<Solution> FormatFilesInProjectAsync(ILogger logger, Pr
}
var formattedSolution = project.Solution;
var filesFormatted = 0;
foreach (var (documentId, formatTask) in formattedDocuments)
{
var text = await formatTask.ConfigureAwait(false);
......@@ -181,10 +188,11 @@ private static async Task<Solution> FormatFilesInProjectAsync(ILogger logger, Pr
continue;
}
filesFormatted++;
formattedSolution = formattedSolution.WithDocumentText(documentId, text);
}
return formattedSolution;
return (formattedSolution, filesFormatted);
}
private static Func<SyntaxTrivia, bool> IsCSharpCommentTrivia =
......
......@@ -2,12 +2,12 @@
"profiles": {
"dotnet-format (--dry-run)": {
"commandName": "Project",
"commandLineArgs": "-w Roslyn.sln --dry-run",
"commandLineArgs": "-w Roslyn.sln -v detailed --dry-run",
"workingDirectory": "$(SolutionDir)"
},
"dotnet-format": {
"commandName": "Project",
"commandLineArgs": "-w Roslyn.sln",
"commandLineArgs": "-w Roslyn.sln -v detailed",
"workingDirectory": "$(SolutionDir)"
}
}
......
......@@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.Tools.CodeFormatter {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
......@@ -109,20 +109,20 @@ internal class Resources {
}
/// <summary>
/// Looks up a localized string similar to Format complete in {0}ms..
/// Looks up a localized string similar to Format files, but do not save changes to disk..
/// </summary>
internal static string Format_complete_in_0_ms {
internal static string Format_files_but_do_not_save_changes_to_disk {
get {
return ResourceManager.GetString("Format_complete_in_0_ms", resourceCulture);
return ResourceManager.GetString("Format_files_but_do_not_save_changes_to_disk", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Format files, but do not save changes to disk..
/// Looks up a localized string similar to Formatted {0} of {1} files in {2}ms..
/// </summary>
internal static string Format_files_but_do_not_save_changes_to_disk {
internal static string Formatted_0_of_1_files_in_2_ms {
get {
return ResourceManager.GetString("Format_files_but_do_not_save_changes_to_disk", resourceCulture);
return ResourceManager.GetString("Formatted_0_of_1_files_in_2_ms", resourceCulture);
}
}
......
......@@ -156,8 +156,8 @@
<data name="Could_not_format_0_Format_currently_supports_only_CSharp_and_Visual_Basic_projects" xml:space="preserve">
<value>Could not format '{0}'. Format currently supports only C# and Visual Basic projects.</value>
</data>
<data name="Format_complete_in_0_ms" xml:space="preserve">
<value>Format complete in {0}ms.</value>
<data name="Formatted_0_of_1_files_in_2_ms" xml:space="preserve">
<value>Formatted {0} of {1} files in {2}ms.</value>
</data>
<data name="Loading_workspace" xml:space="preserve">
<value>Loading workspace.</value>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
......@@ -27,16 +27,16 @@
<target state="new">Format complete.</target>
<note />
</trans-unit>
<trans-unit id="Format_complete_in_0_ms">
<source>Format complete in {0}ms.</source>
<target state="new">Format complete in {0}ms.</target>
<note />
</trans-unit>
<trans-unit id="Format_files_but_do_not_save_changes_to_disk">
<source>Format files, but do not save changes to disk.</source>
<target state="new">Format files, but do not save changes to disk.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files_in_2_ms">
<source>Formatted {0} of {1} files in {2}ms.</source>
<target state="new">Formatted {0} of {1} files in {2}ms.</target>
<note />
</trans-unit>
<trans-unit id="Formatting_code_file_0">
<source>Formatting code file '{0}'.</source>
<target state="new">Formatting code file '{0}'.</target>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册