From 57f9359691be97f879680a62f7eb5487e4629ca2 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 11 Feb 2020 20:33:12 -0800 Subject: [PATCH 1/2] Add vscode launch and build tasks --- .vscode/launch.json | 52 +++++++++++++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..fe7ff94eb0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,52 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": "dotnet-format -f . --dry-run", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/netcoreapp2.1/dotnet-format.dll", + "args": [ + "-f", + ".", + "-v", + "diag", + "--dry-run" + ], + "cwd": "${workspaceFolder}/src", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": "dotnet-format -w format.sln --dry-run", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/netcoreapp2.1/dotnet-format.dll", + "args": [ + "-w", + "format.sln", + "-v", + "diag", + "--dry-run" + ], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..121f98c008 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/dotnet-format.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/src/dotnet-format.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/src/dotnet-format.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file From 1031632bcc31310e3abecf2f7443cd831e539831 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 11 Feb 2020 20:47:05 -0800 Subject: [PATCH 2/2] Enhance --files option to support directory paths --- .gitignore | 3 + README.md | 31 ++++----- src/CodeFormatter.cs | 36 +++++----- src/FormatOptions.cs | 20 +++--- src/Program.cs | 26 ++++---- src/Resources.resx | 60 ++++++++--------- src/Workspaces/FolderWorkspace.cs | 4 +- .../FolderWorkspace_FolderSolutionLoader.cs | 4 +- .../FolderWorkspace_ProjectLoader.cs | 19 +++--- src/xlf/Resources.cs.xlf | 10 +-- src/xlf/Resources.de.xlf | 10 +-- src/xlf/Resources.es.xlf | 10 +-- src/xlf/Resources.fr.xlf | 10 +-- src/xlf/Resources.it.xlf | 10 +-- src/xlf/Resources.ja.xlf | 10 +-- src/xlf/Resources.ko.xlf | 10 +-- src/xlf/Resources.pl.xlf | 10 +-- src/xlf/Resources.pt-BR.xlf | 10 +-- src/xlf/Resources.ru.xlf | 10 +-- src/xlf/Resources.tr.xlf | 10 +-- src/xlf/Resources.zh-Hans.xlf | 10 +-- src/xlf/Resources.zh-Hant.xlf | 10 +-- tests/CodeFormatterTests.cs | 65 +++++++++++-------- tests/Formatters/AbstractFormatterTests.cs | 8 +-- tests/Formatters/FormattedFilesTests.cs | 8 +-- tests/ProgramTests.cs | 4 +- 26 files changed, 215 insertions(+), 203 deletions(-) diff --git a/.gitignore b/.gitignore index 6aba844c90..de3586b8a0 100644 --- a/.gitignore +++ b/.gitignore @@ -332,3 +332,6 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +# OS-specific files +**/.DS_Store diff --git a/README.md b/README.md index ab520657c1..611ad13383 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![MyGet](https://img.shields.io/dotnet.myget/format/vpre/dotnet-format.svg?label=myget)](https://dotnet.myget.org/feed/format/package/nuget/dotnet-format) -|Branch| Windows (Debug)| Windows (Release)| Linux (Debug) | Linux (Release) | Localization (Debug) | Localization (Release) | +|Branch| Windows (Debug)| Windows (Release)| Linux (Debug) | Linux (Release) | Localization (Debug) | Localization (Release) | |---|:--:|:--:|:--:|:--:|:--:|:--:| [master](https://github.com/dotnet/format/tree/master)|[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/format/dotnet.format?branchName=master&jobName=Windows&configuration=debug&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=347&branchName=master)|[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/format/dotnet.format?branchName=master&jobName=Windows&configuration=release&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=347&branchName=master)|[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/format/dotnet.format?branchName=master&jobName=Linux&configuration=debug&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=347&branchName=master)|[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/format/dotnet.format?branchName=master&jobName=Linux&configuration=release&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=347&branchName=master)|[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/format/dotnet.format?branchName=master&jobName=Windows_Spanish&configuration=debug&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=347&branchName=master)|[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/format/dotnet.format?branchName=master&jobName=Windows_Spanish&configuration=release&label=build)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=347&branchName=master)| @@ -41,14 +41,15 @@ Usage: dotnet-format [options] Options: - -f, --folder The folder to operate on. Cannot be used with the `--workspace` option. - -w, --workspace The solution or project file to operate on. If a file is not specified, the command will search + --folder, -f The folder to operate on. Cannot be used with the `--workspace` option. + --workspace, -w The solution or project file to operate on. If a file is not specified, the command will search the current directory for one. - -v, --verbosity Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and + --verbosity, -v Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] --dry-run Format files, but do not save changes to disk. --check Terminates with a non-zero exit code if any files were formatted. - --files A comma separated list of relative file paths to format. All files are formatted if empty. + --include, --files A comma separated list of relative file or folder paths to include in formatting. All files are + formatted if empty. --exclude A comma separated list of relative file or folder paths to exclude from formatting. --version Display version information --report Writes a json file to the given directory. Defaults to 'format-report.json' if no filename given. @@ -56,15 +57,15 @@ Options: Add `format` after `dotnet` and before the command arguments that you want to run: -| Examples | Description | -| -------------------------------------------------------- |---------------------------------------------------------------------------------------------- | -| dotnet **format** | Formats the project or solution in the current directory. | -| dotnet **format** -f <folder> | Formats a particular folder and subfolders. -| dotnet **format** -w <workspace> | Formats a specific project or solution. | -| dotnet **format** -v diag | Formats with very verbose logging. | -| dotnet **format** --files Programs.cs,Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs | -| dotnet **format** --check --dry-run | Formats but does not save. Returns a non-zero exit code if any files would have been changed. | -| dotnet **format** --report <report-path> | Formats and saves a json report file to the given directory. | +| Examples | Description | +| ---------------------------------------------------------- |---------------------------------------------------------------------------------------------- | +| dotnet **format** | Formats the project or solution in the current directory. | +| dotnet **format** -f <folder> | Formats a particular folder and subfolders. | +| dotnet **format** -w <workspace> | Formats a specific project or solution. | +| dotnet **format** -v diag | Formats with very verbose logging. | +| dotnet **format** --include Programs.cs,Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs | +| dotnet **format** --check --dry-run | Formats but does not save. Returns a non-zero exit code if any files would have been changed. | +| dotnet **format** --report <report-path> | Formats and saves a json report file to the given directory. | ### How To Uninstall @@ -82,7 +83,7 @@ You can build and package the tool using the following commands. The instruction build -pack # The final line from the build will read something like # Successfully created package '..\artifacts\packages\Debug\Shipping\dotnet-format.3.0.0-dev.nupkg'. -# Use the value that is in the form `3.0.0-dev` as the version in the next command. +# Use the value that is in the form `3.2.0-dev` as the version in the next command. dotnet tool install --add-source .\artifacts\packages\Debug\Shipping -g dotnet-format --version dotnet format ``` diff --git a/src/CodeFormatter.cs b/src/CodeFormatter.cs index e8de77f34e..7915d34b62 100644 --- a/src/CodeFormatter.cs +++ b/src/CodeFormatter.cs @@ -34,7 +34,7 @@ public static async Task FormatWorkspaceAsync( ILogger logger, CancellationToken cancellationToken) { - var (workspaceFilePath, workspaceType, logLevel, saveFormattedFiles, _, filesToFormat, filesToIgnore, reportPath) = options; + var (workspaceFilePath, workspaceType, logLevel, saveFormattedFiles, _, pathsToInclude, pathsToExclude, reportPath) = options; var logWorkspaceWarnings = logLevel == LogLevel.Trace; logger.LogInformation(string.Format(Resources.Formatting_code_files_in_workspace_0, workspaceFilePath)); @@ -44,7 +44,7 @@ public static async Task FormatWorkspaceAsync( var workspaceStopwatch = Stopwatch.StartNew(); using (var workspace = await OpenWorkspaceAsync( - workspaceFilePath, workspaceType, filesToFormat, logWorkspaceWarnings, logger, cancellationToken).ConfigureAwait(false)) + workspaceFilePath, workspaceType, pathsToInclude, logWorkspaceWarnings, logger, cancellationToken).ConfigureAwait(false)) { if (workspace is null) { @@ -60,7 +60,7 @@ public static async Task FormatWorkspaceAsync( logger.LogTrace(Resources.Determining_formattable_files); var (fileCount, formatableFiles) = await DetermineFormattableFiles( - solution, projectPath, filesToFormat, filesToIgnore, logger, cancellationToken).ConfigureAwait(false); + solution, projectPath, pathsToInclude, pathsToExclude, logger, cancellationToken).ConfigureAwait(false); var determineFilesMS = workspaceStopwatch.ElapsedMilliseconds - loadWorkspaceMS; logger.LogTrace(Resources.Complete_in_0_ms, determineFilesMS); @@ -137,7 +137,7 @@ private static string GetReportFilePath(string reportPath) private static async Task OpenWorkspaceAsync( string workspacePath, WorkspaceType workspaceType, - ImmutableHashSet filesToFormat, + ImmutableHashSet pathsToInclude, bool logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken) @@ -145,7 +145,7 @@ private static async Task OpenWorkspaceAsync( if (workspaceType == WorkspaceType.Folder) { var folderWorkspace = FolderWorkspace.Create(); - await folderWorkspace.OpenFolder(workspacePath, filesToFormat, cancellationToken); + await folderWorkspace.OpenFolder(workspacePath, pathsToInclude, cancellationToken); return folderWorkspace; } @@ -241,8 +241,8 @@ private static async Task RunCodeFormattersAsync( internal static async Task<(int, ImmutableArray<(DocumentId, OptionSet, ICodingConventionsSnapshot)>)> DetermineFormattableFiles( Solution solution, string projectPath, - ImmutableHashSet filesToFormat, - ImmutableHashSet filesToIgnore, + ImmutableHashSet pathsToInclude, + ImmutableHashSet pathsToExclude, ILogger logger, CancellationToken cancellationToken) { @@ -272,7 +272,7 @@ private static async Task RunCodeFormattersAsync( // Get project documents and options with .editorconfig settings applied. var getProjectDocuments = project.DocumentIds.Select(documentId => GetDocumentAndOptions( - project, documentId, filesToFormat, filesToIgnore, codingConventionsManager, optionsApplier, cancellationToken)); + project, documentId, pathsToInclude, pathsToExclude, codingConventionsManager, optionsApplier, cancellationToken)); getDocumentsAndOptions.AddRange(getProjectDocuments); } @@ -307,18 +307,18 @@ private static async Task RunCodeFormattersAsync( return (fileCount, formattableFiles.ToImmutableArray()); } - private static async Task<(Document, OptionSet, ICodingConventionsSnapshot, bool)> GetDocumentAndOptions( + private static async Task<(Document, OptionSet, ICodingConventionsSnapshot, bool)> GetDocumentAndOptions( Project project, DocumentId documentId, - ImmutableHashSet filesToFormat, - ImmutableHashSet filesToIgnore, + ImmutableHashSet pathsToInclude, + ImmutableHashSet pathsToExclude, ICodingConventionsManager codingConventionsManager, EditorConfigOptionsApplier optionsApplier, CancellationToken cancellationToken) { var document = project.Solution.GetDocument(documentId); - if (await ShouldIgnoreDocument(document, filesToFormat, filesToIgnore, cancellationToken)) + if (await ShouldIgnoreDocument(document, pathsToInclude, pathsToExclude, cancellationToken)) { return (null, null, null, false); } @@ -339,14 +339,14 @@ private static async Task RunCodeFormattersAsync( } private static async Task ShouldIgnoreDocument( - Document document, - ImmutableHashSet filesToFormat, - ImmutableHashSet filesToIgnore, + Document document, + ImmutableHashSet pathsToInclude, + ImmutableHashSet pathsToExclude, CancellationToken cancellationToken) { - if (!filesToFormat.IsEmpty && !filesToFormat.Contains(document.FilePath)) + if (!pathsToInclude.IsEmpty && !pathsToInclude.Any(path => document.FilePath.StartsWith(path, StringComparison.OrdinalIgnoreCase))) { - // If a files list was passed in, then ignore files not present in the list. + // If a files list was passed in, then ignore files not present in the list. return true; } else if (!document.SupportsSyntaxTree) @@ -358,7 +358,7 @@ private static async Task ShouldIgnoreDocument( // Ignore generated code files. return true; } - else if (!filesToIgnore.IsEmpty && filesToIgnore.Any(f => document.FilePath.StartsWith(f, StringComparison.OrdinalIgnoreCase))) + else if (!pathsToExclude.IsEmpty && pathsToExclude.Any(path => document.FilePath.StartsWith(path, StringComparison.OrdinalIgnoreCase))) { // Ignore file in, or under a folder in the list to exclude return true; diff --git a/src/FormatOptions.cs b/src/FormatOptions.cs index cee32f81c0..e98708691d 100644 --- a/src/FormatOptions.cs +++ b/src/FormatOptions.cs @@ -12,8 +12,8 @@ internal class FormatOptions public LogLevel LogLevel { get; } public bool SaveFormattedFiles { get; } public bool ChangesAreErrors { get; } - public ImmutableHashSet FilesToFormat { get; } - public ImmutableHashSet FilesToIgnore { get; } + public ImmutableHashSet PathsToInclude { get; } + public ImmutableHashSet PathsToExclude { get; } public string ReportPath { get; } public FormatOptions( @@ -22,8 +22,8 @@ public FormatOptions( LogLevel logLevel, bool saveFormattedFiles, bool changesAreErrors, - ImmutableHashSet filesToFormat, - ImmutableHashSet filesToIgnore, + ImmutableHashSet pathsToInclude, + ImmutableHashSet pathsToExclude, string reportPath) { WorkspaceFilePath = workspaceFilePath; @@ -31,8 +31,8 @@ public FormatOptions( LogLevel = logLevel; SaveFormattedFiles = saveFormattedFiles; ChangesAreErrors = changesAreErrors; - FilesToFormat = filesToFormat; - FilesToIgnore = filesToIgnore; + PathsToInclude = pathsToInclude; + PathsToExclude = pathsToExclude; ReportPath = reportPath; } @@ -42,8 +42,8 @@ public void Deconstruct( out LogLevel logLevel, out bool saveFormattedFiles, out bool changesAreErrors, - out ImmutableHashSet filesToFormat, - out ImmutableHashSet filesToIgnore, + out ImmutableHashSet pathsToInclude, + out ImmutableHashSet pathsToExclude, out string reportPath) { workspaceFilePath = WorkspaceFilePath; @@ -51,8 +51,8 @@ public void Deconstruct( logLevel = LogLevel; saveFormattedFiles = SaveFormattedFiles; changesAreErrors = ChangesAreErrors; - filesToFormat = FilesToFormat; - filesToIgnore = FilesToIgnore; + pathsToInclude = PathsToInclude; + pathsToExclude = PathsToExclude; reportPath = ReportPath; } } diff --git a/src/Program.cs b/src/Program.cs index c1e8307371..eda7703d7b 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -30,12 +30,12 @@ private static async Task Main(string[] args) .RegisterWithDotnetSuggest() .UseParseErrorReporting() .UseExceptionHandler() - .AddOption(new Option(new[] { "-f", "--folder" }, Resources.The_folder_to_operate_on_Cannot_be_used_with_the_workspace_option, new Argument(() => null))) - .AddOption(new Option(new[] { "-w", "--workspace" }, Resources.The_solution_or_project_file_to_operate_on_If_a_file_is_not_specified_the_command_will_search_the_current_directory_for_one, new Argument(() => null))) - .AddOption(new Option(new[] { "-v", "--verbosity" }, Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic, new Argument() { Arity = ArgumentArity.ExactlyOne }.FromAmong(_verbosityLevels))) + .AddOption(new Option(new[] { "--folder", "-f" }, Resources.The_folder_to_operate_on_Cannot_be_used_with_the_workspace_option, new Argument(() => null))) + .AddOption(new Option(new[] { "--workspace", "-w" }, Resources.The_solution_or_project_file_to_operate_on_If_a_file_is_not_specified_the_command_will_search_the_current_directory_for_one, new Argument(() => null))) + .AddOption(new Option(new[] { "--verbosity", "-v" }, Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic, new Argument() { Arity = ArgumentArity.ExactlyOne }.FromAmong(_verbosityLevels))) .AddOption(new Option(new[] { "--dry-run" }, Resources.Format_files_but_do_not_save_changes_to_disk, new Argument())) .AddOption(new Option(new[] { "--check" }, Resources.Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted, new Argument())) - .AddOption(new Option(new[] { "--files" }, Resources.A_comma_separated_list_of_relative_file_paths_to_format_All_files_are_formatted_if_empty, new Argument(() => null))) + .AddOption(new Option(new[] { "--include", "--files" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty, new Argument(() => null))) .AddOption(new Option(new[] { "--exclude" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting, new Argument(() => null))) .AddOption(new Option(new[] { "--report" }, Resources.Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory, new Argument(() => null))) .UseVersionOption() @@ -44,7 +44,7 @@ private static async Task Main(string[] args) return await parser.InvokeAsync(args).ConfigureAwait(false); } - public static async Task Run(string folder, string workspace, string verbosity, bool dryRun, bool check, string files, string exclude, string report, IConsole console = null) + public static async Task Run(string folder, string workspace, string verbosity, bool dryRun, bool check, string include, string exclude, string report, IConsole console = null) { // Setup logging. var serviceCollection = new ServiceCollection(); @@ -102,8 +102,8 @@ public static async Task Run(string folder, string workspace, string verbos Environment.CurrentDirectory = workspaceDirectory; - var filesToFormat = GetFiles(files, folder); - var filesToIgnore = GetFiles(exclude, folder); + var pathsToInclude = GetRootedPaths(include, folder); + var pathsToExclude = GetRootedPaths(exclude, folder); // Since we are running as a dotnet tool we should be able to find an instance of // MSBuild in a .NET Core SDK. @@ -123,8 +123,8 @@ public static async Task Run(string folder, string workspace, string verbos logLevel, saveFormattedFiles: !dryRun, changesAreErrors: check, - filesToFormat, - filesToIgnore, + pathsToInclude, + pathsToExclude, reportPath: report); var formatResult = await CodeFormatter.FormatWorkspaceAsync( @@ -195,22 +195,22 @@ private static void ConfigureServices(ServiceCollection serviceCollection, ICons /// /// Converts a comma-separated list of relative file paths to a hashmap of full file paths. /// - internal static ImmutableHashSet GetFiles(string files, string folder) + internal static ImmutableHashSet GetRootedPaths(string paths, string folder) { - if (string.IsNullOrEmpty(files)) + if (string.IsNullOrEmpty(paths)) { return ImmutableHashSet.Create(); } if (string.IsNullOrEmpty(folder)) { - return files.Split(',') + return paths.Split(',') .Select(path => Path.GetFullPath(path, Environment.CurrentDirectory)) .ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); } else { - return files.Split(',') + return paths.Split(',') .Select(path => Path.GetFullPath(path, Environment.CurrentDirectory)) .Where(path => path.StartsWith(folder)) .ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); diff --git a/src/Resources.resx b/src/Resources.resx index 697faa0575..ffc9fbfe11 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -1,17 +1,17 @@  - @@ -174,8 +174,8 @@ Terminates with a non-zero exit code if any files were formatted. - - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. Formatted code file '{0}'. @@ -217,6 +217,6 @@ Writing formatting report to: '{0}'. - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. \ No newline at end of file diff --git a/src/Workspaces/FolderWorkspace.cs b/src/Workspaces/FolderWorkspace.cs index 1f8a068ac8..815fbda5bb 100644 --- a/src/Workspaces/FolderWorkspace.cs +++ b/src/Workspaces/FolderWorkspace.cs @@ -32,7 +32,7 @@ public static FolderWorkspace Create(HostServices hostServices) return new FolderWorkspace(hostServices); } - public async Task OpenFolder(string folderPath, ImmutableHashSet filesToInclude, CancellationToken cancellationToken) + public async Task OpenFolder(string folderPath, ImmutableHashSet pathsToInclude, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath)) { @@ -41,7 +41,7 @@ public async Task OpenFolder(string folderPath, ImmutableHashSet ProjectLoaders => ImmutableArray.Create(new CSharpProjectLoader(), new VisualBasicProjectLoader()); - public static async Task LoadSolutionInfoAsync(string folderPath, ImmutableHashSet filesToInclude, CancellationToken cancellationToken) + public static async Task LoadSolutionInfoAsync(string folderPath, ImmutableHashSet pathsToInclude, CancellationToken cancellationToken) { var absoluteFolderPath = Path.IsPathFullyQualified(folderPath) ? folderPath @@ -25,7 +25,7 @@ public static async Task LoadSolutionInfoAsync(string folderPath, // Create projects for each of the supported languages. foreach (var loader in ProjectLoaders) { - var projectInfo = await loader.LoadProjectInfoAsync(folderPath, filesToInclude, cancellationToken); + var projectInfo = await loader.LoadProjectInfoAsync(folderPath, pathsToInclude, cancellationToken); if (projectInfo is null) { continue; diff --git a/src/Workspaces/FolderWorkspace_ProjectLoader.cs b/src/Workspaces/FolderWorkspace_ProjectLoader.cs index 8ed30b1d75..6bfd8674d1 100644 --- a/src/Workspaces/FolderWorkspace_ProjectLoader.cs +++ b/src/Workspaces/FolderWorkspace_ProjectLoader.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. +using System; using System.Collections.Immutable; using System.IO; using System.Linq; @@ -16,11 +17,11 @@ private abstract class ProjectLoader public abstract string FileExtension { get; } public virtual string ProjectName => $"{Language}{FileExtension}proj"; - public virtual async Task LoadProjectInfoAsync(string folderPath, ImmutableHashSet filesToInclude, CancellationToken cancellationToken) + public virtual async Task LoadProjectInfoAsync(string folderPath, ImmutableHashSet pathsToInclude, CancellationToken cancellationToken) { var projectId = ProjectId.CreateNewId(debugName: folderPath); - var documents = await LoadDocumentInfosAsync(projectId, folderPath, FileExtension, filesToInclude); + var documents = await LoadDocumentInfosAsync(projectId, folderPath, FileExtension, pathsToInclude); if (documents.IsDefaultOrEmpty) { return null; @@ -36,19 +37,15 @@ public virtual async Task LoadProjectInfoAsync(string folderPath, I documents: documents); } - private static Task> LoadDocumentInfosAsync(ProjectId projectId, string folderPath, string fileExtension, ImmutableHashSet filesToInclude) + private static Task> LoadDocumentInfosAsync(ProjectId projectId, string folderPath, string fileExtension, ImmutableHashSet pathsToInclude) { return Task.Run(() => { - string[] filePaths; - if (filesToInclude.Count == 0) + var filePaths = Directory.GetFiles(folderPath, $"*{fileExtension}", SearchOption.AllDirectories); + if (!pathsToInclude.IsEmpty) { - filePaths = Directory.GetFiles(folderPath, $"*{fileExtension}", SearchOption.AllDirectories); - } - else - { - filePaths = filesToInclude.Where( - filePath => filePath.EndsWith(fileExtension) && File.Exists(filePath)).ToArray(); + filePaths = filePaths.Where(filePath => + pathsToInclude.Any(path => filePath.StartsWith(path, StringComparison.OrdinalIgnoreCase))).ToArray(); } if (filePaths.Length == 0) diff --git a/src/xlf/Resources.cs.xlf b/src/xlf/Resources.cs.xlf index cb119b3574..48aafa99be 100644 --- a/src/xlf/Resources.cs.xlf +++ b/src/xlf/Resources.cs.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.de.xlf b/src/xlf/Resources.de.xlf index 15076bf91e..5bc1d93702 100644 --- a/src/xlf/Resources.de.xlf +++ b/src/xlf/Resources.de.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.es.xlf b/src/xlf/Resources.es.xlf index ee02effb0d..c4eda7fc10 100644 --- a/src/xlf/Resources.es.xlf +++ b/src/xlf/Resources.es.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.fr.xlf b/src/xlf/Resources.fr.xlf index 5d21567927..4c8d65dd7f 100644 --- a/src/xlf/Resources.fr.xlf +++ b/src/xlf/Resources.fr.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.it.xlf b/src/xlf/Resources.it.xlf index 08f6bc534b..0a9060b6f7 100644 --- a/src/xlf/Resources.it.xlf +++ b/src/xlf/Resources.it.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.ja.xlf b/src/xlf/Resources.ja.xlf index b753caf128..24e00eb24a 100644 --- a/src/xlf/Resources.ja.xlf +++ b/src/xlf/Resources.ja.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.ko.xlf b/src/xlf/Resources.ko.xlf index ff7ed4adb2..5e384cc60d 100644 --- a/src/xlf/Resources.ko.xlf +++ b/src/xlf/Resources.ko.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.pl.xlf b/src/xlf/Resources.pl.xlf index 8088e93b18..cfea55f733 100644 --- a/src/xlf/Resources.pl.xlf +++ b/src/xlf/Resources.pl.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.pt-BR.xlf b/src/xlf/Resources.pt-BR.xlf index f3f7f59b3e..295e1d0784 100644 --- a/src/xlf/Resources.pt-BR.xlf +++ b/src/xlf/Resources.pt-BR.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.ru.xlf b/src/xlf/Resources.ru.xlf index 3e44041d7a..d406ace10c 100644 --- a/src/xlf/Resources.ru.xlf +++ b/src/xlf/Resources.ru.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.tr.xlf b/src/xlf/Resources.tr.xlf index 5f759d0f74..aeb17ea83a 100644 --- a/src/xlf/Resources.tr.xlf +++ b/src/xlf/Resources.tr.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.zh-Hans.xlf b/src/xlf/Resources.zh-Hans.xlf index 3be21a3fe0..c7c969c986 100644 --- a/src/xlf/Resources.zh-Hans.xlf +++ b/src/xlf/Resources.zh-Hans.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.zh-Hant.xlf b/src/xlf/Resources.zh-Hant.xlf index 0574ba5e5c..2d8f1a6ab7 100644 --- a/src/xlf/Resources.zh-Hant.xlf +++ b/src/xlf/Resources.zh-Hant.xlf @@ -3,13 +3,13 @@ - A comma separated list of relative file or folder paths to exclude from formatting - A comma separated list of relative file or folder paths to exclude from formatting + A comma separated list of relative file or folder paths to exclude from formatting. + A comma separated list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file paths to format. All files are formatted if empty. - A comma separated list of relative file paths to format. All files are formatted if empty. + + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/tests/CodeFormatterTests.cs b/tests/CodeFormatterTests.cs index 465a562b9c..027e610a4e 100644 --- a/tests/CodeFormatterTests.cs +++ b/tests/CodeFormatterTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -44,7 +43,7 @@ public async Task NoFilesFormattedInFormattedProject() { await TestFormatWorkspaceAsync( FormattedProjectFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -56,7 +55,7 @@ public async Task NoFilesFormattedInFormattedSolution() { await TestFormatWorkspaceAsync( FormattedSolutionFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -68,7 +67,7 @@ public async Task FilesFormattedInUnformattedProject() { await TestFormatWorkspaceAsync( UnformattedProjectFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 2, @@ -80,21 +79,20 @@ public async Task FilesFormattedInUnformattedSolution() { await TestFormatWorkspaceAsync( UnformattedSolutionFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 2, expectedFileCount: 5); } - [Fact] public async Task FilesFormattedInUnformattedProjectFolder() { // Since the code files are beneath the project folder, files are found and formatted. await TestFormatWorkspaceAsync( Path.GetDirectoryName(UnformattedProjectFilePath), - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 2, @@ -107,7 +105,7 @@ public async Task NoFilesFormattedInUnformattedSolutionFolder() // Since the code files are outside the solution folder, no files are found or formatted. await TestFormatWorkspaceAsync( Path.GetDirectoryName(UnformattedSolutionFilePath), - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -119,7 +117,7 @@ public async Task FSharpProjectsDoNotCreateException() { var log = await TestFormatWorkspaceAsync( FSharpProjectFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 1, expectedFilesFormatted: 0, @@ -132,14 +130,28 @@ public async Task FSharpProjectsDoNotCreateException() Assert.Equal(match.Groups[1].Value, Path.GetFullPath(FSharpProjectFilePath)); } + [Fact] + public async Task OnlyFormatPathsFromList() + { + var include = new[] { UnformattedProjectPath }; + + await TestFormatWorkspaceAsync( + UnformattedProjectFilePath, + include, + exclude: EmptyFilesList, + expectedExitCode: 0, + expectedFilesFormatted: 2, + expectedFileCount: 5); + } + [Fact] public async Task OnlyFormatFilesFromList() { - var filesToFormat = new[] { UnformattedProgramFilePath }; + var include = new[] { UnformattedProgramFilePath }; await TestFormatWorkspaceAsync( UnformattedProjectFilePath, - filesToFormat, + include, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 1, @@ -149,11 +161,11 @@ await TestFormatWorkspaceAsync( [Fact] public async Task NoFilesFormattedWhenNotInList() { - var files = new[] { Path.Combine(UnformattedProjectPath, "does_not_exist.cs") }; + var include = new[] { Path.Combine(UnformattedProjectPath, "does_not_exist.cs") }; await TestFormatWorkspaceAsync( UnformattedProjectFilePath, - files, + include, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -163,11 +175,11 @@ await TestFormatWorkspaceAsync( [Fact] public async Task OnlyLogFormattedFiles() { - var files = new[] { UnformattedProgramFilePath }; + var include = new[] { UnformattedProgramFilePath }; var log = await TestFormatWorkspaceAsync( UnformattedSolutionFilePath, - files, + include, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 1, @@ -185,7 +197,7 @@ public async Task FormatLocationsLoggedInUnformattedProject() { var log = await TestFormatWorkspaceAsync( UnformattedProjectFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 2, @@ -235,7 +247,7 @@ public async Task FormatLocationsNotLoggedInFormattedProject() { var log = await TestFormatWorkspaceAsync( FormattedProjectFilePath, - files: EmptyFilesList, + include: EmptyFilesList, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -250,12 +262,11 @@ public async Task FormatLocationsNotLoggedInFormattedProject() [Fact] public async Task LogFilesThatDontMatchExclude() { - var files = new[] { UnformattedProgramFilePath }; - var exclude = new[] { FormattedProjectPath }; + var include = new[] { UnformattedProgramFilePath }; var log = await TestFormatWorkspaceAsync( UnformattedSolutionFilePath, - files, + include, exclude: EmptyFilesList, expectedExitCode: 0, expectedFilesFormatted: 1, @@ -275,7 +286,7 @@ public async Task IgnoreFileWhenListedInExcludeList() var log = await TestFormatWorkspaceAsync( UnformattedSolutionFilePath, - files: files, + include: files, exclude: files, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -295,7 +306,7 @@ public async Task IgnoreFileWhenContainingFolderListedInExcludeList() var log = await TestFormatWorkspaceAsync( UnformattedSolutionFilePath, - files: files, + include: files, exclude: exclude, expectedExitCode: 0, expectedFilesFormatted: 0, @@ -307,7 +318,7 @@ public async Task IgnoreFileWhenContainingFolderListedInExcludeList() Assert.False(match.Success, log); } - public async Task TestFormatWorkspaceAsync(string workspaceFilePath, IEnumerable files, IEnumerable exclude, int expectedExitCode, int expectedFilesFormatted, int expectedFileCount) + public async Task TestFormatWorkspaceAsync(string workspaceFilePath, IEnumerable include, IEnumerable exclude, int expectedExitCode, int expectedFilesFormatted, int expectedFileCount) { var workspacePath = Path.GetFullPath(workspaceFilePath); @@ -323,8 +334,8 @@ public async Task TestFormatWorkspaceAsync(string workspaceFilePath, IEn : WorkspaceType.Project; } - var filesToFormat = files.Select(Path.GetFullPath).ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); - var filesToIgnore = exclude.Select(Path.GetFullPath).ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); + var pathsToInclude = include.Select(Path.GetFullPath).ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); + var pathsToExclude = exclude.Select(Path.GetFullPath).ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); var logger = new TestLogger(); var formatOptions = new FormatOptions( @@ -333,8 +344,8 @@ public async Task TestFormatWorkspaceAsync(string workspaceFilePath, IEn LogLevel.Trace, saveFormattedFiles: false, changesAreErrors: false, - filesToFormat, - filesToIgnore, + pathsToInclude, + pathsToExclude, reportPath: string.Empty); var formatResult = await CodeFormatter.FormatWorkspaceAsync(formatOptions, logger, CancellationToken.None); diff --git a/tests/Formatters/AbstractFormatterTests.cs b/tests/Formatters/AbstractFormatterTests.cs index b069f0e799..8e80649371 100644 --- a/tests/Formatters/AbstractFormatterTests.cs +++ b/tests/Formatters/AbstractFormatterTests.cs @@ -91,13 +91,13 @@ private protected async Task TestAsync(string testCode, string expec logLevel: LogLevel.Trace, saveFormattedFiles: false, changesAreErrors: false, - filesToFormat: ImmutableHashSet.Create(document.FilePath), - filesToIgnore: ImmutableHashSet.Create(), + pathsToInclude: ImmutableHashSet.Create(document.FilePath), + pathsToExclude: ImmutableHashSet.Create(), reportPath: string.Empty); - var filesToFormat = await GetOnlyFileToFormatAsync(solution, editorConfig); + var pathsToFormat = await GetOnlyFileToFormatAsync(solution, editorConfig); - var formattedSolution = await Formatter.FormatAsync(solution, filesToFormat, formatOptions, Logger, new List(), default); + var formattedSolution = await Formatter.FormatAsync(solution, pathsToFormat, formatOptions, Logger, new List(), default); var formattedDocument = GetOnlyDocument(formattedSolution); var formattedText = await formattedDocument.GetTextAsync(); diff --git a/tests/Formatters/FormattedFilesTests.cs b/tests/Formatters/FormattedFilesTests.cs index 782209fa1d..d2ce6b4cb1 100644 --- a/tests/Formatters/FormattedFilesTests.cs +++ b/tests/Formatters/FormattedFilesTests.cs @@ -55,14 +55,14 @@ private async Task> TestFormattedFiles(string testCode) logLevel: LogLevel.Trace, saveFormattedFiles: false, changesAreErrors: false, - filesToFormat: ImmutableHashSet.Create(document.FilePath), - filesToIgnore: ImmutableHashSet.Create(), + pathsToInclude: ImmutableHashSet.Create(document.FilePath), + pathsToExclude: ImmutableHashSet.Create(), reportPath: string.Empty); - var filesToFormat = await GetOnlyFileToFormatAsync(solution, editorConfig); + var pathsToFormat = await GetOnlyFileToFormatAsync(solution, editorConfig); var formattedFiles = new List(); - await Formatter.FormatAsync(solution, filesToFormat, formatOptions, new TestLogger(), formattedFiles, default); + await Formatter.FormatAsync(solution, pathsToFormat, formatOptions, new TestLogger(), formattedFiles, default); return formattedFiles; } diff --git a/tests/ProgramTests.cs b/tests/ProgramTests.cs index 9808d1201b..b95a2aaf46 100644 --- a/tests/ProgramTests.cs +++ b/tests/ProgramTests.cs @@ -38,10 +38,10 @@ public void ExitCodeIsSameWithoutCheck() public void FilesFormattedDirectorySeparatorInsensitive() { var filePath = $"other_items{Path.DirectorySeparatorChar}OtherClass.cs"; - var files = Program.GetFiles(filePath, folder: null); + var files = Program.GetRootedPaths(filePath, folder: null); var filePathAlt = $"other_items{Path.AltDirectorySeparatorChar}OtherClass.cs"; - var filesAlt = Program.GetFiles(filePathAlt, folder: null); + var filesAlt = Program.GetRootedPaths(filePathAlt, folder: null); Assert.True(files.IsSubsetOf(filesAlt)); }