Skip to content
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
2 changes: 1 addition & 1 deletion src/CodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static async Task<Solution> RunCodeFormattersAsync(
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;
Expand Down
13 changes: 9 additions & 4 deletions src/Utilities/SourceFileMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@ internal sealed class SourceFileMatcher
private static string[] AllFilesList => new[] { @"**/*.*" };

public static SourceFileMatcher CreateMatcher(string[] include, string[] exclude)
=> new SourceFileMatcher(include.Length > 0 ? include : AllFilesList, exclude);
=> new SourceFileMatcher(include, exclude);

private readonly Matcher _matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
private readonly bool _shouldMatchAll;

public ImmutableArray<string> Include { get; }
public ImmutableArray<string> Exclude { get; }

private SourceFileMatcher(string[] include, string[] exclude)
{
Include = include.ToImmutableArray();
_shouldMatchAll = include.Length == 0 && exclude.Length == 0;

Include = include.Length > 0
? include.ToImmutableArray()
: AllFilesList.ToImmutableArray();
Exclude = exclude.ToImmutableArray();

_matcher = new Matcher(StringComparison.OrdinalIgnoreCase);
_matcher.AddIncludePatterns(Include);
_matcher.AddExcludePatterns(Exclude);
}

public PatternMatchingResult Match(string filePath)
=> _matcher.Match(filePath);
public bool HasMatches(string filePath)
=> _shouldMatchAll || _matcher.Match(filePath).HasMatches;

public IEnumerable<string> GetResultsInFullPath(string directoryPath)
=> _matcher.GetResultsInFullPath(directoryPath);
Expand Down