Skip to content

Commit 52732de

Browse files
Fix locating startup objects (#78972)
CPS passes us an INamespaceSymbol that is the global namespace symbol; it doesn't have a containing assembly. It does have a containing Compilation though, which is what we actually need. While I'm here, let's expose a better API for this to avoid this silly dance in the first place. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2506795 Fixes #78697
2 parents 96e969a + e805d00 commit 52732de

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/VisualStudio/CSharp/Impl/ProjectSystemShim/CSharpEntryPointFinder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public static IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilat
1818
{
1919
// This differs from the VB implementation
2020
// (Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim.EntryPointFinder) because we don't
21-
// ever consider forms entry points. Technically, this is wrong but it just doesn't matter since the ref
22-
// assemblies are unlikely to have a random Main() method that matches
21+
// ever consider forms entry points.
2322
var visitor = new CSharpEntryPointFinder(compilation);
2423
visitor.Visit(compilation.SourceModule.GlobalNamespace);
2524
return visitor.EntryPoints;

src/VisualStudio/CSharp/Impl/ProjectSystemShim/CSharpEntryPointFinderService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ namespace Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim;
1616
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
1717
internal sealed class CSharpEntryPointFinderService() : AbstractEntryPointFinderService
1818
{
19-
protected override IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilation, bool findFormsOnly)
19+
public override IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilation, bool findFormsOnly)
2020
=> CSharpEntryPointFinder.FindEntryPoints(compilation);
2121
}

src/VisualStudio/Core/Def/ProjectSystem/AbstractEntryPointFinderService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
99

1010
internal abstract class AbstractEntryPointFinderService : IEntryPointFinderService
1111
{
12-
protected abstract IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilation, bool findFormsOnly);
12+
public abstract IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilation, bool findFormsOnly);
1313

1414
public IEnumerable<INamedTypeSymbol> FindEntryPoints(INamespaceSymbol symbol, bool findFormsOnly)
15-
=> symbol is not { ContainingAssembly: ISourceAssemblySymbol sourceAssembly }
16-
? []
17-
: FindEntryPoints(sourceAssembly.Compilation, findFormsOnly);
15+
=> symbol is { ContainingCompilation: Compilation compilation }
16+
? FindEntryPoints(compilation, findFormsOnly)
17+
: [];
1818
}

src/VisualStudio/Core/Def/ProjectSystem/IEntryPointFinderService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ internal interface IEntryPointFinderService : ILanguageService
1919
/// <param name="symbol">The namespace to search.</param>
2020
/// <param name="findFormsOnly">Restrict the search to only Windows Forms classes. Note that this is only implemented for VisualBasic</param>
2121
IEnumerable<INamedTypeSymbol> FindEntryPoints(INamespaceSymbol symbol, bool findFormsOnly);
22+
23+
/// <summary>
24+
/// Finds the types that contain entry points like the Main method in a given compilation.
25+
/// </summary>
26+
/// <param name="compilation">The compilation to search.</param>
27+
/// <param name="findFormsOnly">Restrict the search to only Windows Forms classes. Note that this is only implemented for VisualBasic</param>
28+
IEnumerable<INamedTypeSymbol> FindEntryPoints(Compilation compilation, bool findFormsOnly);
2229
}

src/VisualStudio/VisualBasic/Impl/ProjectSystemShim/VisualBasicEntryPointFinder.vb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
2828
Dim visitor = New VisualBasicEntryPointFinder(compilation, findFormsOnly)
2929
Dim symbol = compilation.SourceModule.GlobalNamespace
3030

31-
' Attempt to only search source symbols
32-
' Some callers will give a symbol that is not part of a compilation
33-
If symbol.ContainingCompilation IsNot Nothing Then
34-
symbol = symbol.ContainingCompilation.SourceModule.GlobalNamespace
35-
End If
36-
3731
visitor.Visit(symbol)
3832
Return visitor.EntryPoints
3933
End Function

src/VisualStudio/VisualBasic/Impl/ProjectSystemShim/VisualBasicEntryPointFinderService.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
1717
Public Sub New()
1818
End Sub
1919

20-
Protected Overrides Function FindEntryPoints(compilation As Compilation, findFormsOnly As Boolean) As IEnumerable(Of INamedTypeSymbol)
20+
Public Overrides Function FindEntryPoints(compilation As Compilation, findFormsOnly As Boolean) As IEnumerable(Of INamedTypeSymbol)
2121
Return VisualBasicEntryPointFinder.FindEntryPoints(compilation, findFormsOnly)
2222
End Function
2323
End Class

0 commit comments

Comments
 (0)