Skip to content

Commit 017537a

Browse files
Switch to explicit jtf run
1 parent 7edae94 commit 017537a

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed

src/VisualStudio/CSharp/Impl/ProjectSystemShim/CSharpProjectShim.ICSharpProjectSite.cs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Runtime.InteropServices;
88
using System.Threading;
9+
using System.Threading.Tasks;
910
using Microsoft.CodeAnalysis;
1011
using Microsoft.CodeAnalysis.Shared.Extensions;
1112
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim.Interop;
@@ -120,48 +121,50 @@ public void OnModuleRemoved(string filename)
120121

121122
public int GetValidStartupClasses(IntPtr[] classNames, ref int count)
122123
{
123-
var project = Workspace.CurrentSolution.GetRequiredProject(ProjectSystemProject.Id);
124-
var compilation = project.GetRequiredCompilationAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
125-
var entryPoints = CSharpEntryPointFinder.FindEntryPoints(compilation);
124+
var (result, newCount) = this.ThreadingContext.JoinableTaskFactory.Run(GetValidStartupClassesAsync);
125+
if (newCount.HasValue)
126+
count = newCount.Value;
126127

127-
// If classNames is NULL, then we need to populate the number of valid startup
128-
// classes only
129-
if (classNames == null)
130-
{
131-
count = entryPoints.Count();
132-
return VSConstants.S_OK;
133-
}
134-
else
128+
return result;
129+
130+
async Task<(int result, int? newCount)> GetValidStartupClassesAsync()
135131
{
136-
// We return S_FALSE if we have more entrypoints than places in the array.
137-
var entryPointNames = entryPoints.Select(e => e.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted))).ToArray();
132+
var project = Workspace.CurrentSolution.GetRequiredProject(ProjectSystemProject.Id);
133+
var compilation = await project.GetRequiredCompilationAsync(CancellationToken.None).ConfigureAwait(true);
134+
var entryPoints = CSharpEntryPointFinder.FindEntryPoints(compilation);
138135

139-
if (entryPointNames.Length > classNames.Length)
136+
// If classNames is NULL, then we need to populate the number of valid startup
137+
// classes only
138+
if (classNames == null)
140139
{
141-
return VSConstants.S_FALSE;
140+
return (VSConstants.S_OK, entryPoints.Count());
142141
}
143-
144-
// The old language service stored startup class names in its string table,
145-
// so the property page never freed them. To avoid leaking memory, we're
146-
// going to allocate our strings on the native heap and keep the pointers to them.
147-
// Subsequent calls to this function will free the old strings and allocate the
148-
// new ones. The last set of marshalled strings is freed in the destructor.
149-
if (_startupClasses != null)
142+
else
150143
{
151-
foreach (var @class in _startupClasses)
144+
// We return S_FALSE if we have more entrypoints than places in the array.
145+
var entryPointNames = entryPoints.Select(e => e.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted))).ToArray();
146+
147+
if (entryPointNames.Length > classNames.Length)
148+
return (VSConstants.S_FALSE, null);
149+
150+
// The old language service stored startup class names in its string table,
151+
// so the property page never freed them. To avoid leaking memory, we're
152+
// going to allocate our strings on the native heap and keep the pointers to them.
153+
// Subsequent calls to this function will free the old strings and allocate the
154+
// new ones. The last set of marshalled strings is freed in the destructor.
155+
if (_startupClasses != null)
152156
{
153-
Marshal.FreeHGlobal(@class);
157+
foreach (var @class in _startupClasses)
158+
Marshal.FreeHGlobal(@class);
154159
}
155-
}
156160

157-
_startupClasses = entryPointNames.Select(Marshal.StringToHGlobalUni).ToArray();
158-
Array.Copy(_startupClasses, classNames, _startupClasses.Length);
161+
_startupClasses = entryPointNames.Select(Marshal.StringToHGlobalUni).ToArray();
162+
Array.Copy(_startupClasses, classNames, _startupClasses.Length);
159163

