-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Update entry point finder to support async Main
#75808
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
850ae14
Update entry point finder to support async main
CyrusNajmabadi c1a7264
Add tests
CyrusNajmabadi 7479b76
Add work item
CyrusNajmabadi f8d7a22
Share test code
CyrusNajmabadi 787e9e6
Share test code
CyrusNajmabadi c1615ab
Merge branch 'main' into entryPoints
CyrusNajmabadi 77d3668
Update src/VisualStudio/CSharp/Test/ProjectSystemShim/EntryPointFinde…
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/VisualStudio/CSharp/Impl/ProjectSystemShim/CSharpEntryPointFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim; | ||
|
||
internal sealed class CSharpEntryPointFinder(Compilation compilation) | ||
: AbstractEntryPointFinder(compilation) | ||
{ | ||
protected override bool MatchesMainMethodName(string name) | ||
=> name == "Main"; | ||
|
||
public static IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilation) | ||
{ | ||
// This differs from the VB implementation | ||
// (Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim.EntryPointFinder) because we don't | ||
// ever consider forms entry points. Technically, this is wrong but it just doesn't matter since the ref | ||
// assemblies are unlikely to have a random Main() method that matches | ||
var visitor = new CSharpEntryPointFinder(compilation); | ||
visitor.Visit(compilation.SourceModule.GlobalNamespace); | ||
return visitor.EntryPoints; | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
src/VisualStudio/CSharp/Impl/ProjectSystemShim/CSharpEntryPointFinderService.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/VisualStudio/CSharp/Impl/ProjectSystemShim/EntryPointFinder.cs
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
src/VisualStudio/CSharp/Test/ProjectSystemShim/EntryPointFinderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Roslyn.VisualStudio.CSharp.UnitTests.ProjectSystemShim; | ||
|
||
[WorkItem("https://github.com/dotnet/roslyn/issues/35376")] | ||
public sealed class EntryPointFinderTests | ||
{ | ||
[Theory, CombinatorialData] | ||
public void PositiveTests( | ||
[CombinatorialValues("public", "private", "")] string accessibility, | ||
[CombinatorialValues("void", "int", "System.Int32", "Int32", "ValueTask", "Task", "ValueTask<int>", "Task<int>")] string returnType, | ||
[CombinatorialValues("string[] args", "string[] args1", "")] string parameters) | ||
{ | ||
Validate($"static {accessibility} {returnType} Main({parameters})", entryPoints => | ||
{ | ||
Assert.Single(entryPoints); | ||
Assert.Equal("C", entryPoints.Single().Name); | ||
}); | ||
} | ||
|
||
private static void NegativeTest(string signature) | ||
=> Validate(signature, Assert.Empty); | ||
|
||
private static void Validate(string signature, Action<IEnumerable<INamedTypeSymbol>> validate) | ||
{ | ||
var compilation = CSharpCompilation.Create("Test", references: [TestBase.MscorlibRef]).AddSyntaxTrees(CSharpSyntaxTree.ParseText($$""" | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
class C | ||
{ | ||
{{signature}} | ||
{ | ||
} | ||
} | ||
""")); | ||
|
||
var entryPoints = CSharpEntryPointFinder.FindEntryPoints(compilation); | ||
validate(entryPoints); | ||
} | ||
|
||
[Theory, CombinatorialData] | ||
public void TestWrongName( | ||
[CombinatorialValues("public", "private", "")] string accessibility, | ||
[CombinatorialValues("void", "int", "System.Int32", "Int32", "ValueTask", "Task", "ValueTask<int>", "Task<int>")] string returnType, | ||
[CombinatorialValues("string[] args", "string[] args1", "")] string parameters) | ||
{ | ||
NegativeTest($"static {accessibility} {returnType} main({parameters})"); | ||
} | ||
|
||
[Theory, CombinatorialData] | ||
public void TestNotStatic( | ||
[CombinatorialValues("public", "private", "")] string accessibility, | ||
[CombinatorialValues("void", "int", "System.Int32", "Int32", "ValueTask", "Task", "ValueTask<int>", "Task<int>")] string returnType, | ||
[CombinatorialValues("string[] args", "string[] args1", "")] string parameters) | ||
{ | ||
NegativeTest($"{accessibility} {returnType} main({parameters})"); | ||
CyrusNajmabadi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
[Theory, CombinatorialData] | ||
public void TestInvalidReturnType( | ||
[CombinatorialValues("public", "private", "")] string accessibility, | ||
[CombinatorialValues("string", "Task<string>", "ValueTask<string>")] string returnType, | ||
[CombinatorialValues("string[] args", "string[] args1", "")] string parameters) | ||
{ | ||
NegativeTest($"static {accessibility} {returnType} Main({parameters})"); | ||
} | ||
|
||
[Theory, CombinatorialData] | ||
public void TestInvalidParameterTypes( | ||
[CombinatorialValues("public", "private", "")] string accessibility, | ||
[CombinatorialValues("void", "int", "System.Int32", "Int32", "ValueTask", "Task", "ValueTask<int>", "Task<int>")] string returnType, | ||
[CombinatorialValues("string args", "string* args", "int[] args", "string[] args1, string[] args2")] string parameters) | ||
{ | ||
NegativeTest($"static {accessibility} {returnType} Main({parameters})"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/VisualStudio/Core/Def/ProjectSystem/IEntryPointFinderService.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
src/VisualStudio/VisualBasic/Impl/ProjectSystemShim/VisualBasicEntryPointFinderService.vb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be Main to be clear it's a "not static" test and not a "wrong name" test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup/ good catch.