Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit ed9e9ab

Browse files
committed
Made IFormattingFilter sync
While plumbing through a CancellationToken I noticed that IFormattingFilter had no async implementations. Made it sync until an actual async version is needed.
1 parent 820c031 commit ed9e9ab

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

src/Microsoft.DotNet.CodeFormatting/Filters/FilenameFilter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public FilenameFilter(IEnumerable<string> filenames)
2121
_filenames = filenames;
2222
}
2323

24-
public Task<bool> ShouldBeProcessedAsync(Document document)
24+
public bool ShouldBeProcessed(Document document)
2525
{
2626
if (!_filenames.Any())
2727
{
28-
return Task.FromResult(true);
28+
return true;
2929
}
3030

3131
string docFilename = Path.GetFileName(document.FilePath);
@@ -34,11 +34,11 @@ public Task<bool> ShouldBeProcessedAsync(Document document)
3434
{
3535
if (filename.Equals(docFilename, StringComparison.InvariantCultureIgnoreCase))
3636
{
37-
return Task.FromResult(true);
37+
return true;
3838
}
3939
}
4040

41-
return Task.FromResult(false);
41+
return false;
4242
}
4343
}
4444
}

src/Microsoft.DotNet.CodeFormatting/Filters/IgnoreDesignerGeneratedCodeFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace Microsoft.DotNet.CodeFormatting.Filters
1212
[Export(typeof(IFormattingFilter))]
1313
internal sealed class IgnoreDesignerGeneratedCodeFilter : IFormattingFilter
1414
{
15-
public Task<bool> ShouldBeProcessedAsync(Document document)
15+
public bool ShouldBeProcessed(Document document)
1616
{
1717
if (document.FilePath == null)
1818
{
19-
return Task.FromResult(true);
19+
return true;
2020
}
2121

2222
var isDesignerGenerated = document.FilePath.EndsWith(".Designer.cs", StringComparison.OrdinalIgnoreCase);
23-
return Task.FromResult(!isDesignerGenerated);
23+
return !isDesignerGenerated;
2424
}
2525
}
2626
}

src/Microsoft.DotNet.CodeFormatting/FormattingEngineImplementation.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private async Task SaveChanges(Solution solution, Solution originalSolution, Can
125125
}
126126
}
127127

128-
private async Task<bool> ShouldBeProcessedAsync(Document document)
128+
private bool ShouldBeProcessed(Document document)
129129
{
130130
if (document.FilePath != null)
131131
{
@@ -141,22 +141,22 @@ private async Task<bool> ShouldBeProcessedAsync(Document document)
141141

142142
foreach (var filter in _filters)
143143
{
144-
var shouldBeProcessed = await filter.ShouldBeProcessedAsync(document);
144+
var shouldBeProcessed = filter.ShouldBeProcessed(document);
145145
if (!shouldBeProcessed)
146146
return false;
147147
}
148148

149149
return true;
150150
}
151151

152-
private async Task<SyntaxNode> GetSyntaxRootAndFilter(Document document, CancellationToken cancellationToken)
152+
private Task<SyntaxNode> GetSyntaxRootAndFilter(Document document, CancellationToken cancellationToken)
153153
{
154-
if (!await ShouldBeProcessedAsync(document))
154+
if (!ShouldBeProcessed(document))
155155
{
156156
return null;
157157
}
158158

159-
return await document.GetSyntaxRootAsync(cancellationToken);
159+
return document.GetSyntaxRootAsync(cancellationToken);
160160
}
161161

162162
private void StartDocument()

src/Microsoft.DotNet.CodeFormatting/IFormattingFilter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
namespace Microsoft.DotNet.CodeFormatting
1010
{
11-
// TODO: does this need to be async?
1211
internal interface IFormattingFilter
1312
{
14-
Task<bool> ShouldBeProcessedAsync(Document document);
13+
bool ShouldBeProcessed(Document document);
1514
}
1615
}

src/Microsoft.DotNet.CodeFormatting/Rules/RuleExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,5 @@ public static IEnumerable<SyntaxTrivia> AddNewLine(this IEnumerable<SyntaxTrivia
2424
{
2525
return trivia.Concat(new[] { SyntaxFactory.CarriageReturnLineFeed });
2626
}
27-
28-
public static IEnumerable<SyntaxTrivia> AddWhiteSpaceTrivia(this IEnumerable<SyntaxTrivia> trivia)
29-
{
30-
return trivia.Concat(new[] { SyntaxFactory.Tab });
31-
}
3227
}
3328
}

0 commit comments

Comments
 (0)