diff --git a/src/CodeFormatter.cs b/src/CodeFormatter.cs index be79fd21e2..86bace4ce8 100644 --- a/src/CodeFormatter.cs +++ b/src/CodeFormatter.cs @@ -194,7 +194,7 @@ private static Workspace OpenFolderWorkspace(string workspacePath, SourceFileMat addedFilePaths.Add(document.FilePath); var isFileIncluded = formatOptions.WorkspaceType == WorkspaceType.Folder || - (formatOptions.FileMatcher.Match(document.FilePath).HasMatches && File.Exists(document.FilePath)); + (formatOptions.FileMatcher.HasMatches(document.FilePath) && File.Exists(document.FilePath)); if (!isFileIncluded || !document.SupportsSyntaxTree) { continue; diff --git a/src/Utilities/SourceFileMatcher.cs b/src/Utilities/SourceFileMatcher.cs index b9fbd81208..ed441da1fb 100644 --- a/src/Utilities/SourceFileMatcher.cs +++ b/src/Utilities/SourceFileMatcher.cs @@ -15,12 +15,15 @@ public static SourceFileMatcher CreateMatcher(string[] include, string[] exclude => new SourceFileMatcher(include.Length > 0 ? include : AllFilesList, exclude); private readonly Matcher _matcher = new Matcher(StringComparison.OrdinalIgnoreCase); + private readonly bool _shouldMatchAll; public ImmutableArray Include { get; } public ImmutableArray Exclude { get; } private SourceFileMatcher(string[] include, string[] exclude) { + _shouldMatchAll = include == AllFilesList && exclude.Length == 0; + Include = include.ToImmutableArray(); Exclude = exclude.ToImmutableArray(); @@ -29,8 +32,8 @@ private SourceFileMatcher(string[] include, string[] exclude) _matcher.AddExcludePatterns(Exclude); } - public PatternMatchingResult Match(string filePath) - => _matcher.Match(filePath); + public bool HasMatches(string filePath) + => _shouldMatchAll || _matcher.Match(filePath).HasMatches; public IEnumerable GetResultsInFullPath(string directoryPath) => _matcher.GetResultsInFullPath(directoryPath);