160-
count = entryPointNames.Length;
161-
return VSConstants.S_OK;
164+
return (VSConstants.S_OK, entryPointNames.Length);
165+
}
162166
}
163167
}
164-
165168
public void OnAliasesChanged(string file, string project, int previousAliasesCount, string[] previousAliases, int currentAliasesCount, string[] currentAliases)
166169
{
167170
using (ProjectSystemProject.CreateBatchScope())

src/VisualStudio/Core/Def/ProjectSystem/Legacy/AbstractLegacyProject.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public AbstractLegacyProject(
6767
IThreadingContext threadingContext,
6868
string externalErrorReportingPrefix)
6969
{
70-
_threadingContext = threadingContext;
71-
_threadingContext.ThrowIfNotOnUIThread();
70+
ThreadingContext = threadingContext;
71+
ThreadingContext.ThrowIfNotOnUIThread();
7272
Contract.ThrowIfNull(hierarchy);
7373

7474
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
@@ -177,7 +177,7 @@ protected void AddFile(
177177
string filename,
178178
SourceCodeKind sourceCodeKind)
179179
{
180-
_threadingContext.ThrowIfNotOnUIThread();
180+
ThreadingContext.ThrowIfNotOnUIThread();
181181

182182
// We have tests that assert that XOML files should not get added; this was similar
183183
// behavior to how ASP.NET projects would add .aspx files even though we ultimately ignored
@@ -306,7 +306,7 @@ private static Guid GetProjectIDGuid(IVsHierarchy hierarchy)
306306
/// <remarks>Using item IDs as a key like this in a long-lived way is considered unsupported by CPS and other
307307
/// IVsHierarchy providers, but this code (which is fairly old) still makes the assumptions anyways.</remarks>
308308
private readonly Dictionary<uint, ImmutableArray<string>> _folderNameMap = [];
309-
private readonly IThreadingContext _threadingContext;
309+
protected readonly IThreadingContext ThreadingContext;
310310

311311
private ImmutableArray<string> GetFolderNamesForDocument(string filename)
312312
{
@@ -321,7 +321,7 @@ private ImmutableArray<string> GetFolderNamesForDocument(string filename)
321321

322322
private ImmutableArray<string> GetFolderNamesForDocument(uint documentItemID)
323323
{
324-
_threadingContext.ThrowIfNotOnUIThread();
324+
ThreadingContext.ThrowIfNotOnUIThread();
325325

326326
if (documentItemID != (uint)VSConstants.VSITEMID.Nil && Hierarchy.GetProperty(documentItemID, (int)VsHierarchyPropID.Parent, out var parentObj) == VSConstants.S_OK)
327327
{
@@ -337,7 +337,7 @@ private ImmutableArray<string> GetFolderNamesForDocument(uint documentItemID)
337337

338338
private ImmutableArray<string> GetFolderNamesForFolder(uint folderItemID)
339339
{
340-
_threadingContext.ThrowIfNotOnUIThread();
340+
ThreadingContext.ThrowIfNotOnUIThread();
341341

342342
using var pooledObject = SharedPools.Default<List<string>>().GetPooledObject();
343343

src/VisualStudio/VisualBasic/Impl/LanguageService/VisualBasicPackage.IVbEntryPointProvider.vb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic
1212
Partial Friend Class VisualBasicPackage
1313
Implements IVBEntryPointProvider
1414

15-
Public Function GetFormEntryPointsList(<[In]> pHierarchy As Object,
16-
cItems As Integer,
17-
<Out> bstrList() As String,
18-
<Out> ByVal pcActualItems As IntPtr) As Integer Implements IVBEntryPointProvider.GetFormEntryPointsList
15+
Public Function GetFormEntryPointsList(
16+
pHierarchy As Object,
17+
cItems As Integer,
18+
<Out> bstrList() As String,
19+
<Out> pcActualItems As IntPtr) As Integer Implements IVBEntryPointProvider.GetFormEntryPointsList
1920

2021
Dim workspace = ComponentModel.GetService(Of VisualStudioWorkspace)()
2122
Dim hierarchy = CType(pHierarchy, IVsHierarchy)

0 commit comments

Comments
 (0)