Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep trivia in 'make method synchronous' #76039

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.MakeMethodSynchronous;
EmptyDiagnosticAnalyzer,
CSharpMakeMethodSynchronousCodeFixProvider>;

public class MakeMethodSynchronousTests
[Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
public sealed class MakeMethodSynchronousTests
{
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestTaskReturnType()
{
await VerifyCS.VerifyCodeFixAsync(
Expand All @@ -44,7 +45,7 @@ void Goo()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestTaskOfTReturnType()
{
await VerifyCS.VerifyCodeFixAsync(
Expand Down Expand Up @@ -72,7 +73,7 @@ class C
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestSecondModifier()
{
await VerifyCS.VerifyCodeFixAsync(
Expand All @@ -98,7 +99,7 @@ public void Goo()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestFirstModifier()
{
await VerifyCS.VerifyCodeFixAsync(
Expand All @@ -124,7 +125,7 @@ public void Goo()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestTrailingTrivia()
{
await VerifyCS.VerifyCodeFixAsync(
Expand All @@ -151,7 +152,7 @@ void Goo()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestRenameMethod()
{
await VerifyCS.VerifyCodeFixAsync(
Expand All @@ -177,7 +178,7 @@ void Goo()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestRenameMethod1()
{
await VerifyCS.VerifyCodeFixAsync(
Expand Down Expand Up @@ -213,7 +214,7 @@ void Bar()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestParenthesizedLambda()
{
var source =
Expand Down Expand Up @@ -260,7 +261,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestSimpleLambda()
{
var source =
Expand Down Expand Up @@ -307,7 +308,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestLambdaWithExpressionBody()
{
var source =
Expand Down Expand Up @@ -356,7 +357,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestAnonymousMethod()
{
var source =
Expand Down Expand Up @@ -403,7 +404,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestFixAll()
{
await VerifyCS.VerifyCodeFixAsync(
Expand Down Expand Up @@ -443,7 +444,7 @@ void Goo()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/13961")]
public async Task TestRemoveAwaitFromCaller1()
{
Expand Down Expand Up @@ -492,7 +493,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/13961")]
public async Task TestRemoveAwaitFromCaller2()
{
Expand Down Expand Up @@ -541,7 +542,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/13961")]
public async Task TestRemoveAwaitFromCaller3()
{
Expand Down Expand Up @@ -590,7 +591,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/13961")]
public async Task TestRemoveAwaitFromCaller4()
{
Expand Down Expand Up @@ -639,7 +640,7 @@ void Goo()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/13961")]
public async Task TestRemoveAwaitFromCallerNested1()
{
Expand Down Expand Up @@ -690,7 +691,7 @@ int Goo(int i)
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/13961")]
public async Task TestRemoveAwaitFromCallerNested()
{
Expand Down Expand Up @@ -861,7 +862,7 @@ class C
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task MethodWithUsingAwait()
{
var source =
Expand Down Expand Up @@ -890,7 +891,7 @@ async System.Threading.Tasks.Task MAsync()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task MethodWithUsingNoAwait()
{
await VerifyCS.VerifyCodeFixAsync(
Expand Down Expand Up @@ -920,7 +921,7 @@ void M()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task MethodWithAwaitForEach()
{
var source =
Expand All @@ -943,7 +944,7 @@ await VerifyCS.VerifyCodeFixAsync(
source);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task MethodWithForEachNoAwait()
{
await VerifyCS.VerifyCodeFixAsync(
Expand Down Expand Up @@ -971,7 +972,7 @@ void M()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task MethodWithForEachVariableAwait()
{
var source =
Expand All @@ -994,7 +995,7 @@ await VerifyCS.VerifyCodeFixAsync(
source);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task MethodWithForEachVariableNoAwait()
{
await VerifyCS.VerifyCodeFixAsync(
Expand Down Expand Up @@ -1022,7 +1023,7 @@ void M()
""");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestIAsyncEnumerableReturnType()
{
var source =
Expand Down Expand Up @@ -1060,7 +1061,7 @@ IEnumerable<int> M()
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodSynchronous)]
[Fact]
public async Task TestIAsyncEnumeratorReturnTypeOnLocalFunction()
{
var source =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Testing;
Expand All @@ -17,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RemoveAsyncModifier;
CSharpRemoveAsyncModifierCodeFixProvider>;

[Trait(Traits.Feature, Traits.Features.CodeActionsRemoveAsyncModifier)]
public class RemoveAsyncModifierTests : CodeAnalysis.CSharp.Test.Utilities.CSharpTestBase
public sealed class RemoveAsyncModifierTests
{
[Fact]
public async Task Method_Task_MultipleAndNested()
Expand Down Expand Up @@ -917,7 +918,7 @@ public void M1()
}

[Fact]
public async Task ParenthesisedLambda_TaskOfT_ExpressionBody()
public async Task ParenthesizedLambda_TaskOfT_ExpressionBody()
{
await VerifyCS.VerifyCodeFixAsync(
"""
Expand Down Expand Up @@ -947,7 +948,7 @@ public void M1()
}

[Fact]
public async Task ParenthesisedLambda_TaskOfT_BlockBody()
public async Task ParenthesizedLambda_TaskOfT_BlockBody()
{
await VerifyCS.VerifyCodeFixAsync(
"""
Expand Down Expand Up @@ -982,7 +983,7 @@ public void M1()
}

[Fact]
public async Task ParenthesisedLambda_Task_ExpressionBody()
public async Task ParenthesizedLambda_Task_ExpressionBody()
{
await VerifyCS.VerifyCodeFixAsync(
"""
Expand Down Expand Up @@ -1012,7 +1013,7 @@ public void M1()
}

[Fact]
public async Task ParenthesisedLambda_Task_BlockBody()
public async Task ParenthesizedLambda_Task_BlockBody()
{
await VerifyCS.VerifyCodeFixAsync(
"""
Expand Down Expand Up @@ -1163,7 +1164,7 @@ async IAsyncEnumerable<int> M()
yield return 1;
}
}
""" + AsyncStreamsTypes;
""" + CSharpTestBase.AsyncStreamsTypes;

await new VerifyCS.Test
{
Expand Down Expand Up @@ -1207,7 +1208,7 @@ async void M()
}

[Fact]
public async Task ParenthesisedLambda_AsyncVoid_Missing()
public async Task ParenthesizedLambda_AsyncVoid_Missing()
{
var source = """
using System;
Expand Down Expand Up @@ -1263,4 +1264,38 @@ void M()
FixedCode = source,
}.RunAsync();
}
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65380")]
public async Task TestCloseBraceTrivia()
{
await VerifyCS.VerifyCodeFixAsync(
"""
using System;
using System.Threading.Tasks;

public class Class1
{
public async Task {|CS1998:Goo|}()
{
//Hello
Console.WriteLine("Goo");
//World
}
}
""",
"""
using System;
using System.Threading.Tasks;

public class Class1
{
public Task Goo()
{
//Hello
Console.WriteLine("Goo");
return Task.CompletedTask;
//World
}
}
""");
}
}
2 changes: 1 addition & 1 deletion src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter
}
";

protected static readonly string AsyncStreamsTypes = DisposableAsyncEnumeratorDefinition + CommonAsyncStreamsTypes;
public static readonly string AsyncStreamsTypes = DisposableAsyncEnumeratorDefinition + CommonAsyncStreamsTypes;

protected static readonly string EnumeratorCancellationAttributeType = @"
namespace System.Runtime.CompilerServices
Expand Down
Loading
Loading